@@ -843,36 +843,35 @@ private void retrieveTags(final BitbucketSCMSourceRequest request) throws IOExce
843
843
protected SCMRevision retrieve (SCMHead head , TaskListener listener ) throws IOException , InterruptedException {
844
844
final BitbucketApi bitbucket = buildBitbucketClient ();
845
845
try {
846
- if (head instanceof PullRequestSCMHead ) {
847
- PullRequestSCMHead h = (PullRequestSCMHead ) head ;
846
+ if (head instanceof PullRequestSCMHead prHead ) {
848
847
BitbucketCommit sourceRevision ;
849
848
BitbucketCommit targetRevision ;
850
849
851
850
if (bitbucket instanceof BitbucketCloudApiClient ) {
852
851
// Bitbucket Cloud /pullrequests/{id} API endpoint only returns short commit IDs of the source
853
852
// and target branch. We therefore retrieve the branches directly
854
- BitbucketBranch targetBranch = bitbucket .getBranch (h .getTarget ().getName ());
853
+ BitbucketBranch targetBranch = bitbucket .getBranch (prHead .getTarget ().getName ());
855
854
856
855
if (targetBranch == null ) {
857
856
listener .getLogger ().format ("No branch found in {0}/{1} with name [{2}]" ,
858
- repoOwner , repository , h .getTarget ().getName ());
857
+ repoOwner , repository , prHead .getTarget ().getName ());
859
858
return null ;
860
859
}
861
860
targetRevision = findCommit (targetBranch , listener );
862
861
863
862
if (targetRevision == null ) {
864
863
listener .getLogger ().format ("No branch found in {0}/{1} with name [{2}]" ,
865
- repoOwner , repository , h .getTarget ().getName ());
864
+ repoOwner , repository , prHead .getTarget ().getName ());
866
865
return null ;
867
866
}
868
867
869
868
// Retrieve the source branch commit
870
869
BitbucketBranch branch ;
871
870
if (head .getOrigin () == SCMHeadOrigin .DEFAULT ) {
872
- branch = bitbucket .getBranch (h .getBranchName ());
871
+ branch = bitbucket .getBranch (prHead .getBranchName ());
873
872
} else {
874
873
// In case of a forked branch, retrieve the branch as that owner
875
- branch = buildBitbucketClient (h ).getBranch (h .getBranchName ());
874
+ branch = buildBitbucketClient (prHead ).getBranch (prHead .getBranchName ());
876
875
}
877
876
878
877
if (branch == null ) {
@@ -886,17 +885,17 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
886
885
} else {
887
886
BitbucketPullRequest pr ;
888
887
try {
889
- pr = bitbucket .getPullRequestById (Integer .parseInt (h .getId ()));
888
+ pr = bitbucket .getPullRequestById (Integer .parseInt (prHead .getId ()));
890
889
} catch (NumberFormatException nfe ) {
891
- LOGGER .log (Level .WARNING , "Cannot parse the PR id {0}" , h .getId ());
890
+ LOGGER .log (Level .WARNING , "Cannot parse the PR id {0}" , prHead .getId ());
892
891
return null ;
893
892
}
894
893
895
894
targetRevision = findPRDestinationCommit (pr , listener );
896
895
897
896
if (targetRevision == null ) {
898
897
listener .getLogger ().format ("No branch found in {0}/{1} with name [{2}]" ,
899
- repoOwner , repository , h .getTarget ().getName ());
898
+ repoOwner , repository , prHead .getTarget ().getName ());
900
899
return null ;
901
900
}
902
901
@@ -905,20 +904,19 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
905
904
906
905
if (sourceRevision == null ) {
907
906
listener .getLogger ().format ("No revision found in {0}/{1} for PR-{2} [{3}]" ,
908
- h .getRepoOwner (),
909
- h .getRepository (),
910
- h .getId (),
911
- h .getBranchName ());
907
+ prHead .getRepoOwner (),
908
+ prHead .getRepository (),
909
+ prHead .getId (),
910
+ prHead .getBranchName ());
912
911
return null ;
913
912
}
914
913
915
914
return new PullRequestSCMRevision (
916
- h ,
917
- new BitbucketGitSCMRevision (h .getTarget (), targetRevision ),
918
- new BitbucketGitSCMRevision (h , sourceRevision )
915
+ prHead ,
916
+ new BitbucketGitSCMRevision (prHead .getTarget (), targetRevision ),
917
+ new BitbucketGitSCMRevision (prHead , sourceRevision )
919
918
);
920
- } else if (head instanceof BitbucketTagSCMHead ) {
921
- BitbucketTagSCMHead tagHead = (BitbucketTagSCMHead ) head ;
919
+ } else if (head instanceof BitbucketTagSCMHead tagHead ) {
922
920
BitbucketBranch tag = bitbucket .getTag (tagHead .getName ());
923
921
if (tag == null ) {
924
922
listener .getLogger ().format ( "No tag found in {0}/{1} with name [{2}]" ,
@@ -949,8 +947,7 @@ protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOExc
949
947
}
950
948
} catch (IOException e ) {
951
949
// here we only want to display the job name to have it in the log
952
- if (e instanceof BitbucketRequestException ) {
953
- BitbucketRequestException bre = (BitbucketRequestException ) e ;
950
+ if (e instanceof BitbucketRequestException bre ) {
954
951
SCMSourceOwner scmSourceOwner = getOwner ();
955
952
if (bre .getHttpCode () == 401 && scmSourceOwner != null ) {
956
953
LOGGER .log (Level .WARNING , "BitbucketRequestException: Authz error. Status: 401 for Item '{0}' using credentialId '{1}'" ,
0 commit comments