Skip to content

Commit

Permalink
Use CodeownersFile.UseRegexMatcherDefault everywhere where applicab…
Browse files Browse the repository at this point in the history
…le + remove obsolete tests (#5437)

This is a follow-up PR to:
- #5241

That PR was supposed to enable the regex-based matcher everywhere, but didn't. This PR fixes that.

This PR also:
- removes the obsolete `ProgramSimplePathTests` test class; it is superseded by `ProgramGlobPathTests`, which is renamed in:
    - #5431
- removes obsolete tests from `get-codeowners.ps1`

This PR is a prerequisite for following PRs:
- #5103
- #5431
  • Loading branch information
Konrad Jamrozik authored Feb 14, 2023
1 parent 5d9dc06 commit 46834a0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 74 deletions.
19 changes: 12 additions & 7 deletions eng/common/scripts/get-codeowners.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati
}

if($Test) {
$testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS)
TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4")
TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4")
TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @()
TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk")
# These tests have been removed; now instead we should run tests from RetrieveCodeOwnersProgramTests, and in a way as explained in:
# https://github.com/Azure/azure-sdk-tools/issues/5434
# https://github.com/Azure/azure-sdk-tools/pull/5103#discussion_r1068680818
Write-Host "These tests have been removed. Please see https://github.com/Azure/azure-sdk-tools/issues/5434 for more."
#
# $testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS)
# TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
# TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
# TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4")
# TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4")
# TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @()
# TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk")
exit 0
}
else {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static int Main(
bool excludeNonUserAliases = false,
string? targetDir = null,
string ignoredPathPrefixes = DefaultIgnoredPrefixes,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
try
{
Expand Down Expand Up @@ -109,7 +109,7 @@ private static Dictionary<string, CodeownersEntry> GetCodeownersForGlobPath(
string codeownersFilePathOrUrl,
bool excludeNonUserAliases,
string[]? ignoredPathPrefixes = null,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
ignoredPathPrefixes ??= Array.Empty<string>();

Expand All @@ -131,7 +131,7 @@ private static CodeownersEntry GetCodeownersForSimplePath(
string targetPath,
string codeownersFilePathOrUrl,
bool excludeNonUserAliases,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
CodeownersEntry codeownersEntry =
CodeownersFile.GetMatchingCodeownersEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Azure.Sdk.Tools.CodeOwnersParser
{
public static class CodeownersFile
{
private const bool UseRegexMatcherDefault = true;
public const bool UseRegexMatcherDefault = true;

public static List<CodeownersEntry> GetCodeownersEntriesFromFileOrUrl(
string codeownersFilePathOrUrl)
Expand Down

0 comments on commit 46834a0

Please sign in to comment.