Skip to content

Commit 9d6e361

Browse files
sindunuragarpvootelerotovAbhi347
authored
fix: Set id field of PullRequest, Comment and Issue to Long (#200)
* BUG SearchIssue id can be bigger than Integer.MAX Represent it as Long instead of Integer. For schema (where id is specified as 'int64') see: https://docs.github.com/en/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests * fix tests for SearchTest * BUG PullRequest id can be bigger than Integer.MAX Represent the id as Long instead of Integer. Official Schema for Pull Request -> int64: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests * BUG Issue Comment id can be bigger than Integer.MAX * test: Fix failing test after merge from master --------- Co-authored-by: Vootele Rotov <[email protected]> Co-authored-by: Abhishek Jain <[email protected]>
1 parent 44eb801 commit 9d6e361

File tree

10 files changed

+558
-12
lines changed

10 files changed

+558
-12
lines changed

src/main/java/com/spotify/github/v3/comment/Comment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface Comment extends UpdateTracking {
4646
URI htmlUrl();
4747

4848
/** Comment ID. */
49-
int id();
49+
Long id();
5050

5151
/** The {@link User} that made the comment. */
5252
@Nullable

src/main/java/com/spotify/github/v3/issues/Issue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface Issue extends CloseTracking {
4141

4242
/** ID. */
4343
@Nullable
44-
Integer id();
44+
Long id();
4545

4646
/** URL. */
4747
@Nullable

src/main/java/com/spotify/github/v3/prs/PullRequestItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public interface PullRequestItem extends CloseTracking {
4343

4444
/** ID. */
4545
@Nullable
46-
Integer id();
46+
Long id();
4747

4848
/** URL. */
4949
@Nullable

src/test/java/com/spotify/github/v3/clients/IssueClientTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public void testCommentPaginationSpliterator() throws IOException {
102102
Async.streamFromPaginatingIterable(pageIterator).collect(toList());
103103

104104
assertThat(listComments.size(), is(30));
105-
assertThat(listComments.get(0).id(), is(1345268));
106-
assertThat(listComments.get(listComments.size() - 1).id(), is(1356168));
105+
assertThat(listComments.get(0).id(), is(1345268L));
106+
assertThat(listComments.get(listComments.size() - 1).id(), is(1356168L));
107107
}
108108

109109
@Test
@@ -135,8 +135,8 @@ public void testCommentPaginationForeach() throws IOException {
135135
});
136136

137137
assertThat(listComments.size(), is(30));
138-
assertThat(listComments.get(0).id(), is(1345268));
139-
assertThat(listComments.get(listComments.size() - 1).id(), is(1356168));
138+
assertThat(listComments.get(0).id(), is(1345268L));
139+
assertThat(listComments.get(listComments.size() - 1).id(), is(1356168L));
140140
}
141141

142142
@Test
@@ -148,7 +148,19 @@ public void testCommentCreated() throws IOException {
148148
when(github.post(eq(path), anyString())).thenReturn(completedFuture(response));
149149
final Comment comment = issueClient.createComment(10, "Me too").join();
150150

151-
assertThat(comment.id(), is(114));
151+
assertThat(comment.id(), is(114L));
152+
}
153+
154+
@Test
155+
public void testCommentCreatedWithLargeId() throws IOException {
156+
final String fixture = loadFixture("clients/comment_created_long_id.json");
157+
final Response response = createMockResponse("", fixture);
158+
final String path = format(COMMENTS_URI_NUMBER_TEMPLATE, "someowner", "somerepo", 10);
159+
when(github.post(anyString(), anyString(), eq(Comment.class))).thenCallRealMethod();
160+
when(github.post(eq(path), anyString())).thenReturn(completedFuture(response));
161+
final Comment comment = issueClient.createComment(10, "Me too").join();
162+
163+
assertThat(comment.id(), is(2459198527L));
152164
}
153165

154166
@Test
@@ -160,7 +172,7 @@ public void testGetIssue() throws IOException {
160172

161173
final var issue = issueClient.getIssue(2).join();
162174

163-
assertThat(issue.id(), is(2));
175+
assertThat(issue.id(), is(2L));
164176
assertNotNull(issue.labels());
165177
assertFalse(issue.labels().isEmpty());
166178
assertThat(issue.labels().get(0).name(), is("bug"));

src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public void testCommentCreated() throws IOException {
539539
.thenReturn(fixture);
540540
final Comment comment = repoClient.createComment("someweirdsha", "Me too").join();
541541

542-
assertThat(comment.id(), is(123));
542+
assertThat(comment.id(), is(123L));
543543
assertThat(comment.commitId().get(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e"));
544544
}
545545

@@ -551,7 +551,7 @@ public void getComment() throws IOException {
551551
.thenReturn(fixture);
552552
final Comment comment = repoClient.getComment(123).join();
553553

554-
assertThat(comment.id(), is(123));
554+
assertThat(comment.id(), is(123L));
555555
assertThat(comment.commitId().get(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e"));
556556
}
557557

src/test/java/com/spotify/github/v3/prs/PullRequestTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public void testDeserializationPr() throws IOException {
3838
String fixture =
3939
Resources.toString(getResource(this.getClass(), "pull_request.json"), defaultCharset());
4040
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);
41+
42+
assertThat(pr.id(), is(1L));
4143
assertThat(pr.nodeId(), is("MDExOlB1bGxSZXF1ZXN0NDI3NDI0Nw=="));
4244
assertThat(pr.mergeCommitSha().get(), is("e5bd3914e2e596debea16f433f57875b5b90bcd6"));
4345
assertThat(pr.merged(), is(false));
@@ -53,6 +55,19 @@ public void testDeserializationPr() throws IOException {
5355
assertThat(pr.labels().get(0).color(),is("ff0000"));
5456
}
5557

58+
@Test
59+
public void testDeserializationPrWithLargeId() throws IOException {
60+
String fixture =
61+
Resources.toString(getResource(this.getClass(), "pull_request_long_id.json"), defaultCharset());
62+
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);
63+
64+
assertThat(pr.id(), is(2459198527L));
65+
assertThat(pr.head().sha(), is("f74c7f420282f584acd2fb5964202e5b525c3ab8"));
66+
assertThat(pr.merged(), is(false));
67+
assertThat(pr.mergeable().get(), is(false));
68+
assertThat(pr.draft(), is(Optional.of(true)));
69+
}
70+
5671
@Test
5772
public void testSerializationMergeParams() throws IOException {
5873
String fixture =

src/test/java/com/spotify/github/v3/search/SearchTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static final void assertSearchIssues(final SearchIssues search) {
4242
issues.url(),
4343
is(URI.create("https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132")));
4444
assertThat(issues.number(), is(132));
45-
assertThat(issues.id(), is(35802));
45+
assertThat(issues.id(), is(35802L));
4646
assertThat(issues.title(), is("Line Number Indexes Beyond 20 Not Displayed"));
4747
}
4848

@@ -54,4 +54,17 @@ public void testDeserialization() throws IOException {
5454
final SearchIssues search = Json.create().fromJson(fixture, SearchIssues.class);
5555
assertSearchIssues(search);
5656
}
57+
58+
@Test
59+
public void testDeserializationWithLargeIssueId() throws IOException {
60+
final String fixture =
61+
Resources.toString(getResource(this.getClass(), "issues-long-id.json"), defaultCharset());
62+
63+
final SearchIssues search = Json.create().fromJson(fixture, SearchIssues.class);
64+
assertThat(search.items().size(), is(1));
65+
66+
final Issue issue = search.items().get(0);
67+
assertThat(issue.id(), is(2592843837L));
68+
assertThat(issue.number(), is(5514));
69+
}
5770
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"url": "https://api.github.com/repos/spotify/github-java-client/issues/comments/1958720937",
3+
"html_url": "https://github.com/spotify/github-java-client/pull/180#issuecomment-1958720937",
4+
"issue_url": "https://api.github.com/repos/spotify/github-java-client/issues/180",
5+
"id": 2459198527,
6+
"node_id": "IC_kwDODynaQc50v7Wp",
7+
"user": {
8+
"login": "vootelerotov",
9+
"id": 1439555,
10+
"node_id": "MDQ6VXNlcjE0Mzk1NTU=",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/1439555?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/vootelerotov",
14+
"html_url": "https://github.com/vootelerotov",
15+
"followers_url": "https://api.github.com/users/vootelerotov/followers",
16+
"following_url": "https://api.github.com/users/vootelerotov/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/vootelerotov/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/vootelerotov/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/vootelerotov/subscriptions",
20+
"organizations_url": "https://api.github.com/users/vootelerotov/orgs",
21+
"repos_url": "https://api.github.com/users/vootelerotov/repos",
22+
"events_url": "https://api.github.com/users/vootelerotov/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/vootelerotov/received_events",
24+
"type": "User",
25+
"user_view_type": "public",
26+
"site_admin": false
27+
},
28+
"created_at": "2024-02-22T05:19:44Z",
29+
"updated_at": "2024-02-22T05:19:44Z",
30+
"author_association": "CONTRIBUTOR",
31+
"body": "Ran into this in the wild.",
32+
"reactions": {
33+
"url": "https://api.github.com/repos/spotify/github-java-client/issues/comments/1958720937/reactions",
34+
"total_count": 0,
35+
"+1": 0,
36+
"-1": 0,
37+
"laugh": 0,
38+
"hooray": 0,
39+
"confused": 0,
40+
"heart": 0,
41+
"rocket": 0,
42+
"eyes": 0
43+
},
44+
"performed_via_github_app": null
45+
}

0 commit comments

Comments
 (0)