From fdd92ee6dc029114657cb00a50a0852ded95dacd Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Sat, 2 Sep 2023 09:02:21 -0700 Subject: [PATCH] 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(