Skip to content

fix: bitbucket service pull request build status from different source #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,36 @@
.filters().stream()
.anyMatch(ExcludeOriginPRBranchesSCMHeadFilter.class::isInstance);

String key;
String refName;
BitbucketApi bitbucket;
final String key;
final String refName;
final BitbucketApi bitbucket;
if (rev instanceof PullRequestSCMRevision) {
listener.getLogger().println("[Bitbucket] Notifying pull request build result");
PullRequestSCMHead head = (PullRequestSCMHead) rev.getHead();
key = getBuildKey(build, head.getOriginName(), shareBuildKeyBetweenBranchAndPR);
/*
* Poor documentation for bitbucket cloud at:
* https://community.atlassian.com/t5/Bitbucket-questions/Re-Builds-not-appearing-in-pull-requests/qaq-p/1805991/comment-id/65864#M65864
* that means refName null or valued with only head.getBranchName()
*
* For Bitbucket Server, refName should be "refs/heads/" + the name
* of the source branch of the pull request, and the build status
* should be posted to the repository that contains that branch.
* If refName is null, then Bitbucket Server does not show the
* build status in the list of pull requests, but still shows it
* on the web page of the individual pull request.
*/
bitbucket = source.buildBitbucketClient(head);
if (BitbucketApiUtils.isCloud(bitbucket)) {
if (BitbucketApiUtils.isCloud(source.getServerUrl())) {
/*
* Poor documentation for bitbucket cloud at:
* https://community.atlassian.com/t5/Bitbucket-questions/Re-Builds-not-appearing-in-pull-requests/qaq-p/1805991/comment-id/65864#M65864
* that means refName null or valued with only head.getBranchName()
*/
refName = null;
bitbucket = source.buildBitbucketClient(head);
} else {
/*
* Head may point to a forked repository that the credentials do
* not have access to, resulting in a 401 error. So we need to
* push build status to the target repository
*/
bitbucket = source.buildBitbucketClient();

Check warning on line 242 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/notifier/BitbucketBuildStatusNotifications.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 228-242 are not covered by tests
/*
* For Bitbucket Server, refName should be "refs/heads/" + the
* name of the source branch of the pull request, and the build
* status should be posted to the repository that contains that
* branch. If refName is null, then Bitbucket Server does not
* show the build status in the list of pull requests, but still
* shows it on the web page of the individual pull request.
*/
refName = "refs/heads/" + head.getBranchName();
}
} else {
Expand Down