diff --git a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java index a44108b70..cc2a5c46e 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java @@ -83,6 +83,7 @@ public class GitLabPushTrigger extends Trigger> { private boolean ciSkip = true; private boolean setBuildDescription = true; private boolean addNoteOnMergeRequest = true; + private boolean addCiMessage = false; private boolean addVoteOnMergeRequest = true; private final String branchFilterName; private final String includeBranchesSpec; @@ -93,7 +94,7 @@ public class GitLabPushTrigger extends Trigger> { @DataBoundConstructor public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest, String triggerOpenMergeRequestOnPush, - boolean ciSkip, boolean setBuildDescription, boolean addNoteOnMergeRequest, + boolean ciSkip, boolean setBuildDescription, boolean addNoteOnMergeRequest, boolean addCiMessage, boolean addVoteOnMergeRequest, boolean acceptMergeRequestOnSuccess, String branchFilterName, String includeBranchesSpec, String excludeBranchesSpec, String targetBranchRegex) { this.triggerOnPush = triggerOnPush; @@ -102,6 +103,7 @@ public GitLabPushTrigger(boolean triggerOnPush, boolean triggerOnMergeRequest, S this.ciSkip = ciSkip; this.setBuildDescription = setBuildDescription; this.addNoteOnMergeRequest = addNoteOnMergeRequest; + this.addCiMessage = addCiMessage; this.addVoteOnMergeRequest = addVoteOnMergeRequest; this.branchFilterName = branchFilterName; this.includeBranchesSpec = includeBranchesSpec; @@ -138,6 +140,22 @@ public boolean getAcceptMergeRequestOnSuccess() { return acceptMergeRequestOnSuccess; } + /** + * @deprecated see {@link com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher} + */ + @Deprecated + public boolean getAddCiMessage() { + return addCiMessage; + } + + /** + * @deprecated see {@link com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher} + */ + @Deprecated + public void setAddCiMessage(boolean addCiMessage) { + this.addCiMessage = addCiMessage; + } + public boolean getCiSkip() { return ciSkip; } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/migration/JobConfigMigration.java b/src/main/java/com/dabsquared/gitlabjenkins/migration/JobConfigMigration.java new file mode 100644 index 000000000..a6d0cfcd0 --- /dev/null +++ b/src/main/java/com/dabsquared/gitlabjenkins/migration/JobConfigMigration.java @@ -0,0 +1,44 @@ +package com.dabsquared.gitlabjenkins.migration; + +import com.dabsquared.gitlabjenkins.GitLabPushTrigger; +import com.dabsquared.gitlabjenkins.publisher.GitLabCommitStatusPublisher; +import com.thoughtworks.xstream.converters.UnmarshallingContext; +import hudson.Plugin; +import hudson.model.Descriptor; +import hudson.model.Items; +import hudson.model.Project; +import hudson.tasks.Publisher; +import hudson.util.DescribableList; +import hudson.util.XStream2; + +/** + * This plugin registers a {@link XStream2.PassthruConverter} that migrates jobs that have the {@link GitLabPushTrigger} + * configured to use the new publisher ({@link GitLabCommitStatusPublisher} if necessary. + * + * @author Robin Müller + */ +public class JobConfigMigration extends Plugin { + + @Override + public void start() throws Exception { + Items.XSTREAM2.registerConverter(new XStream2.PassthruConverter>(Items.XSTREAM2) { + @Override + protected void callback(Project project, UnmarshallingContext context) { + GitLabPushTrigger trigger = project.getTrigger(GitLabPushTrigger.class); + if (trigger != null) { + DescribableList> publishers = project.getPublishersList(); + publishers.setOwner(NOOP); + if (trigger.getAddCiMessage()) { + publishers.add(new GitLabCommitStatusPublisher()); + trigger.setAddCiMessage(false); + } + } + } + + @Override + public boolean canConvert(Class type) { + return Project.class.isAssignableFrom(type); + } + }); + } +} diff --git a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java index dbb68d71f..959359dc8 100644 --- a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java +++ b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java @@ -108,6 +108,7 @@ protected GitLabPushTrigger setUpWithPushTrigger() { boolean ciSkip = false; boolean setBuildDescription = true; boolean addNoteOnMergeRequest = true; + boolean addCiMessage = true; boolean addVoteOnMergeRequest = true; boolean acceptMergeRequestOnSuccess = false; String branchFilter = null; @@ -115,7 +116,7 @@ protected GitLabPushTrigger setUpWithPushTrigger() { String excludeBranchesSpec = null; String targetBranchRegex = null; GitLabPushTrigger gitLabPushTrigger = new GitLabPushTrigger(triggerOnPush, triggerOnMergeRequest, - triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest, + triggerOpenMergeRequestOnPush, ciSkip, setBuildDescription, addNoteOnMergeRequest, addCiMessage, addVoteOnMergeRequest, acceptMergeRequestOnSuccess, branchFilter, includeBranchesSpec, excludeBranchesSpec, targetBranchRegex);