@@ -532,6 +532,25 @@ public BitbucketApi buildBitbucketClient(String repoOwner, String repository) {
532
532
return BitbucketApiFactory .newInstance (getServerUrl (), authenticator (), repoOwner , null , repository );
533
533
}
534
534
535
+ @ Override
536
+ public void afterSave () {
537
+ try {
538
+ gatherPrimaryCloneLinks (buildBitbucketClient ());
539
+ } catch (InterruptedException | IOException e ) {
540
+ LOGGER .log (Level .SEVERE ,
541
+ "Could not determine clone links of " + getRepoOwner () + "/" + getRepository () +
542
+ " on " + getServerUrl () + " for " + getOwner () + " falling back to generated links" , e );
543
+ }
544
+ }
545
+
546
+ private void gatherPrimaryCloneLinks (@ NonNull BitbucketApi apiClient ) throws IOException , InterruptedException {
547
+ BitbucketRepository r = apiClient .getRepository ();
548
+ Map <String , List <BitbucketHref >> links = r .getLinks ();
549
+ if (links != null && links .containsKey ("clone" )) {
550
+ setPrimaryCloneLinks (links .get ("clone" ));
551
+ }
552
+ }
553
+
535
554
@ Override
536
555
protected void retrieve (@ CheckForNull SCMSourceCriteria criteria , @ NonNull SCMHeadObserver observer ,
537
556
@ CheckForNull SCMHeadEvent <?> event , @ NonNull TaskListener listener )
@@ -546,6 +565,8 @@ protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHe
546
565
listener .getLogger ().format ("Connecting to %s using %s%n" , getServerUrl (),
547
566
CredentialsNameProvider .name (scanCredentials ));
548
567
}
568
+ BitbucketApi apiClient = buildBitbucketClient ();
569
+ gatherPrimaryCloneLinks (apiClient );
549
570
550
571
// populate the request with its data sources
551
572
if (request .isFetchPRs ()) {
@@ -558,7 +579,7 @@ protected Iterable<BitbucketPullRequest> create() {
558
579
return getBitbucketPullRequestsFromEvent (hasPrEvent , listener );
559
580
}
560
581
561
- return (Iterable <BitbucketPullRequest >) buildBitbucketClient () .getPullRequests ();
582
+ return (Iterable <BitbucketPullRequest >) apiClient .getPullRequests ();
562
583
} catch (IOException | InterruptedException e ) {
563
584
throw new BitbucketSCMSource .WrappedException (e );
564
585
}
@@ -570,7 +591,7 @@ protected Iterable<BitbucketPullRequest> create() {
570
591
@ Override
571
592
protected Iterable <BitbucketBranch > create () {
572
593
try {
573
- return (Iterable <BitbucketBranch >) buildBitbucketClient () .getBranches ();
594
+ return (Iterable <BitbucketBranch >) apiClient .getBranches ();
574
595
} catch (IOException | InterruptedException e ) {
575
596
throw new BitbucketSCMSource .WrappedException (e );
576
597
}
@@ -582,7 +603,7 @@ protected Iterable<BitbucketBranch> create() {
582
603
@ Override
583
604
protected Iterable <BitbucketBranch > create () {
584
605
try {
585
- return (Iterable <BitbucketBranch >) buildBitbucketClient () .getTags ();
606
+ return (Iterable <BitbucketBranch >) apiClient .getTags ();
586
607
} catch (IOException | InterruptedException e ) {
587
608
throw new BitbucketSCMSource .WrappedException (e );
588
609
}
@@ -1032,11 +1053,8 @@ protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event,
1032
1053
// TODO when we have support for trusted events, use the details from event if event was from trusted source
1033
1054
List <Action > result = new ArrayList <>();
1034
1055
final BitbucketApi bitbucket = buildBitbucketClient ();
1056
+ gatherPrimaryCloneLinks (bitbucket );
1035
1057
BitbucketRepository r = bitbucket .getRepository ();
1036
- Map <String , List <BitbucketHref >> links = r .getLinks ();
1037
- if (links != null && links .containsKey ("clone" )) {
1038
- setPrimaryCloneLinks (links .get ("clone" ));
1039
- }
1040
1058
result .add (new BitbucketRepoMetadataAction (r ));
1041
1059
String defaultBranch = bitbucket .getDefaultBranch ();
1042
1060
if (StringUtils .isNotBlank (defaultBranch )) {
0 commit comments