From cd1b0fef6d1fbc31e501ab843d4f874c1e597a07 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Wed, 24 Jun 2020 14:50:13 +1000 Subject: [PATCH 1/6] [JENKINS-57775][JENKINS-62780] Handle PRs from/to non existing source/dest --- .../client/BitbucketCloudApiClient.java | 4 +- .../BitbucketPullRequestValueDestination.java | 9 +- .../BitbucketPullRequestValueRepository.java | 18 +- .../client/BitbucketServerAPIClient.java | 4 +- ...-repos-pullrequests_page_1_pagelen_50.json | 243 +++++++++++++++++- 5 files changed, 266 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java index a61e1ff77..2755e8e87 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java @@ -307,7 +307,9 @@ public List getPullRequests() throws InterruptedExcep } while (page.getNext() != null); // PRs with missing destination branch are invalid and should be ignored. - pullRequests.removeIf(pr -> pr.getDestination().getBranch() == null); + pullRequests.removeIf(pr -> pr.getSource().getRepository() == null + || pr.getSource().getCommit() == null + || pr.getDestination().getCommit() == null); for (BitbucketPullRequestValue pullRequest : pullRequests) { setupClosureForPRBranch(pullRequest); diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java index c875cbf0b..be30ad3ac 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java @@ -33,6 +33,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.util.StdDateFormat; +import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import java.util.Date; @@ -44,14 +45,14 @@ public class BitbucketPullRequestValueDestination implements BitbucketPullReques @JsonCreator public BitbucketPullRequestValueDestination(@NonNull @JsonProperty("repository") BitbucketCloudRepository repository, @JsonProperty("branch") BitbucketCloudBranch branch, - @NonNull @JsonProperty("commit") BitbucketCloudCommit commit) { + @JsonProperty("commit") BitbucketCloudCommit commit) { this.repository = repository; this.branch = branch; this.commit = commit; // It is possible for a PR's original destination to no longer exist. - if(this.branch != null) { - // redound available the informations into impl objects + if(this.branch != null && this.commit != null) { + // redound available the information into impl objects this.branch.setRawNode(commit.getHash()); } } @@ -66,6 +67,7 @@ public void setRepository(BitbucketCloudRepository repository) { } @Override + @CheckForNull public BitbucketCloudBranch getBranch() { return branch; } @@ -75,6 +77,7 @@ public void setBranch(BitbucketCloudBranch branch) { } @Override + @CheckForNull public BitbucketCommit getCommit() { if (branch != null && commit != null) { // initialise commit value using branch closure if not already valued diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java index 439d9dc3b..c7c406fc7 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java @@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.util.StdDateFormat; -import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.CheckForNull; import java.util.Date; public class BitbucketPullRequestValueRepository implements BitbucketPullRequestSource { @@ -40,18 +40,22 @@ public class BitbucketPullRequestValueRepository implements BitbucketPullRequest private BitbucketCloudCommit commit; @JsonCreator - public BitbucketPullRequestValueRepository(@NonNull @JsonProperty("repository") BitbucketCloudRepository repository, - @NonNull @JsonProperty("branch") BitbucketCloudBranch branch, - @NonNull @JsonProperty("commit") BitbucketCloudCommit commit) { + public BitbucketPullRequestValueRepository(@JsonProperty("repository") BitbucketCloudRepository repository, + @JsonProperty("branch") BitbucketCloudBranch branch, + @JsonProperty("commit") BitbucketCloudCommit commit) { this.repository = repository; this.branch = branch; this.commit = commit; - // redound available the informations into impl objects - this.branch.setRawNode(commit.getHash()); + // It is possible for a PR's original source to no longer exist. + if(branch != null && commit != null) { + // redound available the information into impl objects + this.branch.setRawNode(commit.getHash()); + } } @Override + @CheckForNull public BitbucketCloudRepository getRepository() { return repository; } @@ -61,6 +65,7 @@ public void setRepository(BitbucketCloudRepository repository) { } @Override + @CheckForNull public BitbucketCloudBranch getBranch() { return branch; } @@ -70,6 +75,7 @@ public void setBranch(BitbucketCloudBranch branch) { } @Override + @CheckForNull public BitbucketCommit getCommit() { if (branch != null && commit != null) { // initialise commit value using branch closure if not already valued diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java index 98212de8e..4220957df 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java @@ -329,7 +329,9 @@ private List getPullRequests(UriTemplate template) List pullRequests = getResources(template, BitbucketServerPullRequests.class); // PRs with missing destination branch are invalid and should be ignored. - pullRequests.removeIf(pr -> pr.getDestination().getBranch() == null); + pullRequests.removeIf(pr -> pr.getSource().getRepository() == null + || pr.getSource().getCommit() == null + || pr.getDestination().getCommit() == null); // set commit closure to make commit informations available when need, in a similar way to when request branches for (BitbucketServerPullRequest pullRequest : pullRequests) { diff --git a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/payload/2.0-repositories-amuniz-test-repos-pullrequests_page_1_pagelen_50.json b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/payload/2.0-repositories-amuniz-test-repos-pullrequests_page_1_pagelen_50.json index 7c59c9c73..60ad0b42b 100644 --- a/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/payload/2.0-repositories-amuniz-test-repos-pullrequests_page_1_pagelen_50.json +++ b/src/test/resources/com/cloudbees/jenkins/plugins/bitbucket/client/payload/2.0-repositories-amuniz-test-repos-pullrequests_page_1_pagelen_50.json @@ -416,7 +416,248 @@ }, "merge_commit": null, "closed_by": null - }], + }, { + "description": "PR from deleted forked repo", + "links": { + "decline": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/decline" + }, + "commits": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/commits" + }, + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2" + }, + "comments": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/comments" + }, + "merge": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/merge" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos/pull-requests/3" + }, + "activity": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/activity" + }, + "diff": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/diff" + }, + "approve": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/approve" + }, + "statuses": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/2/statuses" + } + }, + "title": "JENKINS-62780", + "close_source_branch": true, + "type": "pullrequest", + "id": 4, + "destination": { + "commit": { + "hash": "bf4f4ce8a3a8", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/commit/bf4f4ce8a3a8" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos/commits/bf4f4ce8a3a8" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B3deb8c29-778a-450c-8f69-3e50a18079df%7D?ts=default" + } + }, + "type": "repository", + "name": "test-repos", + "full_name": "amuniz/test-repos", + "uuid": "{3deb8c29-778a-450c-8f69-3e50a18079df}" + }, + "branch": { + "name": "master" + } + }, + "created_on": "2018-11-08T13:45:13.837779+00:00", + "summary": { + "raw": "test from forked repo", + "markup": "markdown", + "html": "

test from forked repo

", + "type": "rendered" + }, + "source": { + "branch": { + "name": "feature/BB-2" + }, + "commit": null, + "repository": null + }, + "comment_count": 0, + "state": "OPEN", + "task_count": 0, + "reason": "", + "updated_on": "2018-11-08T13:45:13.958677+00:00", + "author": { + "username": "amuniz", + "display_name": "Nikolas Falco", + "account_id": "557058:ca1cd232-2017-4216-94be-99637899e18d", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/amuniz" + }, + "html": { + "href": "https://bitbucket.org/amuniz/" + }, + "avatar": { + "href": "https://bitbucket.org/account/amuniz/avatar/" + } + }, + "nickname": "amuniz", + "type": "user", + "uuid": "{644c7fc2-b15a-4445-9f89-35390694fac9}" + }, + "merge_commit": null, + "closed_by": null + }, + { + "description": "PR from deleted source branch", + "links": { + "decline": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/decline" + }, + "commits": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/commits" + }, + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3" + }, + "comments": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/comments" + }, + "merge": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/merge" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos/pull-requests/3" + }, + "activity": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/activity" + }, + "diff": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/diff" + }, + "approve": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/approve" + }, + "statuses": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/pullrequests/3/statuses" + } + }, + "title": "JENKINS-57775", + "close_source_branch": true, + "type": "pullrequest", + "id": 5, + "destination": { + "commit": null, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B3deb8c29-778a-450c-8f69-3e50a18079df%7D?ts=default" + } + }, + "type": "repository", + "name": "test-repos", + "full_name": "amuniz/test-repos", + "uuid": "{3deb8c29-778a-450c-8f69-3e50a18079df}" + }, + "branch": { + "name": "master" + } + }, + "created_on": "2018-09-21T14:57:59.455870+00:00", + "summary": { + "raw": "PR with destination branch deleted", + "markup": "markdown", + "html": "

PR with destination branch deleted

", + "type": "rendered" + }, + "source": { + "commit": { + "hash": "bf0e8b7962c4", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos/commit/bf0e8b7962c4" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos/commits/bf0e8b7962c4" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/amuniz/test-repos" + }, + "html": { + "href": "https://bitbucket.org/amuniz/test-repos" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B3deb8c29-778a-450c-8f69-3e50a18079df%7D?ts=default" + } + }, + "type": "repository", + "name": "test-repos", + "full_name": "amuniz/test-repos", + "uuid": "{3deb8c29-778a-450c-8f69-3e50a18079df}" + }, + "branch": { + "name": "bugfix/123" + } + }, + "comment_count": 0, + "state": "OPEN", + "task_count": 0, + "reason": "", + "updated_on": "2018-09-21T14:57:59.488719+00:00", + "author": { + "username": "amuniz", + "display_name": "Nikolas Falco", + "account_id": "557058:ca1cd232-2017-4216-94be-99637899e18d", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/amuniz" + }, + "html": { + "href": "https://bitbucket.org/amuniz/" + }, + "avatar": { + "href": "https://bitbucket.org/account/amuniz/avatar/" + } + }, + "nickname": "amuniz", + "type": "user", + "uuid": "{644c7fc2-b15a-4445-9f89-35390694fac9}" + }, + "merge_commit": null, + "closed_by": null + }], "page": 1, "size": 2 } From e5ae726426bcfafce646b62c179943a6fc162ce9 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Wed, 24 Jun 2020 16:07:24 +1000 Subject: [PATCH 2/6] [JENKINS-57775][JENKINS-62780] Restore the condition on null branch --- .../plugins/bitbucket/client/BitbucketCloudApiClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java index 2755e8e87..1f7b651de 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java @@ -309,6 +309,7 @@ public List getPullRequests() throws InterruptedExcep // PRs with missing destination branch are invalid and should be ignored. pullRequests.removeIf(pr -> pr.getSource().getRepository() == null || pr.getSource().getCommit() == null + || pr.getDestination().getBranch() == null || pr.getDestination().getCommit() == null); for (BitbucketPullRequestValue pullRequest : pullRequests) { From 7416966120952e6f6a3bd98ab6d379fca62ba12f Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Wed, 24 Jun 2020 16:07:54 +1000 Subject: [PATCH 3/6] [JENKINS-57775][JENKINS-62780] Do not rely on getCommit for Bitbucket Server --- .../bitbucket/server/client/BitbucketServerAPIClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java index 4220957df..cc6e501ed 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/BitbucketServerAPIClient.java @@ -330,8 +330,8 @@ private List getPullRequests(UriTemplate template) // PRs with missing destination branch are invalid and should be ignored. pullRequests.removeIf(pr -> pr.getSource().getRepository() == null - || pr.getSource().getCommit() == null - || pr.getDestination().getCommit() == null); + || pr.getSource().getBranch() == null + || pr.getDestination().getBranch() == null); // set commit closure to make commit informations available when need, in a similar way to when request branches for (BitbucketServerPullRequest pullRequest : pullRequests) { From c05439a8cd41ce1f8c841724468903b56d4e8805 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Mon, 29 Jun 2020 21:54:40 +1000 Subject: [PATCH 4/6] [JENKINS-57775][JENKINS-62780] Address CheckForNull --- .../client/BitbucketCloudApiClient.java | 8 +- .../BitbucketCloudPullRequestEvent.java | 93 ++++++++++--------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java index 1f7b651de..2aee618ed 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/BitbucketCloudApiClient.java @@ -339,9 +339,13 @@ public BitbucketCommit call() throws Exception { private void setupClosureForPRBranch(BitbucketPullRequestValue pullRequest) { BitbucketCloudBranch branch = pullRequest.getSource().getBranch(); - branch.setCommitClosure(new CommitClosure(branch.getRawNode())); + if (branch != null) { + branch.setCommitClosure(new CommitClosure(branch.getRawNode())); + } branch = pullRequest.getDestination().getBranch(); - branch.setCommitClosure(new CommitClosure(branch.getRawNode())); + if (branch != null) { + branch.setCommitClosure(new CommitClosure(branch.getRawNode())); + } } @Deprecated diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java index 42933f537..029915bef 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/events/BitbucketCloudPullRequestEvent.java @@ -23,10 +23,14 @@ */ package com.cloudbees.jenkins.plugins.bitbucket.client.events; +import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit; import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest; import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequestEvent; import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository; +import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudBranch; import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValue; +import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination; +import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueRepository; import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepository; import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepositoryOwner; import com.fasterxml.jackson.annotation.JsonProperty; @@ -64,58 +68,61 @@ public void setRepository(BitbucketCloudRepository repository) { private void reconstructMissingData() { if (this.repository != null && this.pullRequest != null) { - if (this.pullRequest.getSource() != null - && this.pullRequest.getSource().getRepository() != null) { - if (this.pullRequest.getSource().getRepository().getScm() == null) { - this.pullRequest.getSource().getRepository().setScm(repository.getScm()); - } - if (this.pullRequest.getSource().getRepository().getOwner() == null) { - if (this.pullRequest.getSource().getRepository().getOwnerName().equals(this.pullRequest.getAuthorLogin())) { - BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner(); - owner.setUsername(this.pullRequest.getAuthorLogin()); - owner.setDisplayName(this.pullRequest.getAuthorDisplayName()); - if (repository.isPrivate()) { - this.pullRequest.getSource().getRepository().setPrivate(repository.isPrivate()); + BitbucketPullRequestValueRepository source = this.pullRequest.getSource(); + if (source != null) { + BitbucketCloudRepository sourceRepository = source.getRepository(); + if(sourceRepository != null) { + if (sourceRepository.getScm() == null) { + sourceRepository.setScm(repository.getScm()); + } + if (sourceRepository.getOwner() == null) { + if (sourceRepository.getOwnerName().equals(this.pullRequest.getAuthorLogin())) { + BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner(); + owner.setUsername(this.pullRequest.getAuthorLogin()); + owner.setDisplayName(this.pullRequest.getAuthorDisplayName()); + if (this.repository.isPrivate()) { + sourceRepository.setPrivate(this.repository.isPrivate()); + } + sourceRepository.setOwner(owner); + } else if (sourceRepository.getOwnerName().equals(this.repository.getOwnerName())) { + sourceRepository.setOwner(this.repository.getOwner()); + sourceRepository.setPrivate(this.repository.isPrivate()); } - this.pullRequest.getSource().getRepository().setOwner(owner); - } else if (this.pullRequest.getSource().getRepository().getOwnerName().equals(repository.getOwnerName())) { - this.pullRequest.getSource().getRepository().setOwner(repository.getOwner()); - this.pullRequest.getSource().getRepository().setPrivate(repository.isPrivate()); } } } - if (this.pullRequest.getSource() != null - && this.pullRequest.getSource().getCommit() != null - && this.pullRequest.getSource().getBranch() != null - && this.pullRequest.getSource().getBranch().getRawNode() == null) { - this.pullRequest.getSource().getBranch() - .setRawNode(this.pullRequest.getSource().getCommit().getHash()); - } - if (this.pullRequest.getSource() != null - && this.pullRequest.getSource().getCommit() != null - && this.pullRequest.getSource().getBranch() != null - && this.pullRequest.getSource().getBranch().getDateMillis() == 0) { - this.pullRequest.getSource().getBranch() - .setDateMillis(toDate(this.pullRequest.getSource().getCommit().getDate())); + if (source != null) { + BitbucketCloudBranch sourceBranch = source.getBranch(); + BitbucketCommit sourceCommit = source.getCommit(); + if (sourceCommit != null + && sourceBranch != null) { + if (sourceBranch.getRawNode() == null) { + sourceBranch.setRawNode(source.getCommit().getHash()); + } + if (sourceBranch.getDateMillis() == 0) { + sourceBranch.setDateMillis(toDate(sourceCommit.getDate())); + } + } } - if (this.pullRequest.getDestination() != null - && this.pullRequest.getDestination().getRepository() != null) { - if (this.pullRequest.getDestination().getRepository().getScm() == null) { - this.pullRequest.getDestination().getRepository().setScm(repository.getScm()); + BitbucketPullRequestValueDestination destination = this.pullRequest.getDestination(); + if (destination != null + && destination.getRepository() != null) { + if (destination.getRepository().getScm() == null) { + destination.getRepository().setScm(repository.getScm()); } - if (this.pullRequest.getDestination().getRepository().getOwner() == null - && this.pullRequest.getDestination().getRepository().getOwnerName() + if (destination.getRepository().getOwner() == null + && destination.getRepository().getOwnerName() .equals(repository.getOwnerName())) { - this.pullRequest.getDestination().getRepository().setOwner(repository.getOwner()); - this.pullRequest.getDestination().getRepository().setPrivate(repository.isPrivate()); + destination.getRepository().setOwner(repository.getOwner()); + destination.getRepository().setPrivate(repository.isPrivate()); } } - if (this.pullRequest.getDestination() != null - && this.pullRequest.getDestination().getCommit() != null - && this.pullRequest.getDestination().getBranch() != null - && this.pullRequest.getDestination().getBranch().getRawNode() == null) { - this.pullRequest.getDestination().getBranch() - .setRawNode(this.pullRequest.getDestination().getCommit().getHash()); + if (destination != null + && destination.getCommit() != null + && destination.getBranch() != null + && destination.getBranch().getRawNode() == null) { + destination.getBranch() + .setRawNode(destination.getCommit().getHash()); } } } From 3c73dcd83e547e0be6f59961f64d5ea160ebdd69 Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Mon, 29 Jun 2020 22:00:31 +1000 Subject: [PATCH 5/6] [JENKINS-57775][JENKINS-62780] Add CheckForNull for destination commit Co-authored-by: Liam Newman --- .../pullrequest/BitbucketPullRequestValueDestination.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java index be30ad3ac..7d6b5ffa7 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java @@ -45,7 +45,7 @@ public class BitbucketPullRequestValueDestination implements BitbucketPullReques @JsonCreator public BitbucketPullRequestValueDestination(@NonNull @JsonProperty("repository") BitbucketCloudRepository repository, @JsonProperty("branch") BitbucketCloudBranch branch, - @JsonProperty("commit") BitbucketCloudCommit commit) { + @CheckForNull @JsonProperty("commit") BitbucketCloudCommit commit) { this.repository = repository; this.branch = branch; this.commit = commit; From 7cf4f694fb95917531e6633868fc219a9b69235d Mon Sep 17 00:00:00 2001 From: Allan Burdajewicz Date: Mon, 29 Jun 2020 22:10:01 +1000 Subject: [PATCH 6/6] [JENKINS-57775][JENKINS-62780] Rephrase comment --- .../pullrequest/BitbucketPullRequestValueDestination.java | 2 +- .../client/pullrequest/BitbucketPullRequestValueRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java index 7d6b5ffa7..1939ed435 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueDestination.java @@ -52,7 +52,7 @@ public BitbucketPullRequestValueDestination(@NonNull @JsonProperty("repository") // It is possible for a PR's original destination to no longer exist. if(this.branch != null && this.commit != null) { - // redound available the information into impl objects + // Make the commit information available into impl objects this.branch.setRawNode(commit.getHash()); } } diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java index c7c406fc7..e605a9871 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/pullrequest/BitbucketPullRequestValueRepository.java @@ -49,7 +49,7 @@ public BitbucketPullRequestValueRepository(@JsonProperty("repository") Bitbucket // It is possible for a PR's original source to no longer exist. if(branch != null && commit != null) { - // redound available the information into impl objects + // Make the commit information available into impl objects this.branch.setRawNode(commit.getHash()); } }