From 9b54bf4d8914de2c58cb88fe612a0d8d74ec97b0 Mon Sep 17 00:00:00 2001 From: sindunuragarp Date: Mon, 25 Nov 2024 21:31:40 +0100 Subject: [PATCH] BUG Issue Comment id can be bigger than Integer.MAX --- .../spotify/github/v3/comment/Comment.java | 2 +- .../github/v3/clients/IssueClientTest.java | 22 ++++++--- .../v3/clients/RepositoryClientTest.java | 4 +- .../v3/clients/comment_created_long_id.json | 45 +++++++++++++++++++ 4 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/com/spotify/github/v3/clients/comment_created_long_id.json diff --git a/src/main/java/com/spotify/github/v3/comment/Comment.java b/src/main/java/com/spotify/github/v3/comment/Comment.java index 175fdc19..1ac9429d 100644 --- a/src/main/java/com/spotify/github/v3/comment/Comment.java +++ b/src/main/java/com/spotify/github/v3/comment/Comment.java @@ -46,7 +46,7 @@ public interface Comment extends UpdateTracking { URI htmlUrl(); /** Comment ID. */ - int id(); + Long id(); /** The {@link User} that made the comment. */ @Nullable diff --git a/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java b/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java index dc7d1939..088f367b 100644 --- a/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/IssueClientTest.java @@ -84,8 +84,8 @@ public void testCommentPaginationSpliterator() throws IOException { final List listComments = Async.streamFromPaginatingIterable(pageIterator).collect(toList()); assertThat(listComments.size(), is(30)); - assertThat(listComments.get(0).id(), is(1345268)); - assertThat(listComments.get(listComments.size() - 1).id(), is(1356168)); + assertThat(listComments.get(0).id(), is(1345268L)); + assertThat(listComments.get(listComments.size() - 1).id(), is(1356168L)); } @Test @@ -117,8 +117,8 @@ public void testCommentPaginationForeach() throws IOException { }); assertThat(listComments.size(), is(30)); - assertThat(listComments.get(0).id(), is(1345268)); - assertThat(listComments.get(listComments.size() - 1).id(), is(1356168)); + assertThat(listComments.get(0).id(), is(1345268L)); + assertThat(listComments.get(listComments.size() - 1).id(), is(1356168L)); } @Test @@ -130,6 +130,18 @@ public void testCommentCreated() throws IOException { when(github.post(eq(path), anyString())).thenReturn(completedFuture(response)); final Comment comment = issueClient.createComment(10, "Me too").join(); - assertThat(comment.id(), is(114)); + assertThat(comment.id(), is(114L)); + } + + @Test + public void testCommentCreatedWithLargeId() throws IOException { + final String fixture = loadFixture("clients/comment_created_long_id.json"); + final Response response = createMockResponse("", fixture); + final String path = format(COMMENTS_URI_NUMBER_TEMPLATE, "someowner", "somerepo", 10); + when(github.post(anyString(), anyString(), eq(Comment.class))).thenCallRealMethod(); + when(github.post(eq(path), anyString())).thenReturn(completedFuture(response)); + final Comment comment = issueClient.createComment(10, "Me too").join(); + + assertThat(comment.id(), is(2459198527L)); } } diff --git a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java index bd8b7ace..f6c0ee37 100644 --- a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java @@ -539,7 +539,7 @@ public void testCommentCreated() throws IOException { .thenReturn(fixture); final Comment comment = repoClient.createComment("someweirdsha", "Me too").join(); - assertThat(comment.id(), is(123)); + assertThat(comment.id(), is(123L)); assertThat(comment.commitId().get(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); } @@ -551,7 +551,7 @@ public void getComment() throws IOException { .thenReturn(fixture); final Comment comment = repoClient.getComment(123).join(); - assertThat(comment.id(), is(123)); + assertThat(comment.id(), is(123L)); assertThat(comment.commitId().get(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); } diff --git a/src/test/resources/com/spotify/github/v3/clients/comment_created_long_id.json b/src/test/resources/com/spotify/github/v3/clients/comment_created_long_id.json new file mode 100644 index 00000000..1ddd888a --- /dev/null +++ b/src/test/resources/com/spotify/github/v3/clients/comment_created_long_id.json @@ -0,0 +1,45 @@ +{ + "url": "https://api.github.com/repos/spotify/github-java-client/issues/comments/1958720937", + "html_url": "https://github.com/spotify/github-java-client/pull/180#issuecomment-1958720937", + "issue_url": "https://api.github.com/repos/spotify/github-java-client/issues/180", + "id": 2459198527, + "node_id": "IC_kwDODynaQc50v7Wp", + "user": { + "login": "vootelerotov", + "id": 1439555, + "node_id": "MDQ6VXNlcjE0Mzk1NTU=", + "avatar_url": "https://avatars.githubusercontent.com/u/1439555?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vootelerotov", + "html_url": "https://github.com/vootelerotov", + "followers_url": "https://api.github.com/users/vootelerotov/followers", + "following_url": "https://api.github.com/users/vootelerotov/following{/other_user}", + "gists_url": "https://api.github.com/users/vootelerotov/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vootelerotov/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vootelerotov/subscriptions", + "organizations_url": "https://api.github.com/users/vootelerotov/orgs", + "repos_url": "https://api.github.com/users/vootelerotov/repos", + "events_url": "https://api.github.com/users/vootelerotov/events{/privacy}", + "received_events_url": "https://api.github.com/users/vootelerotov/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "created_at": "2024-02-22T05:19:44Z", + "updated_at": "2024-02-22T05:19:44Z", + "author_association": "CONTRIBUTOR", + "body": "Ran into this in the wild.", + "reactions": { + "url": "https://api.github.com/repos/spotify/github-java-client/issues/comments/1958720937/reactions", + "total_count": 0, + "+1": 0, + "-1": 0, + "laugh": 0, + "hooray": 0, + "confused": 0, + "heart": 0, + "rocket": 0, + "eyes": 0 + }, + "performed_via_github_app": null +}