From cb7d9f1ed6f65a57ed3d5e3158a8256ce32a703a Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Sat, 2 Sep 2023 08:53:17 -0700 Subject: [PATCH 1/2] style(AddTeamToCodeownersTest): apply auto-formatting --- .../github/AddTeamToCodeownersTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java index 6aa1915..a141dc3 100644 --- a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java +++ b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java @@ -61,8 +61,8 @@ void shouldAddFileIfMissing() { pomXml(POM), text(null, """ - * @jenkinsci/sample-plugin-developers - """, + * @jenkinsci/sample-plugin-developers + """, s -> s.path(".github/CODEOWNERS").noTrim() ) ); @@ -78,7 +78,7 @@ void shouldAddLineIfTeamNotDefinedForAllRetainingTrailingSpace() { * @global-owner1 @global-owner2 *.js @js-owner #This is an inline comment. /build/logs/ @doctocat - + """, """ # This is a comment. @@ -86,7 +86,7 @@ void shouldAddLineIfTeamNotDefinedForAllRetainingTrailingSpace() { * @global-owner1 @global-owner2 *.js @js-owner #This is an inline comment. /build/logs/ @doctocat - + """, s -> s.path(".github/CODEOWNERS").noTrim() ) @@ -223,13 +223,13 @@ void shouldNoOpIfInvalidTeamGenerated() { @Test void shouldNotModifyNonCodeowners() { rewriteRun( - pomXml(POM), - text("*.iml", - s -> s.path(".gitignore")), - text( - "* @jenkinsci/sample-plugin-developers", - s -> s.path(".github/CODEOWNERS").noTrim() - ) + pomXml(POM), + text("*.iml", + s -> s.path(".gitignore")), + text( + "* @jenkinsci/sample-plugin-developers", + s -> s.path(".github/CODEOWNERS").noTrim() + ) ); } } From fdd92ee6dc029114657cb00a50a0852ded95dacd Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Sat, 2 Sep 2023 09:02:21 -0700 Subject: [PATCH 2/2] fix(AddTeamToCodeowners): skip file generation if team name invalid Closes #49 --- .../jenkins/github/AddTeamToCodeowners.java | 2 +- .../github/AddTeamToCodeownersTest.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/jenkins/github/AddTeamToCodeowners.java b/src/main/java/org/openrewrite/jenkins/github/AddTeamToCodeowners.java index cff1fb6..31968c8 100644 --- a/src/main/java/org/openrewrite/jenkins/github/AddTeamToCodeowners.java +++ b/src/main/java/org/openrewrite/jenkins/github/AddTeamToCodeowners.java @@ -80,7 +80,7 @@ public Tree visit(@Nullable Tree tree, ExecutionContext executionContext, Cursor @Override public Collection generate(Scanned acc, ExecutionContext ctx) { - if (acc.foundFile) { + if (acc.foundFile || !acc.hasValidTeamName()) { return Collections.emptyList(); } PlainTextParser parser = new PlainTextParser(); diff --git a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java index a141dc3..7906b27 100644 --- a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java +++ b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java @@ -220,6 +220,29 @@ void shouldNoOpIfInvalidTeamGenerated() { ); } + @Test + void shouldNoOpIfInvalidTeamGeneratedAndCodeownersFileAbsent() { + rewriteRun( + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.72 + + tool-labels-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """) + ); + } + @Test void shouldNotModifyNonCodeowners() { rewriteRun(