From e33ae8fa1b297a5ac19c1cffa1504b4b89e9954d Mon Sep 17 00:00:00 2001 From: Konrad Jamrozik Date: Fri, 27 Jan 2023 15:13:43 -0800 Subject: [PATCH] Enable regex-based CODEOWNERS matcher for azure-sdk-for-net (#5241) --- .../notification-creator/Contacts.cs | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tools/notification-configuration/notification-creator/Contacts.cs b/tools/notification-configuration/notification-creator/Contacts.cs index bad229110f0..9bd064e3bb4 100644 --- a/tools/notification-configuration/notification-creator/Contacts.cs +++ b/tools/notification-configuration/notification-creator/Contacts.cs @@ -75,7 +75,10 @@ public async Task> GetFromBuildDefinitionRepoCodeowners(BuildDefini "Searching CODEOWNERS for matching path for '{buildDefinitionFilePath}'", buildDefinitionFilePath); - CodeownersEntry matchingCodeownersEntry = GetMatchingCodeownersEntry(yamlProcess, codeownersEntries); + CodeownersEntry matchingCodeownersEntry = GetMatchingCodeownersEntry( + yamlProcess, + codeownersEntries, + repoUrl.ToString()); List contacts = matchingCodeownersEntry.Owners; this.log.LogInformation( @@ -94,7 +97,7 @@ private Uri GetCodeownersRepoUrl(BuildDefinition buildDefinition) if (!string.IsNullOrEmpty(repoUrl?.ToString())) { - repoUrl = new Uri(Regex.Replace(repoUrl.ToString(), @"\.git$", String.Empty)); + repoUrl = new Uri(Regex.Replace(repoUrl.ToString(), @"\.git$", string.Empty)); } else { @@ -109,14 +112,45 @@ private Uri GetCodeownersRepoUrl(BuildDefinition buildDefinition) return repoUrl; } - - private CodeownersEntry GetMatchingCodeownersEntry(YamlProcess process, List codeownersEntries) + private CodeownersEntry GetMatchingCodeownersEntry( + YamlProcess process, + List codeownersEntries, + string repoUrl) { CodeownersEntry matchingCodeownersEntry = - CodeownersFile.GetMatchingCodeownersEntry(process.YamlFilename, codeownersEntries); + CodeownersFile.GetMatchingCodeownersEntry( + process.YamlFilename, + codeownersEntries, + UseRegexMatcher(repoUrl)); matchingCodeownersEntry.ExcludeNonUserAliases(); return matchingCodeownersEntry; } + + /// + /// Whether the new regex-based CODEOWNERS matcher that supports wildcards should be used + /// for given repository. This method exists to allow incremental roll-out + /// of the new matcher [1]. + /// + /// Note that enabling the new matcher will not change the reviewers assigned to + /// PRs, because this is handled by built-in GitHub matcher. + /// But it will change who receives build failure notifications. + /// + /// [1] https://github.com/Azure/azure-sdk-tools/pull/5088 + /// + private bool UseRegexMatcher(string repoUrl) + { + // Expected repoUrl: https://github.com/Azure/azure-sdk-for-net + if (repoUrl.Contains("azure-sdk-for-net")) + { + // Work that was done to facilitate enabling the matcher in this repo: + // https://github.com/Azure/azure-sdk-for-net/pull/33584 - Fix invalid paths in CODEOWNERS + // https://github.com/Azure/azure-sdk-for-net/pull/33595 - Remove CODEOWNERS rules /**/ci.yml and /**/tests.yml + // https://github.com/Azure/azure-sdk-for-net/pull/33597 - Add missing /sdk/ rules + return true; + } + + return false; + } }