Skip to content
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

[JENKINS-57775][JENKINS-62780] Handle PRs from/to non existing src/dest #322

Merged
merged 7 commits into from
Jul 17, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ public List<BitbucketPullRequestValue> 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().getBranch() == null
|| pr.getDestination().getCommit() == null);

for (BitbucketPullRequestValue pullRequest : pullRequests) {
setupClosureForPRBranch(pullRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Dohbedoh marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"redound"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's from #152. I am gonna rephrase this to Make the commit information available into impl objects. cc @nfalco79

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should was " re bind"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitwiseman I want heavy remember to you branch-api-plugin#160

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nfalco79 I hear you.

this.branch.setRawNode(commit.getHash());
}
}
Expand All @@ -66,6 +67,7 @@ public void setRepository(BitbucketCloudRepository repository) {
}

@Override
@CheckForNull
public BitbucketCloudBranch getBranch() {
return branch;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -61,6 +65,7 @@ public void setRepository(BitbucketCloudRepository repository) {
}

@Override
@CheckForNull
public BitbucketCloudBranch getBranch() {
return branch;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ private List<BitbucketServerPullRequest> getPullRequests(UriTemplate template)
List<BitbucketServerPullRequest> 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().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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p>test from forked repo</p>",
"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": "<p>PR with destination branch deleted</p>",
"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
}