Merge pull request #516 from czoellin/pipeline_merge_request_hook

Have OpenMergeRequestPushHookTriggerHandler accept pipeline/workflow …
This commit is contained in:
Owen Mehegan 2017-05-17 17:15:03 -07:00 committed by GitHub
commit ef2d689544
1 changed files with 24 additions and 12 deletions

View File

@ -20,8 +20,12 @@ import hudson.model.Action;
import hudson.model.CauseAction;
import hudson.model.Job;
import hudson.plugins.git.RevisionParameterAction;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.model.ParameterizedJobMixIn.ParameterizedJob;
import org.eclipse.jgit.transport.URIish;
import javax.ws.rs.ProcessingException;
@ -30,6 +34,7 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -52,10 +57,12 @@ class OpenMergeRequestPushHookTriggerHandler implements PushHookTriggerHandler {
@Override
public void handle(Job<?, ?> job, PushHook hook, boolean ciSkip, BranchFilter branchFilter, MergeRequestLabelFilter mergeRequestLabelFilter) {
try {
if (job instanceof AbstractProject<?, ?>) {
AbstractProject<?, ?> project = (AbstractProject<?, ?>) job;
if (job instanceof ParameterizedJobMixIn.ParameterizedJob) {
ParameterizedJob project = (ParameterizedJobMixIn.ParameterizedJob) job;
GitLabConnectionProperty property = job.getProperty(GitLabConnectionProperty.class);
final GitLabPushTrigger trigger = project.getTrigger(GitLabPushTrigger.class);
for (Trigger t : project.getTriggers().values()) {
if (t instanceof GitLabPushTrigger) {
final GitLabPushTrigger trigger = (GitLabPushTrigger) t;
Integer projectId = hook.getProjectId();
if (property != null && property.getClient() != null && projectId != null && trigger != null) {
GitLabApi client = property.getClient();
@ -66,6 +73,11 @@ class OpenMergeRequestPushHookTriggerHandler implements PushHookTriggerHandler {
}
}
}
}
} else {
LOGGER.log(Level.FINE, "Not a ParameterizedJob: {0}",LoggerUtil.toArray(job.getClass().getName()));
}
} catch (WebApplicationException | ProcessingException e) {
LOGGER.log(Level.WARNING, "Failed to communicate with gitlab server to determine if this is an update for a merge request: " + e.getMessage(), e);
}