Skip to content

Commit 0ddadb8

Browse files
authored
Use strategies from SCM to the build name job (#291)
1 parent 0c0c463 commit 0ddadb8

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabMergeRequestCauseData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GitLabMergeRequestCauseData {
2121
private Map<String, String> variables = new HashMap<>();
2222

2323
public GitLabMergeRequestCauseData(MergeRequestEvent mergeRequestEvent) {
24-
this.variables.put("GITLAB_OBJECT_KIND", defaultString(mergeRequestEvent.OBJECT_KIND));
24+
this.variables.put("GITLAB_OBJECT_KIND", defaultString(MergeRequestEvent.OBJECT_KIND));
2525
this.variables.put("GITLAB_USER_NAME", defaultString(mergeRequestEvent.getUser().getName()));
2626
this.variables.put("GITLAB_USER_USERNAME", defaultString(mergeRequestEvent.getUser().getUsername()));
2727
this.variables.put("GITLAB_USER_AVATAR_URL", defaultString(mergeRequestEvent.getUser().getAvatarUrl()));

src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabPushCauseData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class GitLabPushCauseData {
1717
private Map<String, String> variables = new HashMap<>();
1818

1919
public GitLabPushCauseData(PushEvent pushEvent) {
20-
this.variables.put("GITLAB_OBJECT_KIND", defaultString(pushEvent.OBJECT_KIND));
20+
this.variables.put("GITLAB_OBJECT_KIND", defaultString(PushEvent.OBJECT_KIND));
2121
this.variables.put("GITLAB_AFTER", defaultString(pushEvent.getAfter()));
2222
this.variables.put("GITLAB_BEFORE", defaultString(pushEvent.getBefore()));
2323
this.variables.put("GITLAB_REF", defaultString(pushEvent.getRef()));

src/main/java/io/jenkins/plugins/gitlabbranchsource/Cause/GitLabTagPushCauseData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class GitLabTagPushCauseData {
1717
private Map<String, String> variables = new HashMap<>();
1818

1919
public GitLabTagPushCauseData(TagPushEvent tagPushEvent) {
20-
this.variables.put("GITLAB_OBJECT_KIND", defaultString(tagPushEvent.OBJECT_KIND));
20+
this.variables.put("GITLAB_OBJECT_KIND", defaultString(TagPushEvent.OBJECT_KIND));
2121
this.variables.put("GITLAB_AFTER", defaultString(tagPushEvent.getAfter()));
2222
this.variables.put("GITLAB_BEFORE", defaultString(tagPushEvent.getBefore()));
2323
this.variables.put("GITLAB_REF", defaultString(tagPushEvent.getRef()));

src/main/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static String getStatusName(final GitLabSCMSourceContext sourceContext, final St
103103
if (revision instanceof BranchSCMRevision) {
104104
type = "branch";
105105
} else if (revision instanceof MergeRequestSCMRevision) {
106-
type = getMrBuildName(fullDisplayName);
106+
type = getMrBuildName((MergeRequestSCMRevision)revision);
107107
} else if (revision instanceof GitTagSCMRevision) {
108108
type = "tag";
109109
} else {
@@ -137,8 +137,8 @@ static String getRevisionRef(final SCMRevision revision) {
137137
return refName;
138138
}
139139

140-
private static String getMrBuildName(final String buildName) {
141-
return (buildName.contains("merge") ? "mr-merge" : "mr-head");
140+
private static String getMrBuildName(final MergeRequestSCMRevision revision) {
141+
return (revision.isMerge() ? "mr-merge" : "mr-head");
142142
}
143143

144144
/**

src/test/java/io/jenkins/plugins/gitlabbranchsource/helpers/GitLabPipelineStatusNotifierTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import jenkins.plugins.git.GitTagSCMHead;
1212
import jenkins.plugins.git.GitTagSCMRevision;
1313
import jenkins.scm.api.SCMRevision;
14+
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
1415
import org.gitlab4j.api.GitLabApi;
1516
import org.gitlab4j.api.MergeRequestApi;
1617
import org.gitlab4j.api.models.MergeRequest;
@@ -44,7 +45,7 @@ public void should_set_merge_request_head_status_name() {
4445
GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null, null);
4546

4647
BranchSCMHead targetHead = new BranchSCMHead("target");
47-
MergeRequestSCMHead head = new MergeRequestSCMHead("head", 0, targetHead, null, null, null, null, null, null);
48+
MergeRequestSCMHead head = new MergeRequestSCMHead("head", 0, targetHead, ChangeRequestCheckoutStrategy.HEAD, null, null, null, null, null);
4849

4950
BranchSCMRevision target = new BranchSCMRevision(targetHead, "target-hash");
5051
BranchSCMRevision source = new BranchSCMRevision(new BranchSCMHead("source"), "source-hash");
@@ -63,7 +64,7 @@ public void should_set_merge_request_merge_status_name() {
6364
GitLabSCMSourceContext sourceContext = new GitLabSCMSourceContext(null, null);
6465

6566
BranchSCMHead targetHead = new BranchSCMHead("target");
66-
MergeRequestSCMHead head = new MergeRequestSCMHead("head", 0, targetHead, null, null, null, null, null, null);
67+
MergeRequestSCMHead head = new MergeRequestSCMHead("head", 0, targetHead, ChangeRequestCheckoutStrategy.MERGE, null, null, null, null, null);
6768

6869
BranchSCMRevision target = new BranchSCMRevision(targetHead, "target-hash");
6970
BranchSCMRevision source = new BranchSCMRevision(new BranchSCMHead("source"), "source-hash");

0 commit comments

Comments
 (0)