forked from Praqma/pretested-integration-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-30192] Added JobDSL support
Added plugin requirement for Job DSL Removed shorthand integration strategies Added some tests for the DSL
- Loading branch information
1 parent
260a3bc
commit ad7569e
Showing
3 changed files
with
106 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
54 changes: 54 additions & 0 deletions
54
.../java/org/jenkinsci/plugins/pretestedintegration/PretestedIntegrationJobDslExtension.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,54 @@ | ||
package org.jenkinsci.plugins.pretestedintegration; | ||
|
||
import hudson.Extension; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import static javaposse.jobdsl.dsl.Preconditions.checkArgument; | ||
import javaposse.jobdsl.dsl.RequiresPlugin; | ||
import javaposse.jobdsl.dsl.helpers.wrapper.WrapperContext; | ||
import javaposse.jobdsl.plugin.ContextExtensionPoint; | ||
import javaposse.jobdsl.plugin.DslExtensionMethod; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.AccumulatedCommitStrategy; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.GitBridge; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.SquashCommitStrategy; | ||
|
||
/* | ||
``` | ||
job{ | ||
wrappers{ | ||
pretestedIntegration(String integrationStrategy, String branch, String repository) | ||
} | ||
} | ||
``` | ||
Valid values for `integrationStrategy` are 'ACCUMULATED' and 'SQUASHED'. | ||
``` | ||
job("pi-job"){ | ||
wrappers{ | ||
pretestedIntegration("SQUASHED","master","origin") | ||
} | ||
} | ||
``` | ||
*/ | ||
|
||
@Extension(optional = true) | ||
public class PretestedIntegrationJobDslExtension extends ContextExtensionPoint { | ||
final List<String> strategies = Arrays.asList("ACCUMULATED", "SQUASHED"); | ||
|
||
@RequiresPlugin(id = "pretested-integration", minimumVersion = "2.3.0") | ||
@DslExtensionMethod(context = WrapperContext.class) | ||
public Object pretestedIntegration(String strategy, String branch, String repo) { | ||
checkArgument(strategies.contains(strategy), "Strategy must be one of " + strategies); | ||
IntegrationStrategy integrationStrategy = null; | ||
switch (strategy) { | ||
case "ACCUMULATED": | ||
integrationStrategy = new AccumulatedCommitStrategy(); | ||
break; | ||
case "SQUASHED": | ||
integrationStrategy = new SquashCommitStrategy(); | ||
break; | ||
} | ||
return new PretestedIntegrationBuildWrapper(new GitBridge(integrationStrategy, branch, repo)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...a/org/jenkinsci/plugins/pretestedintegration/PretestedIntegrationJobDslExtensionTest.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,46 @@ | ||
package org.jenkinsci.plugins.pretestedintegration; | ||
|
||
import javaposse.jobdsl.dsl.DslScriptException; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.AccumulatedCommitStrategy; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.GitBridge; | ||
import org.jenkinsci.plugins.pretestedintegration.scm.git.SquashCommitStrategy; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class PretestedIntegrationJobDslExtensionTest { | ||
|
||
@Test | ||
public void testDslWithSquash() throws Exception { | ||
Object node = new PretestedIntegrationJobDslExtension().pretestedIntegration("SQUASHED", "branch", "repo"); | ||
assertThat(node, instanceOf(PretestedIntegrationBuildWrapper.class)); | ||
PretestedIntegrationBuildWrapper wrapper = (PretestedIntegrationBuildWrapper)node; | ||
|
||
assertThat(wrapper.scmBridge, instanceOf(GitBridge.class)); | ||
GitBridge bridge = (GitBridge)wrapper.scmBridge; | ||
|
||
assertThat(bridge.integrationStrategy, instanceOf(SquashCommitStrategy.class)); | ||
assertEquals(bridge.getBranch(), "branch"); | ||
assertEquals(bridge.getRepoName(), "repo"); | ||
} | ||
|
||
@Test | ||
public void testDslWithAccumulated() throws Exception { | ||
Object node = new PretestedIntegrationJobDslExtension().pretestedIntegration("ACCUMULATED", "branch", "repo"); | ||
assertThat(node, instanceOf(PretestedIntegrationBuildWrapper.class)); | ||
PretestedIntegrationBuildWrapper wrapper = (PretestedIntegrationBuildWrapper)node; | ||
|
||
assertThat(wrapper.scmBridge, instanceOf(GitBridge.class)); | ||
GitBridge bridge = (GitBridge)wrapper.scmBridge; | ||
|
||
assertThat(bridge.integrationStrategy, instanceOf(AccumulatedCommitStrategy.class)); | ||
assertEquals(bridge.getBranch(), "branch"); | ||
assertEquals(bridge.getRepoName(), "repo"); | ||
} | ||
|
||
@Test(expected = DslScriptException.class) | ||
public void testDslWithInvalidStrategy() throws Exception { | ||
new PretestedIntegrationJobDslExtension().pretestedIntegration("b0rk", "branch", "repo"); | ||
} | ||
} |