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

Fix NullPointerException when a reviewer is deleted (#771) #1318

Merged
merged 5 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/java/org/kohsuke/github/GHPullRequestReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public String getBody() {
* the io exception
*/
public GHUser getUser() throws IOException {
return owner.root().getUser(user.getLogin());
if (user != null) {
return owner.root().getUser(user.getLogin());
}
return null;
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.Matchers.*;

Expand Down Expand Up @@ -543,6 +544,38 @@ public void getUserTest() throws IOException {
}
}

@Test
public void checkNonExistentReviewer() throws IOException {
// PR id is based on https://github.com/sahansera/TestRepo/pull/1
final GHPullRequest pullRequest = getRepository().getPullRequest(1);
final Optional<GHPullRequestReview> review = pullRequest.listReviews().toList().stream().findFirst();
final GHUser reviewer = review.get().getUser();

assertThat(pullRequest.getRequestedReviewers(), is(empty()));
assertThat(review, notNullValue());
assertThat(reviewer, is(nullValue()));
}

@Test
public void checkNonExistentAuthor() throws IOException {
// PR id is based on https://github.com/sahansera/TestRepo/pull/2
final GHPullRequest pullRequest = getRepository().getPullRequest(2);

assertThat(pullRequest.getUser(), is(notNullValue()));
assertThat(pullRequest.getUser().login, is("ghost"));
}

@Test
public void checkPullRequestReviewer() throws IOException {
// PR id is based on https://github.com/sahansera/TestRepo/pull/6
final GHPullRequest pullRequest = getRepository().getPullRequest(6);
final Optional<GHPullRequestReview> review = pullRequest.listReviews().toList().stream().findFirst();
final GHUser reviewer = review.get().getUser();

assertThat(review, notNullValue());
assertThat(reviewer, notNullValue());
}

protected GHRepository getRepository() throws IOException {
return getRepository(gitHub);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"login": "hub4j-test-org",
"id": 2032296,
"node_id": "MDQ6VXNlcjIwMzIyOTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/2032296?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "User"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"id": 423321524,
"node_id": "R_kgDOGTtftA",
"name": "github-api",
"full_name": "hub4j-test-org/github-api",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 2032296,
"node_id": "MDQ6VXNlcjIwMzIyOTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/2032296?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "User",
"site_admin": true
},
"html_url": "https://github.com/hub4j-test-org/github-api",
"description": "Recreating an issue",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/github-api",
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/github-api/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/github-api/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/github-api/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/github-api/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/github-api/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/github-api/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/github-api/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments",
"created_at": "2021-11-01T03:08:27Z",
"updated_at": "2021-11-01T03:09:57Z",
"pushed_at": "2021-11-08T13:29:40Z",
"git_url": "git://github.com/hub4j-test-org/github-api.git",
"ssh_url": "git@github.com:hub4j-test-org/github-api.git",
"clone_url": "https://github.com/hub4j-test-org/github-api.git",
"svn_url": "https://github.com/hub4j-test-org/github-api",
"homepage": null,
"size": 2,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"network_count": 0,
"subscribers_count": 1
}
Loading