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 6aa1915..7906b27 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() ) @@ -220,16 +220,39 @@ 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( - 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() + ) ); } }