Support hyphen in name pre/post fixes of OWNERS files
Support OWNERS files with names like "pre-fix_OWNERS" and
"OWNERS_post-fix".
So far we matched the pre/post fixes with "\w" which is equivalent to
[A-Za-z0-9_] and hence doesn't match '-'.
Bug: Google b/324236264
Change-Id: I1a6d34c3a41ab257d663cfa3de6d2c1fc3acc22a
Signed-off-by: Edwin Kempin <ekempin@google.com>
Reviewed-on: https://gerrit-review.googlesource.com/c/plugins/code-owners/+/407819
Tested-by: Zuul <zuul-63@gerritcodereview-ci.iam.gserviceaccount.com>
Reviewed-by: Nitzan Gur-Furman <nitzan@google.com>
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/AbstractFileBasedCodeOwnerBackend.java b/java/com/google/gerrit/plugins/codeowners/backend/AbstractFileBasedCodeOwnerBackend.java
index 5dc8c9c..0e4e9e7 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/AbstractFileBasedCodeOwnerBackend.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/AbstractFileBasedCodeOwnerBackend.java
@@ -176,7 +176,7 @@
.getFileExtension()
.map(ext -> "." + ext)
.orElse(""));
- String nameExtension = "(\\w)+";
+ String nameExtension = "([A-Za-z0-9_-])+";
return Pattern.compile(
"^" + quotedDefaultFileName + "_" + nameExtension + quotedFileExtension + "$")
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
index d31939c..8927cdb 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
@@ -1359,10 +1359,20 @@
}
@Test
+ public void importCodeOwnerConfigWithPostFixThatContainsHyphen() throws Exception {
+ testImportCodeOwnerConfigWithNameExtension("OWNERS_post-fix");
+ }
+
+ @Test
public void importCodeOwnerConfigWithPreFix() throws Exception {
testImportCodeOwnerConfigWithNameExtension("pre_fix_OWNERS");
}
+ @Test
+ public void importCodeOwnerConfigWithPreFixThatContainsHyphen() throws Exception {
+ testImportCodeOwnerConfigWithNameExtension("pre-fix_OWNERS");
+ }
+
private void testImportCodeOwnerConfigWithNameExtension(String nameOfImportedCodeOwnerConfig)
throws Exception {
// create imported config with global code owner