|
29 | 29 | import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient;
|
30 | 30 | import edu.umd.cs.findbugs.annotations.CheckForNull;
|
31 | 31 | import edu.umd.cs.findbugs.annotations.NonNull;
|
| 32 | +import edu.umd.cs.findbugs.annotations.Nullable; |
32 | 33 | import hudson.Extension;
|
33 | 34 | import hudson.FilePath;
|
34 | 35 | import hudson.model.Result;
|
|
44 | 45 | import java.net.URL;
|
45 | 46 | import jenkins.model.JenkinsLocationConfiguration;
|
46 | 47 | import jenkins.plugins.git.AbstractGitSCMSource;
|
| 48 | +import jenkins.scm.api.SCMHead; |
47 | 49 | import jenkins.scm.api.SCMHeadObserver;
|
48 | 50 | import jenkins.scm.api.SCMRevision;
|
49 | 51 | import jenkins.scm.api.SCMRevisionAction;
|
@@ -96,9 +98,12 @@ static String checkURL(@NonNull String url, BitbucketApi bitbucket) {
|
96 | 98 | }
|
97 | 99 | }
|
98 | 100 |
|
99 |
| - private static void createStatus(@NonNull Run<?, ?> build, @NonNull TaskListener listener, |
100 |
| - @NonNull BitbucketApi bitbucket, @NonNull String key, @NonNull String hash) |
101 |
| - throws IOException, InterruptedException { |
| 101 | + private static void createStatus(@NonNull Run<?, ?> build, |
| 102 | + @NonNull TaskListener listener, |
| 103 | + @NonNull BitbucketApi bitbucket, |
| 104 | + @NonNull String key, |
| 105 | + @NonNull String hash, |
| 106 | + @Nullable String refName) throws IOException, InterruptedException { |
102 | 107 |
|
103 | 108 | final SCMSource source = SCMSource.SourceByItem.findSource(build.getParent());
|
104 | 109 | if (!(source instanceof BitbucketSCMSource)) {
|
@@ -161,7 +166,7 @@ private static void createStatus(@NonNull Run<?, ?> build, @NonNull TaskListener
|
161 | 166 |
|
162 | 167 | if (state != null) {
|
163 | 168 | BitbucketChangesetCommentNotifier notifier = new BitbucketChangesetCommentNotifier(bitbucket);
|
164 |
| - notifier.buildStatus(new BitbucketBuildStatus(hash, statusDescription, state, url, key, name)); |
| 169 | + notifier.buildStatus(new BitbucketBuildStatus(hash, statusDescription, state, url, key, name, refName)); |
165 | 170 | if (result != null) {
|
166 | 171 | listener.getLogger().println("[Bitbucket] Build result notified");
|
167 | 172 | }
|
@@ -195,18 +200,32 @@ private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build
|
195 | 200 | .anyMatch(ExcludeOriginPRBranchesSCMHeadFilter.class::isInstance);
|
196 | 201 |
|
197 | 202 | String key;
|
| 203 | + String refName; |
198 | 204 | BitbucketApi bitbucket;
|
199 | 205 | if (rev instanceof PullRequestSCMRevision) {
|
200 | 206 | listener.getLogger().println("[Bitbucket] Notifying pull request build result");
|
201 | 207 | PullRequestSCMHead head = (PullRequestSCMHead) rev.getHead();
|
202 | 208 | key = getBuildKey(build, head.getOriginName(), shareBuildKeyBetweenBranchAndPR);
|
| 209 | + /* |
| 210 | + * in case of pull request it's not clear at all how to value refname. The |
| 211 | + * bitbucket documentation does not help and using values like |
| 212 | + * - refs/heads/PR-748; |
| 213 | + * - refs/pull-requests/748, |
| 214 | + * - refs/pull-requests/feature/test; |
| 215 | + * causes the build status disappear from the UI page. |
| 216 | + * The only working value is null. If commit is used for two different |
| 217 | + * pull requests than you will get double status in both PRs |
| 218 | + */ |
| 219 | + refName = null; // "refs/pull-requests/" + head.getBranchName(); |
203 | 220 | bitbucket = source.buildBitbucketClient(head);
|
204 | 221 | } else {
|
205 | 222 | listener.getLogger().println("[Bitbucket] Notifying commit build result");
|
206 |
| - key = getBuildKey(build, rev.getHead().getName(), shareBuildKeyBetweenBranchAndPR); |
| 223 | + SCMHead head = rev.getHead(); |
| 224 | + key = getBuildKey(build, head.getName(), shareBuildKeyBetweenBranchAndPR); |
| 225 | + refName = "refs/heads/" + head.getName(); |
207 | 226 | bitbucket = source.buildBitbucketClient();
|
208 | 227 | }
|
209 |
| - createStatus(build, listener, bitbucket, key, hash); |
| 228 | + createStatus(build, listener, bitbucket, key, hash, refName); |
210 | 229 | }
|
211 | 230 |
|
212 | 231 | @CheckForNull
|
|
0 commit comments