-
Notifications
You must be signed in to change notification settings - Fork 229
Add to the retrieve-codeowners tool support for returning owners for all paths matching given glob path.
#5134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/ProgramGlobPathTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using Azure.Sdk.Tools.CodeOwnersParser; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Azure.Sdk.Tools.RetrieveCodeOwners.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Test class for Azure.Sdk.Tools.RetrieveCodeOwners.Program.Main(), | ||
| /// for scenario in which targetPath is a glob path, i.e. | ||
| /// targetPath.IsGlobPath() returns true. | ||
| /// </summary> | ||
| [TestFixture] | ||
| public class ProgramGlobPathTests | ||
| { | ||
| /// <summary> | ||
| /// Given: | ||
| /// <br/><br/> | ||
| /// codeownersFilePathOrUrl contents of: | ||
| /// <code> | ||
| /// | ||
| /// /** @2star | ||
| /// /* @star | ||
| /// /foo/**/a.txt @foo_2star_a | ||
| /// /foo/*/a.txt @foo_star_a_1 @foo_star_a_2 | ||
| /// | ||
| /// </code> | ||
| /// | ||
| /// targetDir contents of: | ||
| /// | ||
| /// <code> | ||
| /// | ||
| /// /a.txt | ||
| /// /b.txt | ||
| /// /foo/a.txt | ||
| /// /foo/b.txt | ||
| /// /foo/bar/a.txt | ||
| /// /foo/bar/b.txt | ||
| /// | ||
| /// </code> | ||
| /// | ||
| /// targetPath of: | ||
| /// | ||
| /// <code> | ||
| /// | ||
| /// /foo/** | ||
| /// | ||
| /// </code> | ||
| /// | ||
| /// excludeNonUserAliases set to false and useRegexMatcher set to true. | ||
| /// <br/><br/> | ||
| /// When: | ||
| /// The retrieve-codeowners tool is executed on these inputs. | ||
| /// <br/><br/> | ||
| /// Then: | ||
| /// The tool should return on STDOUT owners matched in following way: | ||
| /// | ||
| /// <code> | ||
| /// /a.txt @star | ||
| /// /b.txt @star | ||
| /// /foo/a.txt @foo_2star_a | ||
| /// /foo/b.txt @2star | ||
| /// /foo/bar/a.txt @foo_star_a_1 @foo_star_a_2 | ||
| /// /foo/bar/b.txt @2star | ||
| /// </code> | ||
| /// </summary> | ||
| [Test] | ||
| public void OutputsCodeownersForGlobPath() | ||
| { | ||
| const string targetDir = "./TestData/InputDir"; | ||
| const string targetPath = "/**"; | ||
| const string codeownersFilePathOrUrl = "./TestData/glob_path_CODEOWNERS"; | ||
| const bool excludeNonUserAliases = false; | ||
| const bool useRegexMatcher = true; | ||
|
|
||
| var expectedEntries = new Dictionary<string, CodeownersEntry> | ||
| { | ||
| // @formatter:off | ||
| ["a.txt"] = new CodeownersEntry("/*", new List<string> { "star" }), | ||
| ["b.txt"] = new CodeownersEntry("/*", new List<string> { "star" }), | ||
| ["foo/a.txt"] = new CodeownersEntry("/foo/**/a.txt", new List<string> { "foo_2star_a" }), | ||
| ["foo/b.txt"] = new CodeownersEntry("/**", new List<string> { "2star" }), | ||
| ["foo/bar/a.txt"] = new CodeownersEntry("/foo/*/a.txt", new List<string> { "foo_star_a_1", "foo_star_a_2" }), | ||
| ["foo/bar/b.txt"] = new CodeownersEntry("/**", new List<string> { "2star" }), | ||
| // @formatter:on | ||
| }; | ||
|
|
||
| string actualOutput, actualErr; | ||
| int returnCode; | ||
| using (var consoleOutput = new ConsoleOutput()) | ||
| { | ||
| // Act | ||
| returnCode = Program.Main( | ||
| targetPath, | ||
| codeownersFilePathOrUrl, | ||
| excludeNonUserAliases, | ||
| targetDir, | ||
| useRegexMatcher); | ||
|
|
||
| actualOutput = consoleOutput.GetStdout(); | ||
| actualErr = consoleOutput.GetStderr(); | ||
| } | ||
|
|
||
| var actualEntries = TryDeserializeActualEntries(actualOutput, actualErr); | ||
|
|
||
| Assert.Multiple(() => | ||
| { | ||
| AssertEntries(actualEntries, expectedEntries); | ||
| Assert.That(returnCode, Is.EqualTo(0)); | ||
| Assert.That(actualErr, Is.EqualTo(string.Empty)); | ||
| }); | ||
| } | ||
|
|
||
| private static Dictionary<string, CodeownersEntry> TryDeserializeActualEntries( | ||
| string actualOutput, | ||
| string actualErr) | ||
| { | ||
| Dictionary<string, CodeownersEntry> actualEntries; | ||
| try | ||
| { | ||
| actualEntries = | ||
| JsonSerializer.Deserialize<Dictionary<string, CodeownersEntry>>(actualOutput)!; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| Console.WriteLine("actualOutput: " + actualOutput); | ||
| Console.WriteLine("actualErr: " + actualErr); | ||
| throw; | ||
| } | ||
|
|
||
| return actualEntries; | ||
| } | ||
|
|
||
| private static void AssertEntries( | ||
| Dictionary<string, CodeownersEntry> actualEntries, | ||
| Dictionary<string, CodeownersEntry> expectedEntries) | ||
| { | ||
| foreach (KeyValuePair<string, CodeownersEntry> kvp in actualEntries) | ||
| { | ||
| string path = kvp.Key; | ||
| CodeownersEntry actualEntry = kvp.Value; | ||
| Assert.That(expectedEntries[path], Is.EqualTo(actualEntry), $"path: {path}"); | ||
| } | ||
|
|
||
| Assert.That(actualEntries.Count, Is.EqualTo(expectedEntries.Count)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
12 changes: 12 additions & 0 deletions
12
tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/InputDir/b.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Sdk.Tools.RetrieveCodeOwners.Tests.TestData | ||
| { | ||
| class b | ||
| { | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...s/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/InputDir/foo/a.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Sdk.Tools.RetrieveCodeOwners.Tests.TestData.foo | ||
| { | ||
| class a | ||
| { | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...s/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/InputDir/foo/b.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Sdk.Tools.RetrieveCodeOwners.Tests.TestData.foo | ||
| { | ||
| class b | ||
| { | ||
| } | ||
| } |
Empty file.
Empty file.
9 changes: 9 additions & 0 deletions
9
...code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/glob_path_CODEOWNERS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # This file is a test resoure for the test: | ||
| # | ||
| # Azure.Sdk.Tools.RetrieveCodeOwners.Tests.WildcardTests.TestWildcard | ||
| # | ||
|
|
||
| /** @2star | ||
| /* @star | ||
| /foo/**/a.txt @foo_2star_a | ||
| /foo/*/a.txt @foo_star_a_1 @foo_star_a_2 |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary to specify? What is the default language feature?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weshaggard Prompted by your question I investigated a bit and I think it is coming from Directory.Build.props. I will make a PR to update this to
10.0, now that we have moved everything tonet6.0.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted PR:
10.0due to TFM ofnet6.0). #5175