diff --git a/pom.xml b/pom.xml index 9ab7679..2702874 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.jenkins-ci.plugins plugin - 1.568 + 1.609 gitlab-plugin @@ -108,12 +108,12 @@ org.jenkins-ci.plugins git - 2.3.1 + 2.4.1 org.jenkins-ci.plugins git-client - 1.12.0 + 1.19.0 org.eclipse.jgit diff --git a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java index 1ef50ad..7c6ed42 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java @@ -29,6 +29,7 @@ import hudson.util.ListBoxModel.Option; import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -320,8 +321,15 @@ public class GitLabPushTrigger extends Trigger> { public RevisionParameterAction createPushRequestRevisionParameter(Job job, GitLabPushRequest req) { RevisionParameterAction revision = null; + URIish urIish = null; + try { + urIish = new URIish(req.getRepository().getUrl()); + } catch (URISyntaxException e) { + LOGGER.log(Level.WARNING, "could not parse URL"); + } + if (req.getLastCommit() !=null) { - revision = new RevisionParameterAction(req.getLastCommit().getId()); + revision = new RevisionParameterAction(req.getLastCommit().getId(), urIish); } else { if (req.getCheckout_sha() != null) { if (req.getCheckout_sha().contains("0000000000000000000000000000000000000000")) { @@ -329,11 +337,11 @@ public class GitLabPushTrigger extends Trigger> { LOGGER.log(Level.INFO, "GitLab Push {0} has been deleted, skip build .", req.getRef()); return null; } - revision = new RevisionParameterAction(req.getCheckout_sha()); + revision = new RevisionParameterAction(req.getCheckout_sha(), urIish); } else if (req.getBefore() != null && req.getBefore().contains("0000000000000000000000000000000000000000")) { // new branches - revision = new RevisionParameterAction(req.getAfter()); + revision = new RevisionParameterAction(req.getAfter(), urIish); } else { LOGGER.log(Level.WARNING, "unknown handled situation, dont know what revision to build for req {0} for job {1}", diff --git a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java index 959359d..bc31152 100644 --- a/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java +++ b/src/test/java/com/dabsquared/gitlabjenkins/AbstractGitLabPushTriggerGitlabServerTest.java @@ -3,8 +3,14 @@ package com.dabsquared.gitlabjenkins; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import hudson.plugins.git.GitSCM; +import jenkins.triggers.SCMTriggerItem; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.transport.RemoteConfig; import org.junit.Test; import com.dabsquared.gitlabjenkins.testhelpers.GitLabPushRequestSamples; @@ -12,6 +18,9 @@ import com.dabsquared.gitlabjenkins.testhelpers.GitLabPushRequestSamples; import hudson.model.Job; import hudson.plugins.git.RevisionParameterAction; +import java.util.ArrayList; +import java.util.Arrays; + public abstract class AbstractGitLabPushTriggerGitlabServerTest { protected GitLabPushTrigger pushTrigger; @@ -30,6 +39,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { // then assertThat(revisionParameterAction, is(notNullValue())); assertThat(revisionParameterAction.commit, is(pushRequest.getAfter())); + assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList())); } @Test @@ -44,6 +54,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { // then assertThat(revisionParameterAction, is(notNullValue())); assertThat(revisionParameterAction.commit, is(pushRequest.getAfter())); + assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList())); } @Test @@ -58,6 +69,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { // then assertThat(revisionParameterAction, is(notNullValue())); assertThat(revisionParameterAction.commit, is(pushRequest.getAfter())); + assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList())); } @Test @@ -72,6 +84,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { // then assertThat(revisionParameterAction, is(notNullValue())); assertThat(revisionParameterAction.commit, is(pushRequest.getAfter())); + assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList())); } @Test @@ -86,6 +99,7 @@ public abstract class AbstractGitLabPushTriggerGitlabServerTest { // then assertThat(revisionParameterAction, is(notNullValue())); assertThat(revisionParameterAction.commit, is(pushRequest.getAfter())); + assertFalse(revisionParameterAction.canOriginateFrom(new ArrayList())); } @Test