102
102
import org .kohsuke .stapler .DataBoundConstructor ;
103
103
import org .kohsuke .stapler .DataBoundSetter ;
104
104
import org .kohsuke .stapler .QueryParameter ;
105
+ import org .kohsuke .stapler .interceptor .RequirePOST ;
105
106
106
107
import static com .cloudbees .jenkins .plugins .bitbucket .impl .util .BitbucketApiUtils .getFromBitbucket ;
107
108
@@ -288,9 +289,9 @@ public String getServerUrl() {
288
289
}
289
290
290
291
@ DataBoundSetter
291
- public void setServerUrl (String serverUrl ) {
292
+ public void setServerUrl (@ CheckForNull String serverUrl ) {
292
293
serverUrl = BitbucketEndpointConfiguration .normalizeServerUrl (serverUrl );
293
- if (!StringUtils .equals (this .serverUrl , serverUrl )) {
294
+ if (serverUrl != null && !StringUtils .equals (this .serverUrl , serverUrl )) {
294
295
this .serverUrl = serverUrl ;
295
296
resetId ();
296
297
}
@@ -384,14 +385,14 @@ public String getPattern() {
384
385
@ DataBoundSetter
385
386
public void setBitbucketServerUrl (String url ) {
386
387
url = BitbucketEndpointConfiguration .normalizeServerUrl (url );
387
- AbstractBitbucketEndpoint endpoint = BitbucketEndpointConfiguration .get ().findEndpoint (url );
388
- if (endpoint != null ) {
389
- // we have a match
390
- setServerUrl (url );
391
- return ;
388
+ url = StringUtils .defaultIfBlank (url , BitbucketCloudEndpoint .SERVER_URL ); // when BitbucketServerUrl was null means cloud was configured
389
+ AbstractBitbucketEndpoint endpoint = BitbucketEndpointConfiguration .get ()
390
+ .findEndpoint (url )
391
+ .orElse (null );
392
+ if (endpoint == null ) {
393
+ LOGGER .log (Level .WARNING , "Call to legacy setBitbucketServerUrl({0}) method is configuring a url missing "
394
+ + "from the global configuration." , url );
392
395
}
393
- LOGGER .log (Level .WARNING , "Call to legacy setBitbucketServerUrl({0}) method is configuring a url missing "
394
- + "from the global configuration." , url );
395
396
setServerUrl (url );
396
397
}
397
398
@@ -400,7 +401,10 @@ public void setBitbucketServerUrl(String url) {
400
401
@ RestrictedSince ("2.2.0" )
401
402
@ CheckForNull
402
403
public String getBitbucketServerUrl () {
403
- if (BitbucketEndpointConfiguration .get ().findEndpoint (serverUrl ) instanceof BitbucketCloudEndpoint ) {
404
+ if (BitbucketEndpointConfiguration .get ()
405
+ .findEndpoint (serverUrl )
406
+ .filter (BitbucketCloudEndpoint .class ::isInstance )
407
+ .isPresent ()) {
404
408
return null ;
405
409
}
406
410
return serverUrl ;
@@ -629,7 +633,7 @@ public String getIconClassName() {
629
633
@ Override
630
634
public SCMNavigator newInstance (String name ) {
631
635
BitbucketSCMNavigator instance = new BitbucketSCMNavigator (StringUtils .defaultString (name ));
632
- instance .setTraits (( List ) getTraitsDefaults ());
636
+ instance .setTraits (getTraitsDefaults ());
633
637
return instance ;
634
638
}
635
639
@@ -647,16 +651,21 @@ public ListBoxModel doFillServerUrlItems(@AncestorInPath SCMSourceOwner context)
647
651
return BitbucketEndpointConfiguration .get ().getEndpointItems ();
648
652
}
649
653
654
+ @ RequirePOST
650
655
@ SuppressWarnings ("unused" ) // used By stapler
651
- public FormValidation doCheckCredentialsId (@ AncestorInPath SCMSourceOwner context , @ QueryParameter String serverUrl , @ QueryParameter String value ) {
652
- return BitbucketCredentials .checkCredentialsId (context , value , serverUrl );
656
+ public static FormValidation doCheckCredentialsId (@ AncestorInPath SCMSourceOwner context ,
657
+ @ QueryParameter (fixEmpty = true , value = "serverUrl" ) String serverURL ,
658
+ @ QueryParameter String value ) {
659
+ return BitbucketCredentials .checkCredentialsId (context , value , serverURL );
653
660
}
654
661
662
+ @ RequirePOST
655
663
@ SuppressWarnings ("unused" ) // used By stapler
656
- public static FormValidation doCheckMirrorId (@ QueryParameter String value , @ QueryParameter String serverUrl ) {
664
+ public static FormValidation doCheckMirrorId (@ QueryParameter String value ,
665
+ @ QueryParameter (fixEmpty = true , value = "serverUrl" ) String serverURL ) {
657
666
if (!value .isEmpty ()) {
658
667
BitbucketServerWebhookImplementation webhookImplementation =
659
- BitbucketServerEndpoint .findWebhookImplementation (serverUrl );
668
+ BitbucketServerEndpoint .findWebhookImplementation (serverURL );
660
669
if (webhookImplementation == BitbucketServerWebhookImplementation .PLUGIN ) {
661
670
return FormValidation .error ("Mirror can only be used with native webhooks" );
662
671
}
@@ -666,13 +675,13 @@ public static FormValidation doCheckMirrorId(@QueryParameter String value, @Quer
666
675
667
676
@ SuppressWarnings ("unused" ) // used By stapler
668
677
public ListBoxModel doFillCredentialsIdItems (@ AncestorInPath SCMSourceOwner context ,
669
- @ QueryParameter String serverUrl ) {
670
- return BitbucketCredentials .fillCredentialsIdItems (context , serverUrl );
678
+ @ QueryParameter ( fixEmpty = true , value = " serverUrl" ) String serverURL ) {
679
+ return BitbucketCredentials .fillCredentialsIdItems (context , serverURL );
671
680
}
672
681
673
682
@ SuppressWarnings ("unused" ) // used By stapler
674
683
public ListBoxModel doFillMirrorIdItems (@ AncestorInPath SCMSourceOwner context ,
675
- @ QueryParameter String serverUrl ,
684
+ @ QueryParameter ( fixEmpty = true , value = "serverUrl" ) String serverUrl ,
676
685
@ QueryParameter String credentialsId ,
677
686
@ QueryParameter String repoOwner )
678
687
throws FormFillFailure {
0 commit comments