|
23 | 23 | */ |
24 | 24 | package com.cloudbees.jenkins.plugins.bitbucket.client.events; |
25 | 25 |
|
| 26 | +import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit; |
26 | 27 | import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequest; |
27 | 28 | import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketPullRequestEvent; |
28 | 29 | import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository; |
| 30 | +import com.cloudbees.jenkins.plugins.bitbucket.client.branch.BitbucketCloudBranch; |
29 | 31 | import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValue; |
| 32 | +import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueDestination; |
| 33 | +import com.cloudbees.jenkins.plugins.bitbucket.client.pullrequest.BitbucketPullRequestValueRepository; |
30 | 34 | import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepository; |
31 | 35 | import com.cloudbees.jenkins.plugins.bitbucket.client.repository.BitbucketCloudRepositoryOwner; |
32 | 36 | import com.fasterxml.jackson.annotation.JsonProperty; |
@@ -64,58 +68,61 @@ public void setRepository(BitbucketCloudRepository repository) { |
64 | 68 |
|
65 | 69 | private void reconstructMissingData() { |
66 | 70 | if (this.repository != null && this.pullRequest != null) { |
67 | | - if (this.pullRequest.getSource() != null |
68 | | - && this.pullRequest.getSource().getRepository() != null) { |
69 | | - if (this.pullRequest.getSource().getRepository().getScm() == null) { |
70 | | - this.pullRequest.getSource().getRepository().setScm(repository.getScm()); |
71 | | - } |
72 | | - if (this.pullRequest.getSource().getRepository().getOwner() == null) { |
73 | | - if (!this.pullRequest.getSource().getRepository().getOwnerName().equals(repository.getOwnerName())) { // i.e., a fork |
74 | | - BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner(); |
75 | | - owner.setUsername(this.pullRequest.getSource().getRepository().getOwnerName()); |
76 | | - owner.setDisplayName(this.pullRequest.getAuthorLogin()); |
77 | | - if (repository.isPrivate()) { |
78 | | - this.pullRequest.getSource().getRepository().setPrivate(repository.isPrivate()); |
| 71 | + BitbucketPullRequestValueRepository source = this.pullRequest.getSource(); |
| 72 | + if (source != null) { |
| 73 | + BitbucketCloudRepository sourceRepository = source.getRepository(); |
| 74 | + if (sourceRepository != null) { |
| 75 | + if (sourceRepository.getScm() == null) { |
| 76 | + sourceRepository.setScm(repository.getScm()); |
| 77 | + } |
| 78 | + if (sourceRepository.getOwner() == null) { |
| 79 | + if (!sourceRepository.getOwnerName().equals(repository.getOwnerName())) { // i.e., a fork |
| 80 | + BitbucketCloudRepositoryOwner owner = new BitbucketCloudRepositoryOwner(); |
| 81 | + owner.setUsername(sourceRepository.getOwnerName()); |
| 82 | + owner.setDisplayName(this.pullRequest.getAuthorLogin()); |
| 83 | + if (repository.isPrivate()) { |
| 84 | + sourceRepository.setPrivate(repository.isPrivate()); |
| 85 | + } |
| 86 | + sourceRepository.setOwner(owner); |
| 87 | + } else { // origin branch |
| 88 | + sourceRepository.setOwner(repository.getOwner()); |
| 89 | + sourceRepository.setPrivate(repository.isPrivate()); |
79 | 90 | } |
80 | | - this.pullRequest.getSource().getRepository().setOwner(owner); |
81 | | - } else { // origin branch |
82 | | - this.pullRequest.getSource().getRepository().setOwner(repository.getOwner()); |
83 | | - this.pullRequest.getSource().getRepository().setPrivate(repository.isPrivate()); |
84 | 91 | } |
85 | 92 | } |
86 | 93 | } |
87 | | - if (this.pullRequest.getSource() != null |
88 | | - && this.pullRequest.getSource().getCommit() != null |
89 | | - && this.pullRequest.getSource().getBranch() != null |
90 | | - && this.pullRequest.getSource().getBranch().getRawNode() == null) { |
91 | | - this.pullRequest.getSource().getBranch() |
92 | | - .setRawNode(this.pullRequest.getSource().getCommit().getHash()); |
93 | | - } |
94 | | - if (this.pullRequest.getSource() != null |
95 | | - && this.pullRequest.getSource().getCommit() != null |
96 | | - && this.pullRequest.getSource().getBranch() != null |
97 | | - && this.pullRequest.getSource().getBranch().getDateMillis() == 0) { |
98 | | - this.pullRequest.getSource().getBranch() |
99 | | - .setDateMillis(toDate(this.pullRequest.getSource().getCommit().getDate())); |
| 94 | + if (source != null) { |
| 95 | + BitbucketCloudBranch sourceBranch = source.getBranch(); |
| 96 | + BitbucketCommit sourceCommit = source.getCommit(); |
| 97 | + if (sourceCommit != null |
| 98 | + && sourceBranch != null) { |
| 99 | + if (sourceBranch.getRawNode() == null) { |
| 100 | + sourceBranch.setRawNode(source.getCommit().getHash()); |
| 101 | + } |
| 102 | + if (sourceBranch.getDateMillis() == 0) { |
| 103 | + sourceBranch.setDateMillis(toDate(sourceCommit.getDate())); |
| 104 | + } |
| 105 | + } |
100 | 106 | } |
101 | | - if (this.pullRequest.getDestination() != null |
102 | | - && this.pullRequest.getDestination().getRepository() != null) { |
103 | | - if (this.pullRequest.getDestination().getRepository().getScm() == null) { |
104 | | - this.pullRequest.getDestination().getRepository().setScm(repository.getScm()); |
| 107 | + BitbucketPullRequestValueDestination destination = this.pullRequest.getDestination(); |
| 108 | + if (destination != null |
| 109 | + && destination.getRepository() != null) { |
| 110 | + if (destination.getRepository().getScm() == null) { |
| 111 | + destination.getRepository().setScm(repository.getScm()); |
105 | 112 | } |
106 | | - if (this.pullRequest.getDestination().getRepository().getOwner() == null |
107 | | - && this.pullRequest.getDestination().getRepository().getOwnerName() |
108 | | - .equals(repository.getOwnerName())) { |
109 | | - this.pullRequest.getDestination().getRepository().setOwner(repository.getOwner()); |
110 | | - this.pullRequest.getDestination().getRepository().setPrivate(repository.isPrivate()); |
| 113 | + if (destination.getRepository().getOwner() == null |
| 114 | + && destination.getRepository().getOwnerName() |
| 115 | + .equals(repository.getOwnerName())) { |
| 116 | + destination.getRepository().setOwner(repository.getOwner()); |
| 117 | + destination.getRepository().setPrivate(repository.isPrivate()); |
111 | 118 | } |
112 | 119 | } |
113 | | - if (this.pullRequest.getDestination() != null |
114 | | - && this.pullRequest.getDestination().getCommit() != null |
115 | | - && this.pullRequest.getDestination().getBranch() != null |
116 | | - && this.pullRequest.getDestination().getBranch().getRawNode() == null) { |
117 | | - this.pullRequest.getDestination().getBranch() |
118 | | - .setRawNode(this.pullRequest.getDestination().getCommit().getHash()); |
| 120 | + if (destination != null |
| 121 | + && destination.getCommit() != null |
| 122 | + && destination.getBranch() != null |
| 123 | + && destination.getBranch().getRawNode() == null) { |
| 124 | + destination.getBranch() |
| 125 | + .setRawNode(destination.getCommit().getHash()); |
119 | 126 | } |
120 | 127 | } |
121 | 128 | } |
|
0 commit comments