MR webhook compatibility

This commit is contained in:
Xinran Xiao 2016-05-18 11:09:04 -07:00
parent 88d0f92ad2
commit 89cbe2515d
1 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,8 @@ package com.dabsquared.gitlabjenkins.webhook.build;
import com.dabsquared.gitlabjenkins.GitLabPushTrigger;
import com.dabsquared.gitlabjenkins.gitlab.hook.model.MergeRequestHook;
import com.dabsquared.gitlabjenkins.gitlab.hook.model.ObjectAttributes;
import com.dabsquared.gitlabjenkins.gitlab.hook.model.Project;
import com.dabsquared.gitlabjenkins.util.JsonUtil;
import com.dabsquared.gitlabjenkins.webhook.WebHookAction;
import hudson.model.Job;
@ -29,10 +31,21 @@ public class MergeRequestBuildAction extends BuildWebHookAction {
this.mergeRequestHook = JsonUtil.read(json, MergeRequestHook.class);
}
/**
* Noop for merge request hooks.
*/
void processForCompatibility() {}
void processForCompatibility() {
// url and homepage are introduced in 8.x versions of Gitlab
final ObjectAttributes attributes = this.mergeRequestHook.getObjectAttributes();
if (attributes != null) {
final Project source = attributes.getSource();
if (source != null && source.getHttpUrl() != null) {
if (source.getUrl() == null) {
source.setUrl(source.getHttpUrl());
}
if (source.getHomepage() == null) {
source.setHomepage(source.getHttpUrl().substring(0, source.getHttpUrl().lastIndexOf(".git")));
}
}
}
}
public void execute() {
ACL.impersonate(ACL.SYSTEM, new Runnable() {