Skip to content

Commit 53d05c9

Browse files
authored
[JENKINS-75015] Update the build status refname format used for Bitbucket Cloud (#947)
1 parent 5876f02 commit 53d05c9

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketApiUtils.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
55
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
66
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException;
7+
import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient;
78
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
89
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
910
import com.cloudbees.plugins.credentials.CredentialsProvider;
@@ -22,7 +23,11 @@
2223

2324
public class BitbucketApiUtils {
2425

25-
private static final Logger LOGGER = Logger.getLogger(BitbucketApiUtils.class.getName());
26+
private static final Logger logger = Logger.getLogger(BitbucketApiUtils.class.getName());
27+
28+
public static boolean isCloud(BitbucketApi client) {
29+
return client instanceof BitbucketCloudApiClient;
30+
}
2631

2732
public static ListBoxModel getFromBitbucket(SCMSourceOwner context,
2833
String serverUrl,
@@ -78,10 +83,10 @@ public static ListBoxModel getFromBitbucket(SCMSourceOwner context,
7883
: Messages.BitbucketSCMSource_UnauthorizedOwner(repoOwner)).withSelectionCleared();
7984
}
8085
}
81-
LOGGER.log(Level.SEVERE, e.getMessage(), e);
86+
logger.log(Level.SEVERE, e.getMessage(), e);
8287
throw FormFillFailure.error(e.getMessage());
8388
} catch (Throwable e) {
84-
LOGGER.log(Level.SEVERE, e.getMessage(), e);
89+
logger.log(Level.SEVERE, e.getMessage(), e);
8590
throw FormFillFailure.error(e.getMessage());
8691
}
8792
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotifications.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,16 @@ private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build
227227
listener.getLogger().println("[Bitbucket] Notifying commit build result");
228228
SCMHead head = rev.getHead();
229229
key = getBuildKey(build, head.getName(), shareBuildKeyBetweenBranchAndPR);
230-
if (rev instanceof BitbucketTagSCMRevision || head instanceof BitbucketTagSCMHead) {
231-
refName = "refs/tags/" + head.getName();
230+
bitbucket = source.buildBitbucketClient();
231+
if (BitbucketApiUtils.isCloud(bitbucket)) {
232+
refName = head.getName();
232233
} else {
233-
refName = "refs/heads/" + head.getName();
234+
if (rev instanceof BitbucketTagSCMRevision || head instanceof BitbucketTagSCMHead) {
235+
refName = "refs/tags/" + head.getName();
236+
} else {
237+
refName = "refs/heads/" + head.getName();
238+
}
234239
}
235-
bitbucket = source.buildBitbucketClient();
236240
}
237241
createStatus(build, listener, bitbucket, key, hash, refName);
238242
}

0 commit comments

Comments
 (0)