-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add support for wildcard handling of file matching in codeowners library #2770
Comments
@weshaggard I analyzed the relevant code and here is my plan of action. Sharing with you in case you have any concerns or suggestions. Also CC @sima-zhu as I believe Sima has recent experience working with the relevant code :) What code needs to changePrincipally, there are two places that need to be modified: // We want to find the match closest to the bottom of the codeowners file.
// CODEOWNERS sorts the paths in order of 'RepoPath', 'ServicePath' and then 'PackagePath'.
for (int i = codeOwnerEntries.Count - 1; i >= 0; i--)
{
string codeOwnerPath = codeOwnerEntries[i].PathExpression.Trim('/');
// Note that this only matches on paths without glob patterns which is good enough
// for our current scenarios but in the future might need to support globs
if (targetPath.StartsWith(codeOwnerPath, StringComparison.OrdinalIgnoreCase))
{
return codeOwnerEntries[i];
}
} // Entries with wildcards are not yet supported
if (entries[i].ContainsWildcard)
{
// log a warning there
if (entries[i].PRLabels.Any())
{
Colorizer.WriteLine("[Yellow!Warning]: The path '[Cyan!{0}]' contains a wildcard and a label '[Magenta!{1}]' which is not supported!", entries[i].PathExpression, string.Join(',', entries[i].PRLabels));
}
continue; //TODO: regex expressions are not yet supported
} Accepted modifications proposal, Dec 28, 2022Per the follow-up discussion seen in comments below, we care only about case 1, not 2. Case 1 is processing input paths one by one, and looking for a first match in CODEOWNERS file. Hence all we need to do is to ensure that if a candidate path from CODEOWNERS contains Rejected modifications proposal, Dec 5, 2022This proposal was rejected in favor of proposal from 12/28/2022. This rejected proposal would have required expanding each wildcard path against all paths in repo that match it, which would be a lot of work only to then later discard almost all of it, and would require reading the repository structure while parsing CODEOWNERS file. The accepted proposal from 12/27 doesn't have this issues.
Footnotes[1] per this comment:
and our CODEOWNERS documentation:
Which patterns I will supportThe GitHub doc on CODEOWNERS syntax states:
Per this issue description, only this pattern has to be supported, as explained in the gitignore doc:
However, if it will turn out that ROI on supporting other patterns too will be good, I will do so too. Why do I think these are the places to modify, and no other?The parsing logic lives in CodeOwnersFile.ParseContent. It returns a value of type
This means that any limitations of supporting wildcards need to be present downstream of a call to I made the analysis by loading in VS Code the entire repository and doing In addition, I also looked at references to CodeOwnerEntry.PathExpression and CodeOwnerEntry.ContainsWildcard. Here are all the use cases I have identified: Use case 1: The
|
What do you mean by expand here? Do you plan to use some sort of regex patterns to replace the gitignore patterns so you can do a match? That is sort of what I had in mind for implementing this. Other than the one clarification the other logic and searching seems correct. Thanks for the detailed investigation. |
@weshaggard let me summarize our in-person follow-up discussion here. I also discovered another limitation, and I would appreciate your input. We observed that the usage in CodeOwnersFile.FindOwnersForClosestMatch is matching specific file names against the CODEOWNERS entry, so indeed changing the logic from "does this However! The second use case is FabricBot, and there is a problem with it, as it does not support wildcards. The CODEOWNERS path entry gets converted to FabricBot's
which ends up being converted to this pathFilter in fabricbot.json:
Our relevant code doing this is in CreateRuleFabricBot/Rules/PullRequestLabel/PathConfig.cs and around it, in I believe the FabricBot logic matching paths against
as it appears to be called from here (Microsoft-internal). As you can see, this logic is doing plain I see two options going forward:
Given that we plan to move away from FabricBot anyway, per:
I am leaning towards option no 1. @weshaggard let me know what you think. Also CC @JimSuplizio as possibly relevant to his work. |
I agree that for now we can ignore fabricbot and any wildcard paths will just not work there. Once @JimSuplizio does his work to move to github actions for this work he will be using our library here so any file path match should work. |
@konrad-jamrozik , Ignore the FabricBot work, right now they have what they have hard coded inside of the repository specific FabricBot.json files. I need similar things but what I'd ended up doing was including the code-owners-parser to my project and writing some utils. We should, however, have a chat about how I'm using it. |
…r all paths matching given glob path. (#5134) This PR implements for the `retrieve-codeowners` tool the ability to return not only owners for a single path, but a list of all owners for all paths resolved when matching a glob path given as input. As such, this PR contributes to: - #5135 This work is necessary to be able to compare and diff the owners of all files in repository before and after the regex matcher is turned on, per this comment: - #5088 (review) In other words, this PR contributes to unblocking to the following PR: - #5088 And as such, also contributes to: - #2770 This PR will require some upstream changes, which are captured by: - #5103 ### Additional changes - Removed logger from `CodeOwnersParser`; replaced with `Console.Out` and `Console.Error`. This addresses the following comment: - #5063 (comment) - Prevented the new regex matcher from matching paths that have `*` in them - such paths are malformed anyway (at least on Windows). - A lot of assorted changes to surrounding production & test code - please see the file diff for details. ### Implementation notes This PR leverages [`Microsoft.Extensions.FileSystemGlobbing`](https://www.nuget.org/packages/Microsoft.Extensions.FileSystemGlobbing). Doc: https://learn.microsoft.com/en-us/dotnet/core/extensions/file-globbing
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240 Related PRs: - Similar PR fixing invalid paths, but for `net` repo: Azure/azure-sdk-for-net#33584 - Similar PR deprioritizing the Azure SDK EngSys team ownership, but for `python` repo: Azure/azure-sdk-for-python#28534
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240
* Update `CODEOWNERS` paths: fix invalid paths As part of ongoing work of enabling wildcard support for `CODEOWNERS`: - Azure/azure-sdk-tools#2770 - Azure/azure-sdk-tools#5088 and enabling stricter validation: - Azure/azure-sdk-tools#4859 this PR: - fixes invalid paths, to match rules explained [here](https://github.com/Azure/azure-sdk/blob/main/docs/policies/opensource.md#codeowners); - removes `/**/tests.yml` and `/**/ci.yml`, to avoid all build failure notifications being routed to it once we enable the new regex-based, wildcard-supporting `CODEOWNERS` matcher, per: Azure/azure-sdk-tools#5088 (comment) Once this PR is merged, I will enable the new `CODEOWNERS` matcher, similar to how it was done for `net` repo by these two PRs: - Azure/azure-sdk-tools#5241 - Azure/azure-sdk-tools#5240 Related PRs: - Similar PR fixing invalid paths, but for `net` repo: Azure/azure-sdk-for-net#33584 - Similar PR deprioritizing the Azure SDK EngSys team ownership, but for `python` repo: Azure/azure-sdk-for-python#28534 * Update .github/CODEOWNERS Co-authored-by: Ben Broderick Phillips <[email protected]> --------- Co-authored-by: Ben Broderick Phillips <[email protected]>
…ers` executable + add some tests; make assorted refactorings (#5103) This PR is part of work required in preparation to merge: - #5088 Specifically, to enable review of ownership changes due to upcoming wildcards support, as explained in: - #5088 (comment) As such, this PR contributes to: - #2770 This PR is a prerequisite for following PRs: - #5431 ### Merging prerequisite This PR can be merged only after the following PRs are merged and relevant NuGet package published - #5437 - #5104 This is because this PR depends on that NuGet package.
This functionality has been enabled as of: |
Update the NuGet packages using CODEOWNERS parser to pick up these changes: - #5431 - #5518 Relevant NuGet feeds: - https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/Azure.Sdk.Tools.RetrieveCodeOwners/overview - https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/Azure.Sdk.Tools.NotificationConfiguration/overview And builds powering them: - https://dev.azure.com/azure-sdk/internal/_build?definitionId=3188 - https://dev.azure.com/azure-sdk/internal/_build?definitionId=1815 Related work: - #2770
See comment Azure/azure-sdk-for-js#20354 (comment).
It would be helpful to support some basic wildcard matching in our code owners file library. Maybe we cannot easily support all wildcard patterns but we could probably support
**
for something like/sdk/**/ci.mgmt.yml
.The text was updated successfully, but these errors were encountered: