diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter.Tests/Utils/MonikerUtilsTests.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter.Tests/Utils/MonikerUtilsTests.cs index 4540a9af40d..a4f18418cd5 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter.Tests/Utils/MonikerUtilsTests.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter.Tests/Utils/MonikerUtilsTests.cs @@ -40,6 +40,28 @@ public void TestMonikerParsingForMonikerLines(string moniker, string line) Assert.That(parsedMoniker, Is.EqualTo(moniker), $"ParseMonikerFromLine for '{line}' should have returned '{moniker}' but returned '{parsedMoniker}'"); } + [Category("Utils")] + [Category("Moniker")] + // Case Insensitive Tests + [TestCase(MonikerConstants.AzureSdkOwners, $"# AzureSDKOwners: @fakeOwner1 @fakeOwner2")] + [TestCase(MonikerConstants.AzureSdkOwners, $"# azureSdkowners: @fakeOwner1 @fakeOwner2")] + [TestCase(MonikerConstants.PRLabel, $"# prlabel: %Fake Label")] + [TestCase(MonikerConstants.PRLabel, $"# PrLabel: %Fake Label")] + [TestCase(MonikerConstants.ServiceLabel, $"# serviceLabel: %Fake Label")] + [TestCase(MonikerConstants.ServiceLabel, $"# SERVICELABEL: %Fake Label")] + [TestCase(MonikerConstants.ServiceOwners, $"# seRvICEowners:")] + [TestCase(MonikerConstants.ServiceOwners, $"# serviceOwners:")] + public void TestMonikerParsingForMonikerLinesCaseInsensitive(string moniker, string line) + { + // The MonikerUtils has 2 methods to test for Moniker parsing + // 1. ParseMonikerFromLine - returns the moniker if one is found on the line + // 2. IsMonikerLine - returns true if the line is a moniker line + bool isMonikerLine = MonikerUtils.IsMonikerLine(line); + Assert.IsTrue(isMonikerLine, $"IsMonikerLine for '{line}' contains '{moniker}' and should have returned true."); + string parsedMoniker = MonikerUtils.ParseMonikerFromLine(line); + Assert.That(parsedMoniker, Is.EqualTo(moniker), $"ParseMonikerFromLine for '{line}' should have returned '{moniker}' but returned '{parsedMoniker}'"); + } + [Category("Utils")] [Category("Moniker")] [TestCase("# just a comment line")] diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/MonikerUtils.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/MonikerUtils.cs index e70850db611..d7d7980994c 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/MonikerUtils.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/MonikerUtils.cs @@ -34,7 +34,7 @@ public static string ParseMonikerFromLine(string line) { // Line starts with ":", unfortunately // has no colon and needs // to be checked separately - if (strippedLine.StartsWith($"{tempMoniker}{SeparatorConstants.Colon}")) + if (strippedLine.StartsWith($"{tempMoniker}{SeparatorConstants.Colon}", StringComparison.OrdinalIgnoreCase)) { return tempMoniker; } @@ -69,7 +69,7 @@ public static bool IsMonikerLine(string line) { // Line starts with ":", unfortunately // has no colon and needs // to be checked separately - if (strippedLine.StartsWith($"{tempMoniker}{SeparatorConstants.Colon}")) + if (strippedLine.StartsWith($"{tempMoniker}{SeparatorConstants.Colon}", StringComparison.OrdinalIgnoreCase)) { return true; } diff --git a/tools/codeowners-utils/METADATA.md b/tools/codeowners-utils/METADATA.md index 96043d2e633..6b74d44b052 100644 --- a/tools/codeowners-utils/METADATA.md +++ b/tools/codeowners-utils/METADATA.md @@ -32,9 +32,11 @@ This list of examples is exhaustive. If an example isn't in here then it won't w ```text # AzureSdkOwners: @fakeUser3 @fakeUser4 +# ServiceLabel: %fakeLabel12 /sdk/SomePath/ @fakeUser1 @fakeUser2 @Azure/fakeTeam1 OR # AzureSdkOwners: +# ServiceLabel: %fakeLabel12 /sdk/SomePath/ @fakeUser1 @fakeUser2 @Azure/fakeTeam1 OR # AzureSdkOwners: @fakeUser3 @fakeUser4