diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java index 1c2cde44..f38594e5 100644 --- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java +++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait.java @@ -16,6 +16,7 @@ public class BuildStatusNameCustomPartTrait extends SCMSourceTrait { private String buildStatusNameCustomPart = ""; private boolean buildStatusNameOverwrite; + private boolean ignoreTypeInStatusName; /** * Constructor for stapler. @@ -38,12 +39,18 @@ public void setBuildStatusNameOverwrite(@NonNull Boolean buildStatusNameOverwrit this.buildStatusNameOverwrite = buildStatusNameOverwrite; } + @DataBoundSetter + public void setIgnoreTypeInStatusName(@NonNull Boolean ignoreTypeInStatusName) { + this.ignoreTypeInStatusName = ignoreTypeInStatusName; + } + @Override protected void decorateContext(SCMSourceContext context) { if (context instanceof GitLabSCMSourceContext) { GitLabSCMSourceContext ctx = (GitLabSCMSourceContext) context; ctx.withBuildStatusNameCustomPart(getBuildStatusNameCustomPart()); ctx.withBuildStatusNameOverwrite(getBuildStatusNameOverwrite()); + ctx.withIgnoreTypeInStatusName(getIgnoreTypeInStatusName()); } } @@ -66,6 +73,15 @@ public boolean getBuildStatusNameOverwrite() { return buildStatusNameOverwrite; } + /** + * Getter method for the build status name overwrite + * + * @return build status name overwrite option + */ + public boolean getIgnoreTypeInStatusName() { + return ignoreTypeInStatusName; + } + /** * Our descriptor. */ diff --git a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java index 9e92aa9d..b8462dc9 100644 --- a/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java +++ b/src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSourceContext.java @@ -53,6 +53,8 @@ public class GitLabSCMSourceContext extends SCMSourceContext "Retrieved status name is: " + statusName); return statusName; } diff --git a/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/config.jelly b/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/config.jelly index df194f88..bc060d94 100644 --- a/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/config.jelly +++ b/src/main/resources/io/jenkins/plugins/gitlabbranchsource/BuildStatusNameCustomPartTrait/config.jelly @@ -6,4 +6,7 @@ + + + diff --git a/src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifierTest.java b/src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifierTest.java index b48b97fe..11dc9760 100644 --- a/src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifierTest.java +++ b/src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifierTest.java @@ -42,6 +42,41 @@ public void should_set_branch_status_name() { + "branch")); } + @Test + public void should_set_branch_status_name_withBuildStatusNameCustomPart() { + GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null, null); + sourceContext.withBuildStatusNameCustomPart("CUSTOM"); + sourceContext.withBuildStatusNameOverwrite(false); + + BranchSCMHead head = new BranchSCMHead("head"); + SCMRevision revision = new BranchSCMRevision(head, "hash"); + + String statusName = + GitLabPipelineStatusNotifier.getStatusName(sourceContext, null, revision, new hudson.EnvVars()); + + assertThat( + statusName, + is(GitLabPipelineStatusNotifier.GITLAB_PIPELINE_STATUS_PREFIX + + GitLabPipelineStatusNotifier.GITLAB_PIPELINE_STATUS_DELIMITER + + "CUSTOM" + + GitLabPipelineStatusNotifier.GITLAB_PIPELINE_STATUS_DELIMITER + + "branch")); + } + + @Test + public void should_set_branch_status_name_withIgnoreTypeInStatusName() { + GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null, null); + sourceContext.withIgnoreTypeInStatusName(true); + + BranchSCMHead head = new BranchSCMHead("head"); + SCMRevision revision = new BranchSCMRevision(head, "hash"); + + String statusName = + GitLabPipelineStatusNotifier.getStatusName(sourceContext, null, revision, new hudson.EnvVars()); + + assertThat(statusName, is(GitLabPipelineStatusNotifier.GITLAB_PIPELINE_STATUS_PREFIX)); + } + @Test public void should_set_merge_request_head_status_name() { GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null, null);