Skip to content

Commit

Permalink
Add functionality to add the new publisher automatically to old jobs …
Browse files Browse the repository at this point in the history
…if addCiMessage was activated for the GitLabPushTrigger
  • Loading branch information
coder-hugo committed Feb 16, 2016
1 parent 8b9c886 commit 9c62979
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
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;
Expand All @@ -93,7 +94,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {

@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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project<?, ?>>(Items.XSTREAM2) {
@Override
protected void callback(Project<?, ?> project, UnmarshallingContext context) {
GitLabPushTrigger trigger = project.getTrigger(GitLabPushTrigger.class);
if (trigger != null) {
DescribableList<Publisher, Descriptor<Publisher>> 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);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ protected GitLabPushTrigger setUpWithPushTrigger() {
boolean ciSkip = false;
boolean setBuildDescription = true;
boolean addNoteOnMergeRequest = true;
boolean addCiMessage = true;
boolean addVoteOnMergeRequest = true;
boolean acceptMergeRequestOnSuccess = false;
String branchFilter = null;
String includeBranchesSpec = null;
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);

Expand Down

0 comments on commit 9c62979

Please sign in to comment.