예제 #1
0
        private void Test(
            // ReSharper disable ParameterOnlyUsedForPreconditionCheck.Local
            MatchResult wildmatch,
            MatchResult wildmatchInsenstive,
            MatchResult pathmatch,
            MatchResult pathmatchInsensitive,
            // ReSharper restore ParameterOnlyUsedForPreconditionCheck.Local
            string input,
            string pattern)
        {
            var wildmatchResult            = Wildmatch.Match(pattern, input, MatchFlags.None);
            var wildmatchInsenstiveResult  = Wildmatch.Match(pattern, input, MatchFlags.CaseFold);
            var pathmatchResult            = Wildmatch.Match(pattern, input, MatchFlags.PathName);
            var pathmatchInsensitiveResult = Wildmatch.Match(pattern, input, MatchFlags.PathName | MatchFlags.CaseFold);

            try
            {
                Assert.Equal($"{wildmatch}:{wildmatchInsenstive}:{pathmatch}:{pathmatchInsensitive}",
                             $"{wildmatchResult}:{wildmatchInsenstiveResult}:{pathmatchResult}:{pathmatchInsensitiveResult}");
            }
            catch (Exception ex)
            {
                throw new Exception($"Input: {input} Pattern: {pattern} Message: {ex.Message}");
            }
        }
예제 #2
0
        public async Task <List <string> > GetOwnersForPath(IFileProvider provider, string path)
        {
            var result = new List <string>();

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentOutOfRangeException();
            }
            if (!path.StartsWith("/"))
            {
                path = $"/{path}";
            }

            await WalkParentsForCodeOwners(provider, path, (directory, relativePath, config) =>
            {
                foreach (var entry in config.Entries)
                {
                    if (Wildmatch.Match(entry.Pattern.TrimStart('/'), relativePath.TrimStart('/'), MatchFlags.CaseFold) == MatchResult.Match)
                    {
                        foreach (var user in entry.Users)
                        {
                            if (user.StartsWith("!"))
                            {
                                if (result.Contains(user.Substring(1)))
                                {
                                    result.Remove(user.Substring(1));
                                }
                            }
                            else
                            {
                                if (!result.Contains(user))
                                {
                                    result.Add(user);
                                }
                            }
                        }
                    }
                }

                return(Task.CompletedTask);
            });

            return(result);
        }