Skip to content

Commit a432a2b

Browse files
authored
added optional fields in CheckSuite and method to create ChecksClient (#115)
* added optional fields in CheckSuite and method to create ChecksClient * fixed documentation error * optional instead of nullable for apps in ChecksSuite Co-authored-by: Tasos Martidis <[email protected]>
1 parent aa1d1a4 commit a432a2b

File tree

6 files changed

+277
-0
lines changed

6 files changed

+277
-0
lines changed

src/main/java/com/spotify/github/v3/checks/CheckSuite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2424
import com.spotify.github.GithubStyle;
25+
import java.util.Optional;
2526
import org.immutables.value.Value;
2627

2728
/** Github CheckSuite */
@@ -36,4 +37,6 @@ public interface CheckSuite {
3637
* @return the integer
3738
*/
3839
Integer id();
40+
41+
Optional<App> app();
3942
}

src/main/java/com/spotify/github/v3/clients/ChecksClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class ChecksClient {
6060
this.repo = repo;
6161
}
6262

63+
static ChecksClient create(final GitHubClient github, final String owner, final String repo) {
64+
return new ChecksClient(github, owner, repo);
65+
}
66+
6367
/**
6468
* Create a checkRun.
6569
*

src/main/java/com/spotify/github/v3/clients/GitHubClient.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,17 @@ public SearchClient createSearchClient() {
351351
return SearchClient.create(this);
352352
}
353353

354+
/**
355+
* Create a checks API client
356+
*
357+
* @param owner repository owner
358+
* @param repo repository name
359+
* @return checks API client
360+
*/
361+
public ChecksClient createChecksClient(final String owner, final String repo) {
362+
return ChecksClient.create(this, owner, repo);
363+
}
364+
354365
Json json() {
355366
return json;
356367
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-
2+
* -\-\-
3+
* github-client
4+
* --
5+
* Copyright (C) 2016 - 2022 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.checks;
22+
23+
import static com.google.common.io.Resources.getResource;
24+
import static java.nio.charset.Charset.defaultCharset;
25+
import static org.hamcrest.CoreMatchers.is;
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
28+
import com.google.common.io.Resources;
29+
import com.spotify.github.jackson.Json;
30+
import java.io.IOException;
31+
import org.junit.jupiter.api.Test;
32+
33+
public class CheckSuiteTest {
34+
35+
@Test
36+
public void testDeserialization() throws IOException {
37+
// sample payload from https://docs.github.com/en/rest/checks/suites#list-check-suites-for-a-git-reference
38+
String fixture =
39+
Resources.toString(
40+
getResource(this.getClass(), "check_suites_response.json"), defaultCharset());
41+
final CheckSuiteResponseList checkSuiteResponseList = Json.create().fromJson(fixture, CheckSuiteResponseList.class);
42+
assertThat(checkSuiteResponseList.checkSuites().get(0).id(), is(5));
43+
assertThat(checkSuiteResponseList.checkSuites().get(0).app().get().slug().get(), is("octoapp"));
44+
}
45+
46+
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.google.common.io.Resources;
3333
import com.spotify.github.Tracer;
34+
import com.spotify.github.v3.checks.CheckSuiteResponseList;
3435
import com.spotify.github.v3.exceptions.ReadOnlyRepositoryException;
3536
import com.spotify.github.v3.exceptions.RequestNotOkException;
3637
import com.spotify.github.v3.repos.CommitItem;
@@ -177,4 +178,33 @@ public void testPutConvertsToClass() throws Throwable {
177178
assertThat(requestCapture.getValue().url().toString(), is("http://bogus/collaborators/"));
178179
assertThat(invitation.id(), is(1));
179180
}
181+
182+
@Test
183+
public void testGetCheckSuites() throws Throwable {
184+
185+
final Call call = mock(Call.class);
186+
final ArgumentCaptor<Callback> callbackCapture = ArgumentCaptor.forClass(Callback.class);
187+
doNothing().when(call).enqueue(callbackCapture.capture());
188+
189+
final Response response = new okhttp3.Response.Builder()
190+
.code(200)
191+
.body(
192+
ResponseBody.create(
193+
MediaType.get("application/json"), getFixture("../checks/check_suites_response.json")))
194+
.message("")
195+
.protocol(Protocol.HTTP_1_1)
196+
.request(new Request.Builder().url("http://localhost/").build())
197+
.build();
198+
199+
when(client.newCall(any())).thenReturn(call);
200+
ChecksClient client = github.createChecksClient("testorg", "testrepo");
201+
202+
CompletableFuture<CheckSuiteResponseList> future = client.getCheckSuites("sha");
203+
callbackCapture.getValue().onResponse(call, response);
204+
var result = future.get();
205+
206+
assertThat(result.totalCount(), is(1));
207+
assertThat(result.checkSuites().get(0).app().get().slug().get(), is("octoapp"));
208+
209+
}
180210
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"total_count": 1,
3+
"check_suites": [
4+
{
5+
"id": 5,
6+
"node_id": "MDEwOkNoZWNrU3VpdGU1",
7+
"head_branch": "master",
8+
"head_sha": "d6fde92930d4715a2b49857d24b940956b26d2d3",
9+
"status": "completed",
10+
"conclusion": "neutral",
11+
"url": "https://api.github.com/repos/github/hello-world/check-suites/5",
12+
"before": "146e867f55c26428e5f9fade55a9bbf5e95a7912",
13+
"after": "d6fde92930d4715a2b49857d24b940956b26d2d3",
14+
"pull_requests": [],
15+
"app": {
16+
"id": 1,
17+
"slug": "octoapp",
18+
"node_id": "MDExOkludGVncmF0aW9uMQ==",
19+
"owner": {
20+
"login": "github",
21+
"id": 1,
22+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
23+
"url": "https://api.github.com/orgs/github",
24+
"repos_url": "https://api.github.com/orgs/github/repos",
25+
"events_url": "https://api.github.com/orgs/github/events",
26+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
27+
"gravatar_id": "",
28+
"html_url": "https://github.com/octocat",
29+
"followers_url": "https://api.github.com/users/octocat/followers",
30+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
31+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
32+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
33+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
34+
"organizations_url": "https://api.github.com/users/octocat/orgs",
35+
"received_events_url": "https://api.github.com/users/octocat/received_events",
36+
"type": "User",
37+
"site_admin": true
38+
},
39+
"name": "Octocat App",
40+
"description": "",
41+
"external_url": "https://example.com",
42+
"html_url": "https://github.com/apps/octoapp",
43+
"created_at": "2017-07-08T16:18:44-04:00",
44+
"updated_at": "2017-07-08T16:18:44-04:00",
45+
"permissions": {
46+
"metadata": "read",
47+
"contents": "read",
48+
"issues": "write",
49+
"single_file": "write"
50+
},
51+
"events": [
52+
"push",
53+
"pull_request"
54+
]
55+
},
56+
"repository": {
57+
"id": 1296269,
58+
"node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5",
59+
"name": "Hello-World",
60+
"full_name": "octocat/Hello-World",
61+
"owner": {
62+
"login": "octocat",
63+
"id": 1,
64+
"node_id": "MDQ6VXNlcjE=",
65+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
66+
"gravatar_id": "",
67+
"url": "https://api.github.com/users/octocat",
68+
"html_url": "https://github.com/octocat",
69+
"followers_url": "https://api.github.com/users/octocat/followers",
70+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
71+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
72+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
73+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
74+
"organizations_url": "https://api.github.com/users/octocat/orgs",
75+
"repos_url": "https://api.github.com/users/octocat/repos",
76+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
77+
"received_events_url": "https://api.github.com/users/octocat/received_events",
78+
"type": "User",
79+
"site_admin": false
80+
},
81+
"private": false,
82+
"html_url": "https://github.com/octocat/Hello-World",
83+
"description": "This your first repo!",
84+
"fork": false,
85+
"url": "https://api.github.com/repos/octocat/Hello-World",
86+
"archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
87+
"assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}",
88+
"blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
89+
"branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}",
90+
"collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
91+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}",
92+
"commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}",
93+
"compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
94+
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}",
95+
"contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors",
96+
"deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments",
97+
"downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads",
98+
"events_url": "https://api.github.com/repos/octocat/Hello-World/events",
99+
"forks_url": "https://api.github.com/repos/octocat/Hello-World/forks",
100+
"git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
101+
"git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
102+
"git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
103+
"git_url": "git:github.com/octocat/Hello-World.git",
104+
"issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
105+
"issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
106+
"issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}",
107+
"keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
108+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}",
109+
"languages_url": "https://api.github.com/repos/octocat/Hello-World/languages",
110+
"merges_url": "https://api.github.com/repos/octocat/Hello-World/merges",
111+
"milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}",
112+
"notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}",
113+
"pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}",
114+
"releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}",
115+
"ssh_url": "[email protected]:octocat/Hello-World.git",
116+
"stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers",
117+
"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
118+
"subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers",
119+
"subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription",
120+
"tags_url": "https://api.github.com/repos/octocat/Hello-World/tags",
121+
"teams_url": "https://api.github.com/repos/octocat/Hello-World/teams",
122+
"trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
123+
"clone_url": "https://github.com/octocat/Hello-World.git",
124+
"mirror_url": "git:git.example.com/octocat/Hello-World",
125+
"hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks",
126+
"svn_url": "https://svn.github.com/octocat/Hello-World",
127+
"homepage": "https://github.com",
128+
"language": null,
129+
"forks_count": 9,
130+
"stargazers_count": 80,
131+
"watchers_count": 80,
132+
"size": 108,
133+
"default_branch": "master",
134+
"open_issues_count": 0,
135+
"is_template": true,
136+
"topics": [
137+
"octocat",
138+
"atom",
139+
"electron",
140+
"api"
141+
],
142+
"has_issues": true,
143+
"has_projects": true,
144+
"has_wiki": true,
145+
"has_pages": false,
146+
"has_downloads": true,
147+
"archived": false,
148+
"disabled": false,
149+
"visibility": "public",
150+
"pushed_at": "2011-01-26T19:06:43Z",
151+
"created_at": "2011-01-26T19:01:12Z",
152+
"updated_at": "2011-01-26T19:14:43Z",
153+
"permissions": {
154+
"admin": false,
155+
"push": false,
156+
"pull": true
157+
},
158+
"temp_clone_token": "ABTLWHOULUVAXGTRYU7OC2876QJ2O",
159+
"delete_branch_on_merge": true,
160+
"subscribers_count": 42,
161+
"network_count": 0
162+
},
163+
"created_at": "2011-01-26T19:01:12Z",
164+
"updated_at": "2011-01-26T19:14:43Z",
165+
"head_commit": {
166+
"id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
167+
"tree_id": "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
168+
"message": "Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.",
169+
"timestamp": "2016-10-10T00:00:00Z",
170+
"author": {
171+
"name": "The Octocat",
172+
"email": "[email protected]"
173+
},
174+
"committer": {
175+
"name": "The Octocat",
176+
"email": "[email protected]"
177+
}
178+
},
179+
"latest_check_runs_count": 1,
180+
"check_runs_url": "https://api.github.com/repos/octocat/Hello-World/check-suites/5/check-runs"
181+
}
182+
]
183+
}

0 commit comments

Comments
 (0)