99import hudson .scm .SCM ;
1010import hudson .scm .SCMDescriptor ;
1111import java .io .IOException ;
12- import jenkins .plugins .git .GitTagSCMRevision ;
1312import jenkins .scm .api .SCMFile ;
1413import jenkins .scm .api .SCMFileSystem ;
1514import jenkins .scm .api .SCMHead ;
1615import jenkins .scm .api .SCMRevision ;
1716import jenkins .scm .api .SCMSource ;
1817import jenkins .scm .api .SCMSourceDescriptor ;
18+ import jenkins .scm .api .mixin .ChangeRequestCheckoutStrategy ;
1919import org .gitlab4j .api .GitLabApi ;
2020import org .gitlab4j .api .GitLabApiException ;
2121
@@ -30,19 +30,7 @@ protected GitLabSCMFileSystem(GitLabApi gitLabApi, String projectPath, String re
3030 super (rev );
3131 this .gitLabApi = gitLabApi ;
3232 this .projectPath = projectPath ;
33- if (rev != null ) {
34- if (rev .getHead () instanceof MergeRequestSCMHead ) {
35- this .ref = ((MergeRequestSCMRevision ) rev ).getOrigin ().getHash ();
36- } else if (rev instanceof BranchSCMRevision ) {
37- this .ref = ((BranchSCMRevision ) rev ).getHash ();
38- } else if (rev instanceof GitTagSCMRevision ) {
39- this .ref = ((GitTagSCMRevision ) rev ).getHash ();
40- } else {
41- this .ref = ref ;
42- }
43- } else {
44- this .ref = ref ;
45- }
33+ this .ref = ref ;
4634 }
4735
4836 @ Override
@@ -109,7 +97,17 @@ public SCMFileSystem build(
10997 throws IOException , InterruptedException {
11098 String ref ;
11199 if (head instanceof MergeRequestSCMHead ) {
112- ref = ((MergeRequestSCMHead ) head ).getOriginName ();
100+ MergeRequestSCMHead mrHead = (MergeRequestSCMHead ) head ;
101+ ChangeRequestCheckoutStrategy checkoutStrategy = mrHead .getCheckoutStrategy ();
102+ String mrRef ;
103+ if (checkoutStrategy == ChangeRequestCheckoutStrategy .HEAD ) {
104+ mrRef = "head" ;
105+ } else if (checkoutStrategy == ChangeRequestCheckoutStrategy .MERGE ) {
106+ mrRef = "merge" ;
107+ } else {
108+ return null ;
109+ }
110+ ref = String .format ("merge-requests/%s/%s" , mrHead .getId (), mrRef );
113111 } else if (head instanceof BranchSCMHead ) {
114112 ref = head .getName ();
115113 } else if (head instanceof GitLabTagSCMHead ) {
0 commit comments