Skip to content

Commit 36b00d4

Browse files
committed
Add verified_at to GHVerification
1 parent 3622553 commit 36b00d4

10 files changed

Lines changed: 453 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.kohsuke.github;
22

3+
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
34
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
45

6+
import java.time.Instant;
7+
import java.util.Date;
8+
59
// TODO: Auto-generated Javadoc
610
/**
711
* The commit/tag can be signed by user. This object holds the verification status. Whether the Commit/Tag is signed or
@@ -15,7 +19,7 @@
1519
*/
1620
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
1721
justification = "JSON API")
18-
public class GHVerification {
22+
public class GHVerification extends GitHubBridgeAdapterObject {
1923

2024
/**
2125
* The possible values for reason in verification object from github.
@@ -84,6 +88,7 @@ public enum Reason {
8488
private Reason reason;
8589
private String signature, payload;
8690
private boolean verified;
91+
private String verifiedAt;
8792

8893
/**
8994
* Create default GHVerification instance
@@ -119,6 +124,16 @@ public String getSignature() {
119124
return signature;
120125
}
121126

127+
/**
128+
* Gets the time when the signature was verified by GitHub.
129+
*
130+
* @return the instant the signature was verified, or null if not available.
131+
*/
132+
@WithBridgeMethods(value = Date.class, adapterMethod = "instantToDate")
133+
public Instant getVerifiedAt() {
134+
return GitHubClient.parseInstant(verifiedAt);
135+
}
136+
122137
/**
123138
* Indicates whether GitHub considers the signature in this commit to be verified.
124139
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public void testBridgeMethods() {
8888
verifyBridgeMethods(GHSubscription.class, "getCreatedAt", Date.class, Instant.class);
8989
verifyBridgeMethods(GHThread.class, "getLastReadAt", Date.class, Instant.class);
9090
verifyBridgeMethods(GHUser.class, "getSuspendedAt", Date.class, Instant.class);
91+
verifyBridgeMethods(GHVerification.class, "getVerifiedAt", Date.class, Instant.class);
9192
verifyBridgeMethods(GHWorkflowJob.class, "getStartedAt", Date.class, Instant.class);
9293
verifyBridgeMethods(GHWorkflowJob.class, "getCompletedAt", Date.class, Instant.class);
9394
verifyBridgeMethods(GHWorkflowJob.class, "getStartedAt", Date.class, Instant.class);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.junit.Test;
44

5+
import java.time.Instant;
6+
57
import static org.hamcrest.Matchers.*;
68

79
// TODO: Auto-generated Javadoc
@@ -306,5 +308,21 @@ public void testValid() throws Exception {
306308
assertThat(commit.getCommitShortInfo().getVerification().getReason(), equalTo(GHVerification.Reason.VALID));
307309
assertThat(commit.getCommitShortInfo().getVerification().getPayload(), notNullValue());
308310
assertThat(commit.getCommitShortInfo().getVerification().getSignature(), notNullValue());
311+
assertThat(commit.getCommitShortInfo().getVerification().getVerifiedAt(),
312+
equalTo(Instant.ofEpochMilli(1615809600000L)));
313+
}
314+
315+
/**
316+
* Test verified at is null when not verified.
317+
*
318+
* @throws Exception
319+
* the exception
320+
*/
321+
@Test
322+
public void testVerifiedAtNullWhenUnsigned() throws Exception {
323+
GHRepository r = gitHub.getRepository("hub4j/github-api");
324+
GHCommit commit = r.getCommit("86a2e245aa6d71d54923655066049d9e21a15f05");
325+
assertThat(commit.getCommitShortInfo().getVerification().isVerified(), is(false));
326+
assertThat(commit.getCommitShortInfo().getVerification().getVerifiedAt(), nullValue());
309327
}
310328
}

src/test/resources/org/kohsuke/github/GHVerificationReasonTest/wiremock/testValid/__files/3-r_h_g_commits_86a2e245.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"verification": {
2323
"verified": true,
2424
"reason": "valid",
25+
"verified_at": "2021-03-15T12:00:00Z",
2526
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJdWt+iCRBK7hj4Ov3rIwAAdHIIAF2vncFEFRwkJdZrVZEkT30N\neYJXFeILq+wFRDuWEDOueIkUwCy9Z4xYnM/n7fw+51LsRK+4kaFNjP6HFJGr/+m5\nioCArE27vaXnZjTAldpAG0Jku3eIfChutub0HcBy4UURozLw70ajWpbA3vOQ560B\ntontgx2I/pJmwOqkXRVvM7yxTlW751kyTVWScCtOeX2efuveeotECsDrqScKxq66\nkvJ1xmb9olWdlTjChOgqNrLbLC0jUHqc1nMGCkkVL0Pl2BMB8cXrKBQyU71ZuVJt\n4EW8IBWBtuHwHFtwABBCHXdtSsCGPat0hVag72CHiqKoZV/EAPecIlyiZMAYYig=\n=7zTb\n-----END PGP SIGNATURE-----\n",
2627
"payload": "tree 859fffa8ce0c958e4e4209c7a758be16f0c97c55\nparent 2a971c4e38c6d6693f7ad8b6768e4d74840d6679\nauthor Jeff Thompson <37345299+jeffret-b@users.noreply.github.com> 1566236578 -0600\ncommitter GitHub <noreply@github.com> 1566236578 -0600\n\nUpdate BSD license reference.\n\nCo-Authored-By: Jesse Glick <jglick@cloudbees.com>"
2728
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "bitwiseman",
3+
"id": 1958953,
4+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
5+
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/bitwiseman",
8+
"html_url": "https://github.com/bitwiseman",
9+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
10+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
14+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
15+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
16+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Liam Newman",
21+
"company": "Cloudbees, Inc.",
22+
"blog": "",
23+
"location": "Seattle, WA, USA",
24+
"email": "bitwiseman@gmail.com",
25+
"hireable": null,
26+
"bio": "https://twitter.com/bitwiseman",
27+
"public_repos": 169,
28+
"public_gists": 7,
29+
"followers": 139,
30+
"following": 9,
31+
"created_at": "2012-07-11T20:38:33Z",
32+
"updated_at": "2019-09-24T19:32:29Z",
33+
"private_gists": 7,
34+
"total_private_repos": 9,
35+
"owned_private_repos": 0,
36+
"disk_usage": 33697,
37+
"collaborators": 0,
38+
"two_factor_authentication": true,
39+
"plan": {
40+
"name": "free",
41+
"space": 976562499,
42+
"collaborators": 0,
43+
"private_repos": 10000
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"id": 617210,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=",
4+
"name": "github-api",
5+
"full_name": "hub4j/github-api",
6+
"private": false,
7+
"owner": {
8+
"login": "hub4j",
9+
"id": 54909825,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
11+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j",
14+
"html_url": "https://github.com/hub4j",
15+
"followers_url": "https://api.github.com/users/hub4j/followers",
16+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j/repos",
22+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j/github-api",
28+
"description": "Java API for GitHub",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j/github-api",
31+
"forks_url": "https://api.github.com/repos/hub4j/github-api/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j/github-api/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j/github-api/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j/github-api/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j/github-api/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors",
49+
"subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j/github-api/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
67+
"created_at": "2010-04-19T04:13:03Z",
68+
"updated_at": "2019-10-25T01:32:16Z",
69+
"pushed_at": "2019-10-25T16:41:09Z",
70+
"git_url": "git://github.com/hub4j/github-api.git",
71+
"ssh_url": "git@github.com:hub4j/github-api.git",
72+
"clone_url": "https://github.com/hub4j/github-api.git",
73+
"svn_url": "https://github.com/hub4j/github-api",
74+
"homepage": "http://github-api.kohsuke.org/",
75+
"size": 13494,
76+
"stargazers_count": 565,
77+
"watchers_count": 565,
78+
"language": "Java",
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": true,
84+
"forks_count": 433,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 64,
89+
"license": {
90+
"key": "mit",
91+
"name": "MIT License",
92+
"spdx_id": "MIT",
93+
"url": "https://api.github.com/licenses/mit",
94+
"node_id": "MDc6TGljZW5zZTEz"
95+
},
96+
"forks": 433,
97+
"open_issues": 64,
98+
"watchers": 565,
99+
"default_branch": "main",
100+
"permissions": {
101+
"admin": true,
102+
"push": true,
103+
"pull": true
104+
},
105+
"allow_squash_merge": true,
106+
"allow_merge_commit": true,
107+
"allow_rebase_merge": true,
108+
"organization": {
109+
"login": "hub4j",
110+
"id": 54909825,
111+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
112+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
113+
"gravatar_id": "",
114+
"url": "https://api.github.com/users/hub4j",
115+
"html_url": "https://github.com/hub4j",
116+
"followers_url": "https://api.github.com/users/hub4j/followers",
117+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
118+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
119+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
120+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
121+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
122+
"repos_url": "https://api.github.com/users/hub4j/repos",
123+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
124+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
125+
"type": "Organization",
126+
"site_admin": false
127+
},
128+
"network_count": 433,
129+
"subscribers_count": 48
130+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"sha": "86a2e245aa6d71d54923655066049d9e21a15f05",
3+
"node_id": "MDY6Q29tbWl0NjE3MjEwOjg2YTJlMjQ1YWE2ZDcxZDU0OTIzNjU1MDY2MDQ5ZDllMjFhMTVmMjM=",
4+
"commit": {
5+
"author": {
6+
"name": "Sourabh Parkala",
7+
"email": "sourabh.sarvotham.parkala@sap.com",
8+
"date": "2010-04-19T04:12:41Z"
9+
},
10+
"committer": {
11+
"name": "Sourabh Parkala",
12+
"email": "sourabh.sarvotham.parkala@sap.com",
13+
"date": "2010-04-19T04:12:41Z"
14+
},
15+
"message": "doc",
16+
"tree": {
17+
"sha": "17ed4173aeb2e98c93216e8b6e16138dc7f8cd91",
18+
"url": "https://api.github.com/repos/hub4j/github-api/git/trees/17ed4173aeb2e98c93216e8b6e16138dc7f8cd91"
19+
},
20+
"url": "https://api.github.com/repos/hub4j/github-api/git/commits/86a2e245aa6d71d54923655066049d9e21a15f05",
21+
"comment_count": 0,
22+
"verification": {
23+
"verified": false,
24+
"reason": "unsigned",
25+
"signature": null,
26+
"payload": null
27+
}
28+
},
29+
"url": "https://api.github.com/repos/hub4j/github-api/commits/86a2e245aa6d71d54923655066049d9e21a15f05",
30+
"html_url": "https://github.com/hub4j/github-api/commit/86a2e245aa6d71d54923655066049d9e21a15f05",
31+
"comments_url": "https://api.github.com/repos/hub4j/github-api/commits/86a2e245aa6d71d54923655066049d9e21a15f05/comments",
32+
"author": {
33+
"login": "kohsuke",
34+
"id": 50003,
35+
"node_id": "MDQ6VXNlcjUwMDAz",
36+
"avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4",
37+
"gravatar_id": "",
38+
"url": "https://api.github.com/users/kohsuke",
39+
"html_url": "https://github.com/kohsuke",
40+
"followers_url": "https://api.github.com/users/kohsuke/followers",
41+
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
42+
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
43+
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
44+
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
45+
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
46+
"repos_url": "https://api.github.com/users/kohsuke/repos",
47+
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
48+
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
49+
"type": "User",
50+
"site_admin": false
51+
},
52+
"committer": {
53+
"login": "kohsuke",
54+
"id": 50003,
55+
"node_id": "MDQ6VXNlcjUwMDAz",
56+
"avatar_url": "https://avatars1.githubusercontent.com/u/50003?v=4",
57+
"gravatar_id": "",
58+
"url": "https://api.github.com/users/kohsuke",
59+
"html_url": "https://github.com/kohsuke",
60+
"followers_url": "https://api.github.com/users/kohsuke/followers",
61+
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
62+
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
63+
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
64+
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
65+
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
66+
"repos_url": "https://api.github.com/users/kohsuke/repos",
67+
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
68+
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
69+
"type": "User",
70+
"site_admin": false
71+
},
72+
"parents": [
73+
{
74+
"sha": "ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396",
75+
"url": "https://api.github.com/repos/hub4j/github-api/commits/ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396",
76+
"html_url": "https://github.com/hub4j/github-api/commit/ecbfdd7315ef2cf04b2be7f11a072ce0bd00c396"
77+
}
78+
],
79+
"stats": {
80+
"total": 3,
81+
"additions": 3,
82+
"deletions": 0
83+
},
84+
"files": [
85+
{
86+
"sha": "2a2e1f77fd77bd03273946d893d25a455f696be0",
87+
"filename": "README",
88+
"status": "added",
89+
"additions": 3,
90+
"deletions": 0,
91+
"changes": 3,
92+
"blob_url": "https://github.com/hub4j/github-api/blob/86a2e245aa6d71d54923655066049d9e21a15f05/README",
93+
"raw_url": "https://github.com/hub4j/github-api/raw/86a2e245aa6d71d54923655066049d9e21a15f05/README",
94+
"contents_url": "https://api.github.com/repos/hub4j/github-api/contents/README?ref=86a2e245aa6d71d54923655066049d9e21a15f05",
95+
"patch": "@@ -0,0 +1,3 @@\n+Java API for GitHub\n+\n+See http://kohsuke.org/github-api/ for more details"
96+
}
97+
]
98+
}

0 commit comments

Comments
 (0)