From 6bf88261fd5ac4c0327c20e8374900cae252780e Mon Sep 17 00:00:00 2001 From: Vootele Rotov Date: Tue, 1 Aug 2023 09:48:16 +0300 Subject: [PATCH 1/2] bug: Check Suite id can be bigger than MAX_INT Not sure if it can be bigger than long either, but this does not make things worse and solves the issue I ran into. --- .../spotify/github/v3/checks/CheckSuite.java | 2 +- .../github/v3/checks/CheckSuiteTest.java | 12 ++ .../checks/check-suites-response-long-id.json | 183 ++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/com/spotify/github/v3/checks/check-suites-response-long-id.json diff --git a/src/main/java/com/spotify/github/v3/checks/CheckSuite.java b/src/main/java/com/spotify/github/v3/checks/CheckSuite.java index b1b8f05f..380b8aee 100644 --- a/src/main/java/com/spotify/github/v3/checks/CheckSuite.java +++ b/src/main/java/com/spotify/github/v3/checks/CheckSuite.java @@ -36,7 +36,7 @@ public interface CheckSuite { * * @return the integer */ - Integer id(); + Long id(); Optional app(); diff --git a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java index b821fc71..bb06f6f4 100644 --- a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java +++ b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java @@ -43,4 +43,16 @@ public void testDeserialization() throws IOException { assertThat(checkSuiteResponseList.checkSuites().get(0).app().get().slug().get(), is("octoapp")); } + + @Test + public void testDeserializationWithLongId() throws IOException { + // sample payload from https://docs.github.com/en/rest/checks/suites#list-check-suites-for-a-git-reference + String fixture = + Resources.toString( + getResource(this.getClass(), "check-suites-response-long-id.json"), defaultCharset()); + final CheckSuiteResponseList checkSuiteResponseList = Json.create().fromJson(fixture, CheckSuiteResponseList.class); + assertThat(checkSuiteResponseList.checkSuites().get(0).id(), is(14707641936L)); + assertThat(checkSuiteResponseList.checkSuites().get(0).app().get().slug().get(), is("octoapp")); + } + } \ No newline at end of file diff --git a/src/test/resources/com/spotify/github/v3/checks/check-suites-response-long-id.json b/src/test/resources/com/spotify/github/v3/checks/check-suites-response-long-id.json new file mode 100644 index 00000000..ca43441d --- /dev/null +++ b/src/test/resources/com/spotify/github/v3/checks/check-suites-response-long-id.json @@ -0,0 +1,183 @@ +{ + "total_count": 1, + "check_suites": [ + { + "id": 14707641936, + "node_id": "MDEwOkNoZWNrU3VpdGU1", + "head_branch": "master", + "head_sha": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "status": "completed", + "conclusion": "neutral", + "url": "https://api.github.com/repos/github/hello-world/check-suites/5", + "before": "146e867f55c26428e5f9fade55a9bbf5e95a7912", + "after": "d6fde92930d4715a2b49857d24b940956b26d2d3", + "pull_requests": [], + "app": { + "id": 1, + "slug": "octoapp", + "node_id": "MDExOkludGVncmF0aW9uMQ==", + "owner": { + "login": "github", + "id": 1, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", + "url": "https://api.github.com/orgs/github", + "repos_url": "https://api.github.com/orgs/github/repos", + "events_url": "https://api.github.com/orgs/github/events", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": true + }, + "name": "Octocat App", + "description": "", + "external_url": "https://example.com", + "html_url": "https://github.com/apps/octoapp", + "created_at": "2017-07-08T16:18:44-04:00", + "updated_at": "2017-07-08T16:18:44-04:00", + "permissions": { + "metadata": "read", + "contents": "read", + "issues": "write", + "single_file": "write" + }, + "events": [ + "push", + "pull_request" + ] + }, + "repository": { + "id": 1296269, + "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", + "name": "Hello-World", + "full_name": "octocat/Hello-World", + "owner": { + "login": "octocat", + "id": 1, + "node_id": "MDQ6VXNlcjE=", + "avatar_url": "https://github.com/images/error/octocat_happy.gif", + "gravatar_id": "", + "url": "https://api.github.com/users/octocat", + "html_url": "https://github.com/octocat", + "followers_url": "https://api.github.com/users/octocat/followers", + "following_url": "https://api.github.com/users/octocat/following{/other_user}", + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", + "organizations_url": "https://api.github.com/users/octocat/orgs", + "repos_url": "https://api.github.com/users/octocat/repos", + "events_url": "https://api.github.com/users/octocat/events{/privacy}", + "received_events_url": "https://api.github.com/users/octocat/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/octocat/Hello-World", + "description": "This your first repo!", + "fork": false, + "url": "https://api.github.com/repos/octocat/Hello-World", + "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", + "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", + "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", + "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", + "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", + "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", + "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", + "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", + "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", + "events_url": "https://api.github.com/repos/octocat/Hello-World/events", + "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", + "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", + "git_url": "git:github.com/octocat/Hello-World.git", + "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", + "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", + "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", + "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", + "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", + "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", + "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", + "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", + "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", + "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", + "ssh_url": "git@github.com:octocat/Hello-World.git", + "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", + "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", + "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", + "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", + "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", + "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", + "clone_url": "https://github.com/octocat/Hello-World.git", + "mirror_url": "git:git.example.com/octocat/Hello-World", + "hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks", + "svn_url": "https://svn.github.com/octocat/Hello-World", + "homepage": "https://github.com", + "language": null, + "forks_count": 9, + "stargazers_count": 80, + "watchers_count": 80, + "size": 108, + "default_branch": "master", + "open_issues_count": 0, + "is_template": true, + "topics": [ + "octocat", + "atom", + "electron", + "api" + ], + "has_issues": true, + "has_projects": true, + "has_wiki": true, + "has_pages": false, + "has_downloads": true, + "archived": false, + "disabled": false, + "visibility": "public", + "pushed_at": "2011-01-26T19:06:43Z", + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "permissions": { + "admin": false, + "push": false, + "pull": true + }, + "temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O", + "delete_branch_on_merge": true, + "subscribers_count": 42, + "network_count": 0 + }, + "created_at": "2011-01-26T19:01:12Z", + "updated_at": "2011-01-26T19:14:43Z", + "head_commit": { + "id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "tree_id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", + "message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.", + "timestamp": "2016-10-10T00:00:00Z", + "author": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + }, + "committer": { + "name": "The Octocat", + "email": "octocat@nowhere.com" + } + }, + "latest_check_runs_count": 1, + "check_runs_url": "https://api.github.com/repos/octocat/Hello-World/check-suites/5/check-runs" + } + ] +} \ No newline at end of file From 522850e34f4602a2d77eb98374006b2469ed9bf8 Mon Sep 17 00:00:00 2001 From: Vootele Rotov Date: Tue, 1 Aug 2023 09:50:10 +0300 Subject: [PATCH 2/2] clean: use dashes over underscores in check-suites-response.json for consistency Every other file in the same folder uses dashes, lets go with them. --- src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java | 2 +- .../java/com/spotify/github/v3/clients/GitHubClientTest.java | 2 +- .../{check_suites_response.json => check-suites-response.json} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/test/resources/com/spotify/github/v3/checks/{check_suites_response.json => check-suites-response.json} (100%) diff --git a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java index bb06f6f4..443a6fe4 100644 --- a/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java +++ b/src/test/java/com/spotify/github/v3/checks/CheckSuiteTest.java @@ -37,7 +37,7 @@ public void testDeserialization() throws IOException { // sample payload from https://docs.github.com/en/rest/checks/suites#list-check-suites-for-a-git-reference String fixture = Resources.toString( - getResource(this.getClass(), "check_suites_response.json"), defaultCharset()); + getResource(this.getClass(), "check-suites-response.json"), defaultCharset()); final CheckSuiteResponseList checkSuiteResponseList = Json.create().fromJson(fixture, CheckSuiteResponseList.class); assertThat(checkSuiteResponseList.checkSuites().get(0).id(), is(5)); assertThat(checkSuiteResponseList.checkSuites().get(0).app().get().slug().get(), is("octoapp")); diff --git a/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java b/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java index 6fae45dd..64b24bc8 100644 --- a/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/GitHubClientTest.java @@ -190,7 +190,7 @@ public void testGetCheckSuites() throws Throwable { .code(200) .body( ResponseBody.create( - MediaType.get("application/json"), getFixture("../checks/check_suites_response.json"))) + MediaType.get("application/json"), getFixture("../checks/check-suites-response.json"))) .message("") .protocol(Protocol.HTTP_1_1) .request(new Request.Builder().url("http://localhost/").build()) diff --git a/src/test/resources/com/spotify/github/v3/checks/check_suites_response.json b/src/test/resources/com/spotify/github/v3/checks/check-suites-response.json similarity index 100% rename from src/test/resources/com/spotify/github/v3/checks/check_suites_response.json rename to src/test/resources/com/spotify/github/v3/checks/check-suites-response.json