Merge pull request #205 from froque/multi-scm

closes #183 Plugin not working with multiple SCM configuration
This commit is contained in:
Owen Mehegan 2016-03-01 14:00:39 -08:00
commit 7eec9b7e70
3 changed files with 28 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.568</version>
<version>1.609</version>
</parent>
<artifactId>gitlab-plugin</artifactId>
@ -108,12 +108,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git</artifactId>
<version>2.3.1</version>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>git-client</artifactId>
<version>1.12.0</version>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>

View File

@ -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<Job<?, ?>> {
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<Job<?, ?>> {
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}",

View File

@ -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<RemoteConfig>()));
}
@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<RemoteConfig>()));
}
@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<RemoteConfig>()));
}
@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<RemoteConfig>()));
}
@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<RemoteConfig>()));
}
@Test