Merge pull request #311 from team-supercharge/fix-commit-status

Fix finding related commit of the build
This commit is contained in:
Robin Müller 2016-05-19 20:46:03 +02:00
commit 6e2de7c63d
2 changed files with 8 additions and 1 deletions

View File

@ -64,7 +64,9 @@ public class CommitStatusUpdater {
}
private static String getBuildRevision(Run<?, ?> build) {
return build.getAction(BuildData.class).getLastBuiltRevision().getSha1String();
BuildData action = build.getAction(BuildData.class);
return action.getLastBuild(action.getLastBuiltRevision().getSha1()).getMarked().getSha1String();
}
private static boolean existsCommit(GitLabApi client, String gitlabProjectId, String commitHash) {

View File

@ -17,9 +17,11 @@ import hudson.model.Result;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
import hudson.plugins.git.Revision;
import hudson.plugins.git.util.Build;
import hudson.plugins.git.util.BuildData;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.eclipse.jgit.lib.ObjectId;
import org.hamcrest.CoreMatchers;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.junit.After;
@ -226,6 +228,9 @@ public class GitLabCommitStatusPublisherTest {
when(revision.getSha1String()).thenReturn(sha);
when(buildData.getLastBuiltRevision()).thenReturn(revision);
when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(remoteUrls)));
Build gitBuild = mock(Build.class);
when(gitBuild.getMarked()).thenReturn(revision);
when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild);
when(build.getAction(BuildData.class)).thenReturn(buildData);
when(build.getResult()).thenReturn(result);
when(build.getUrl()).thenReturn(buildUrl);