Skip to content

Commit

Permalink
[JENKINS-57775][JENKINS-62780] Address CheckForNull
Browse files Browse the repository at this point in the history
  • Loading branch information
Dohbedoh committed Jun 29, 2020
1 parent 7416966 commit c05439a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit c05439a

Please sign in to comment.