-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #528 from jonesbusy/feature/remove-release-drafter
Add recipe to remove release drafter if cd is present
- Loading branch information
Showing
9 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...re/src/main/java/io/jenkins/tools/pluginmodernizer/core/recipes/RemoveReleaseDrafter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.jenkins.tools.pluginmodernizer.core.recipes; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.openrewrite.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Remove release drafter if CD is in place (overlap of workflow) | ||
*/ | ||
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "No user input") | ||
public class RemoveReleaseDrafter extends ScanningRecipe<AtomicBoolean> { | ||
|
||
/** | ||
* LOGGER. | ||
*/ | ||
private static final Logger LOG = LoggerFactory.getLogger(RemoveReleaseDrafter.class); | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Remove release drafter if CD is in place"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove the release drafter file if CD is in place."; | ||
} | ||
|
||
@Override | ||
public AtomicBoolean getInitialValue(ExecutionContext ctx) { | ||
return new AtomicBoolean(false); | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getScanner(AtomicBoolean shouldRemove) { | ||
return new TreeVisitor<>() { | ||
|
||
@Override | ||
public Tree visit(Tree tree, ExecutionContext ctx) { | ||
SourceFile sourceFile = (SourceFile) tree; | ||
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.WORKFLOW_CD.getPath())) { | ||
LOG.info("Project is using CD. Need to remove release drafter."); | ||
shouldRemove.set(true); | ||
} | ||
return tree; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor(AtomicBoolean shouldRemove) { | ||
return new TreeVisitor<>() { | ||
@Override | ||
public Tree visit(Tree tree, ExecutionContext ctx) { | ||
LOG.info("Checking if release drafter should be removed"); | ||
if (shouldRemove.get() && tree instanceof SourceFile sourceFile) { | ||
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.RELEASE_DRAFTER.getPath())) { | ||
LOG.info("Deleting release drafter file: {}", sourceFile.getSourcePath()); | ||
return null; | ||
} | ||
if (sourceFile.getSourcePath().equals(ArchetypeCommonFile.RELEASE_DRAFTER_WORKFLOW.getPath())) { | ||
LOG.info("Deleting release drafter workflow file: {}", sourceFile.getSourcePath()); | ||
return null; | ||
} | ||
} | ||
return tree; | ||
} | ||
}; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
plugin-modernizer-core/src/main/jte/pr-title-RemoveReleaseDrafter.jte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Recipe | ||
@param Plugin plugin | ||
@param Recipe recipe | ||
Remove release drafter due to enabled cd |
5 changes: 5 additions & 0 deletions
5
plugin-modernizer-core/src/main/jte/pr-title-SetupDependabot.jte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Plugin | ||
@import io.jenkins.tools.pluginmodernizer.core.model.Recipe | ||
@param Plugin plugin | ||
@param Recipe recipe | ||
Automate dependency updates with Dependabot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...rc/test/java/io/jenkins/tools/pluginmodernizer/core/recipes/RemoveReleaseDrafterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.jenkins.tools.pluginmodernizer.core.recipes; | ||
|
||
import static org.openrewrite.yaml.Assertions.yaml; | ||
|
||
import io.jenkins.tools.pluginmodernizer.core.extractor.ArchetypeCommonFile; | ||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
/** | ||
* Test for {@link RemoveReleaseDrafter}. | ||
*/ | ||
public class RemoveReleaseDrafterTest implements RewriteTest { | ||
|
||
@Test | ||
void shouldNotRemoveReleaseDrafter() { | ||
rewriteRun( | ||
spec -> spec.recipe(new RemoveReleaseDrafter()), | ||
// language=yaml | ||
yaml("{}", sourceSpecs -> { | ||
sourceSpecs.path(ArchetypeCommonFile.RELEASE_DRAFTER.getPath()); | ||
}), | ||
yaml("{}", sourceSpecs -> { | ||
sourceSpecs.path(ArchetypeCommonFile.RELEASE_DRAFTER_WORKFLOW.getPath()); | ||
})); | ||
} | ||
|
||
@Test | ||
void shouldRemoveReleaseDrafterIfContinuousDeliveryEnabled() { | ||
rewriteRun( | ||
spec -> spec.recipe(new RemoveReleaseDrafter()), | ||
// language=yaml | ||
yaml("{}", sourceSpecs -> { | ||
sourceSpecs.path(ArchetypeCommonFile.WORKFLOW_CD.getPath()); | ||
}), | ||
yaml("{}", null, sourceSpecs -> { | ||
sourceSpecs.path(ArchetypeCommonFile.RELEASE_DRAFTER.getPath()); | ||
}), | ||
yaml("{}", null, sourceSpecs -> { | ||
sourceSpecs.path(ArchetypeCommonFile.RELEASE_DRAFTER_WORKFLOW.getPath()); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters