Skip to content

Commit 0f19519

Browse files
halkeymehmet.afacanbitwiseman
authored
Add withName method to GHCheckRunBuilder (#1769)
* issue1587: withName method created in GHCheckRunBuilder and its test has been written. * issue1587: test * issue1587: new test added to coverage missing lines and javadoc edited * issue1587: formatted --------- Co-authored-by: mehmet.afacan <[email protected]> Co-authored-by: Liam Newman <[email protected]>
1 parent 665a723 commit 0f19519

22 files changed

+1173
-0
lines changed

src/main/java/org/kohsuke/github/GHCheckRunBuilder.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
102102
.withUrlPath(repo.getApiTailUrl("check-runs/" + checkId)));
103103
}
104104

105+
/**
106+
* With name.
107+
*
108+
* @param name
109+
* the name
110+
* @param oldName
111+
* the old name
112+
* @return the GH check run builder
113+
*/
114+
public @NonNull GHCheckRunBuilder withName(@CheckForNull String name, String oldName) {
115+
if (oldName == null) {
116+
throw new GHException("Can not update uncreated check run");
117+
}
118+
requester.with("name", name);
119+
return this;
120+
}
121+
105122
/**
106123
* With details URL.
107124
*

src/test/java/org/kohsuke/github/GHCheckRunBuilderTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.kohsuke.github;
2626

27+
import org.junit.Assert;
2728
import org.junit.Test;
2829
import org.kohsuke.github.GHCheckRun.Status;
2930

@@ -195,4 +196,60 @@ public void updateCheckRun() throws Exception {
195196
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
196197
}
197198

199+
/**
200+
* Update check run with name.
201+
*
202+
* @throws Exception
203+
* the exception
204+
*/
205+
@Test
206+
public void updateCheckRunWithName() throws Exception {
207+
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
208+
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
209+
.withStatus(GHCheckRun.Status.IN_PROGRESS)
210+
.withStartedAt(new Date(999_999_000))
211+
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
212+
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
213+
1,
214+
GHCheckRun.AnnotationLevel.NOTICE,
215+
"hello to you too").withTitle("Look here")))
216+
.create();
217+
GHCheckRun updated = checkRun.update()
218+
.withStatus(GHCheckRun.Status.COMPLETED)
219+
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
220+
.withCompletedAt(new Date(999_999_999))
221+
.withName("bar", checkRun.getName())
222+
.create();
223+
assertThat(new Date(999_999_000), equalTo(updated.getStartedAt()));
224+
assertThat("bar", equalTo(updated.getName()));
225+
assertThat(checkRun.getOutput().getAnnotationsCount(), equalTo(1));
226+
}
227+
228+
/**
229+
* Update the check run with name exception.
230+
*
231+
* @throws Exception
232+
* the exception
233+
*/
234+
@Test
235+
public void updateCheckRunWithNameException() throws Exception {
236+
snapshotNotAllowed();
237+
GHCheckRun checkRun = getInstallationGithub().getRepository("hub4j-test-org/test-checks")
238+
.createCheckRun("foo", "89a9ae301e35e667756034fdc933b1fc94f63fc1")
239+
.withStatus(GHCheckRun.Status.IN_PROGRESS)
240+
.withStartedAt(new Date(999_999_000))
241+
.add(new GHCheckRunBuilder.Output("Some Title", "what happened…")
242+
.add(new GHCheckRunBuilder.Annotation("stuff.txt",
243+
1,
244+
GHCheckRun.AnnotationLevel.NOTICE,
245+
"hello to you too").withTitle("Look here")))
246+
.create();
247+
Assert.assertThrows(GHException.class,
248+
() -> checkRun.update()
249+
.withStatus(GHCheckRun.Status.COMPLETED)
250+
.withConclusion(GHCheckRun.Conclusion.SUCCESS)
251+
.withCompletedAt(new Date(999_999_999))
252+
.withName("bar", null)
253+
.create());
254+
}
198255
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"id": 89368,
3+
"slug": "ghapi-test-app-3",
4+
"node_id": "MDM6QXBwODkzNjg=",
5+
"owner": {
6+
"login": "hub4j-test-org",
7+
"id": 7544739,
8+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
9+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
10+
"gravatar_id": "",
11+
"url": "https://api.github.com/users/hub4j-test-org",
12+
"html_url": "https://github.com/hub4j-test-org",
13+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
14+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
15+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
16+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
17+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
18+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
19+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
20+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
21+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
22+
"type": "Organization",
23+
"site_admin": false
24+
},
25+
"name": "GHApi Test app 3",
26+
"description": "Test app for checks api testing",
27+
"external_url": "http://localhost",
28+
"html_url": "https://github.com/apps/ghapi-test-app-3",
29+
"created_at": "2020-11-19T14:30:34Z",
30+
"updated_at": "2020-11-19T14:30:34Z",
31+
"permissions": {
32+
"checks": "write",
33+
"metadata": "read"
34+
},
35+
"events": [],
36+
"installations_count": 1
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
{
3+
"id": 13064215,
4+
"account": {
5+
"login": "hub4j-test-org",
6+
"id": 7544739,
7+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
8+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/hub4j-test-org",
11+
"html_url": "https://github.com/hub4j-test-org",
12+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
13+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
17+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
18+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
19+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"repository_selection": "selected",
25+
"access_tokens_url": "https://api.github.com/app/installations/13064215/access_tokens",
26+
"repositories_url": "https://api.github.com/installation/repositories",
27+
"html_url": "https://github.com/organizations/hub4j-test-org/settings/installations/13064215",
28+
"app_id": 89368,
29+
"app_slug": "ghapi-test-app-3",
30+
"target_id": 7544739,
31+
"target_type": "Organization",
32+
"permissions": {
33+
"checks": "write",
34+
"metadata": "read"
35+
},
36+
"events": [],
37+
"created_at": "2020-11-19T14:33:27.000Z",
38+
"updated_at": "2020-11-19T14:33:27.000Z",
39+
"single_file_name": null,
40+
"has_multiple_single_files": false,
41+
"single_file_paths": [],
42+
"suspended_by": null,
43+
"suspended_at": null
44+
}
45+
]
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"id": 314259932,
3+
"node_id": "MDEwOlJlcG9zaXRvcnkzMTQyNTk5MzI=",
4+
"name": "test-checks",
5+
"full_name": "hub4j-test-org/test-checks",
6+
"private": true,
7+
"owner": {
8+
"login": "hub4j-test-org",
9+
"id": 7544739,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
11+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j-test-org",
14+
"html_url": "https://github.com/hub4j-test-org",
15+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
16+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
22+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j-test-org/test-checks",
28+
"description": "Repo for testing the checks API",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j-test-org/test-checks",
31+
"forks_url": "https://api.github.com/repos/hub4j-test-org/test-checks/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j-test-org/test-checks/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/test-checks/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j-test-org/test-checks/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j-test-org/test-checks/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/test-checks/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j-test-org/test-checks/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j-test-org/test-checks/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j-test-org/test-checks/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j-test-org/test-checks/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j-test-org/test-checks/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/test-checks/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/test-checks/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j-test-org/test-checks/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j-test-org/test-checks/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j-test-org/test-checks/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/test-checks/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j-test-org/test-checks/contributors",
49+
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/test-checks/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j-test-org/test-checks/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j-test-org/test-checks/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/test-checks/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j-test-org/test-checks/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/test-checks/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j-test-org/test-checks/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j-test-org/test-checks/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j-test-org/test-checks/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j-test-org/test-checks/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j-test-org/test-checks/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j-test-org/test-checks/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j-test-org/test-checks/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j-test-org/test-checks/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j-test-org/test-checks/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j-test-org/test-checks/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j-test-org/test-checks/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j-test-org/test-checks/deployments",
67+
"created_at": "2020-11-19T13:41:45Z",
68+
"updated_at": "2020-11-19T13:41:50Z",
69+
"pushed_at": "2020-11-19T13:41:47Z",
70+
"git_url": "git://github.com/hub4j-test-org/test-checks.git",
71+
"ssh_url": "[email protected]:hub4j-test-org/test-checks.git",
72+
"clone_url": "https://github.com/hub4j-test-org/test-checks.git",
73+
"svn_url": "https://github.com/hub4j-test-org/test-checks",
74+
"homepage": null,
75+
"size": 0,
76+
"stargazers_count": 0,
77+
"watchers_count": 0,
78+
"language": null,
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": false,
84+
"forks_count": 0,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 0,
89+
"license": null,
90+
"forks": 0,
91+
"open_issues": 0,
92+
"watchers": 0,
93+
"default_branch": "main",
94+
"permissions": {
95+
"admin": false,
96+
"push": false,
97+
"pull": false
98+
},
99+
"organization": {
100+
"login": "hub4j-test-org",
101+
"id": 7544739,
102+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
103+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
104+
"gravatar_id": "",
105+
"url": "https://api.github.com/users/hub4j-test-org",
106+
"html_url": "https://github.com/hub4j-test-org",
107+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
108+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
109+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
110+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
111+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
112+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
113+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
114+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
115+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
116+
"type": "Organization",
117+
"site_admin": false
118+
},
119+
"network_count": 0,
120+
"subscribers_count": 8
121+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"id": 1424883037,
3+
"node_id": "MDg6Q2hlY2tSdW4xNDI0ODgzMDM3",
4+
"head_sha": "89a9ae301e35e667756034fdc933b1fc94f63fc1",
5+
"external_id": "",
6+
"url": "https://api.github.com/repos/hub4j-test-org/test-checks/check-runs/1424883037",
7+
"html_url": "https://github.com/hub4j-test-org/test-checks/runs/1424883037",
8+
"details_url": "http://localhost",
9+
"status": "in_progress",
10+
"conclusion": null,
11+
"started_at": "1970-01-12T13:46:39Z",
12+
"completed_at": null,
13+
"output": {
14+
"title": "Some Title",
15+
"summary": "what happened…",
16+
"text": null,
17+
"annotations_count": 1,
18+
"annotations_url": "https://api.github.com/repos/hub4j-test-org/test-checks/check-runs/1424883037/annotations"
19+
},
20+
"name": "foo",
21+
"check_suite": {
22+
"id": 1529145983
23+
},
24+
"app": {
25+
"id": 89368,
26+
"slug": "ghapi-test-app-3",
27+
"node_id": "MDM6QXBwODkzNjg=",
28+
"owner": {
29+
"login": "hub4j-test-org",
30+
"id": 7544739,
31+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
32+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
33+
"gravatar_id": "",
34+
"url": "https://api.github.com/users/hub4j-test-org",
35+
"html_url": "https://github.com/hub4j-test-org",
36+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
37+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
38+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
39+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
40+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
41+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
42+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
43+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
44+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
45+
"type": "Organization",
46+
"site_admin": false
47+
},
48+
"name": "GHApi Test app 3",
49+
"description": "Test app for checks api testing",
50+
"external_url": "http://localhost",
51+
"html_url": "https://github.com/apps/ghapi-test-app-3",
52+
"created_at": "2020-11-19T14:30:34Z",
53+
"updated_at": "2020-11-19T14:30:34Z",
54+
"permissions": {
55+
"checks": "write",
56+
"metadata": "read"
57+
},
58+
"events": []
59+
},
60+
"pull_requests": []
61+
}

0 commit comments

Comments
 (0)