Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding signature to commits #951

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/kohsuke/github/GHCommitBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ public GHCommitBuilder author(String name, String email, Date date) {
return this;
}

/**
* Configures the PGP signature of this commit.
*
* @param signature
* the signature calculated from the commit
*
* @return the gh commit builder
*/
public GHCommitBuilder withSignature(String signature) {
req.with("signature", signature);
return this;
}

/**
* Configures the committer of this commit.
*
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.kohsuke.github.GHVerification.Reason.*;

/**
* @author Liam Newman
Expand Down Expand Up @@ -75,6 +76,40 @@ public void getBranch_URLEncoded() throws Exception {
assertThat(branch.getName(), is("test/#UrlEncode"));
}

@Test
public void createSignedCommitVerifyError() throws IOException {
GHRepository repository = getRepository();

GHTree ghTree = new GHTreeBuilder(repository).textEntry("a", "", false).create();

GHVerification verification = repository.createCommit()
.message("test signing")
.withSignature("-----BEGIN PGP SIGNATURE-----\ninvalid\n-----END PGP SIGNATURE-----")
.tree(ghTree.getSha())
.create()
.getCommitShortInfo()
.getVerification();

assertEquals(GPGVERIFY_ERROR, verification.getReason());
}

@Test
public void createSignedCommitUnknownSignatureType() throws IOException {
GHRepository repository = getRepository();

GHTree ghTree = new GHTreeBuilder(repository).textEntry("a", "", false).create();

GHVerification verification = repository.createCommit()
.message("test signing")
.withSignature("unknown")
.tree(ghTree.getSha())
.create()
.getCommitShortInfo()
.getVerification();

assertEquals(UNKNOWN_SIGNATURE_TYPE, verification.getReason());
}

// Issue #607
@Test
public void getBranchNonExistentBut200Status() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/hub4j-test-org",
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": "Hub4j Test Org Description (this could be null or blank too)",
"name": "Hub4j Test Org Name (this could be null or blank too)",
"company": null,
"blog": "https://hub4j.url.io/could/be/null",
"location": "Hub4j Test Org Location (this could be null or blank too)",
"email": "hub4jtestorgemail@could.be.null.com",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 13,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization",
"total_private_repos": 1,
"owned_private_repos": 1,
"private_gists": 0,
"disk_usage": 152,
"collaborators": 0,
"billing_email": "kk@kohsuke.org",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_can_create_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 18,
"seats": 3
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"sha": "4c84ff0c2e63c338a783d151d34884443269c2b7",
"node_id": "MDY6Q29tbWl0MjA2ODg4MjAxOjRjODRmZjBjMmU2M2MzMzhhNzgzZDE1MWQzNDg4NDQ0MzI2OWMyYjc=",
"commit": {
"author": {
"name": "Tadas Giniotis",
"email": "61763026+tginiotis-at-work@users.noreply.github.com",
"date": "2020-09-30T22:23:51Z"
},
"committer": {
"name": "Tadas Giniotis",
"email": "61763026+tginiotis-at-work@users.noreply.github.com",
"date": "2020-09-30T22:23:51Z"
},
"message": "test signing",
"tree": {
"sha": "496d6428b9cf92981dc9495211e6e1120fb6f2ba",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees/496d6428b9cf92981dc9495211e6e1120fb6f2ba"
},
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits/4c84ff0c2e63c338a783d151d34884443269c2b7",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unknown_signature_type",
"signature": "unknown",
"payload": "tree 496d6428b9cf92981dc9495211e6e1120fb6f2ba\nauthor Tadas Giniotis <61763026+tginiotis-at-work@users.noreply.github.com> 1601504631 +0300\ncommitter Tadas Giniotis <61763026+tginiotis-at-work@users.noreply.github.com> 1601504631 +0300\n\ntest signing"
}
},
"url": "https://api.github.com/repos/hub4j-test-org/github-api/commits/4c84ff0c2e63c338a783d151d34884443269c2b7",
"html_url": "https://github.com/hub4j-test-org/github-api/commit/4c84ff0c2e63c338a783d151d34884443269c2b7",
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits/4c84ff0c2e63c338a783d151d34884443269c2b7/comments",
"author": {
"login": "tginiotis-at-work",
"id": 61763026,
"node_id": "MDQ6VXNlcjYxNzYzMDI2",
"avatar_url": "https://avatars3.githubusercontent.com/u/61763026?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tginiotis-at-work",
"html_url": "https://github.com/tginiotis-at-work",
"followers_url": "https://api.github.com/users/tginiotis-at-work/followers",
"following_url": "https://api.github.com/users/tginiotis-at-work/following{/other_user}",
"gists_url": "https://api.github.com/users/tginiotis-at-work/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tginiotis-at-work/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tginiotis-at-work/subscriptions",
"organizations_url": "https://api.github.com/users/tginiotis-at-work/orgs",
"repos_url": "https://api.github.com/users/tginiotis-at-work/repos",
"events_url": "https://api.github.com/users/tginiotis-at-work/events{/privacy}",
"received_events_url": "https://api.github.com/users/tginiotis-at-work/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "tginiotis-at-work",
"id": 61763026,
"node_id": "MDQ6VXNlcjYxNzYzMDI2",
"avatar_url": "https://avatars3.githubusercontent.com/u/61763026?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tginiotis-at-work",
"html_url": "https://github.com/tginiotis-at-work",
"followers_url": "https://api.github.com/users/tginiotis-at-work/followers",
"following_url": "https://api.github.com/users/tginiotis-at-work/following{/other_user}",
"gists_url": "https://api.github.com/users/tginiotis-at-work/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tginiotis-at-work/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tginiotis-at-work/subscriptions",
"organizations_url": "https://api.github.com/users/tginiotis-at-work/orgs",
"repos_url": "https://api.github.com/users/tginiotis-at-work/repos",
"events_url": "https://api.github.com/users/tginiotis-at-work/events{/privacy}",
"received_events_url": "https://api.github.com/users/tginiotis-at-work/received_events",
"type": "User",
"site_admin": false
},
"parents": [],
"stats": {
"total": 0,
"additions": 0,
"deletions": 0
},
"files": [
{
"sha": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"filename": "a",
"status": "added",
"additions": 0,
"deletions": 0,
"changes": 0,
"blob_url": "https://github.com/hub4j-test-org/github-api/blob/4c84ff0c2e63c338a783d151d34884443269c2b7/a",
"raw_url": "https://github.com/hub4j-test-org/github-api/raw/4c84ff0c2e63c338a783d151d34884443269c2b7/a",
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/a?ref=4c84ff0c2e63c338a783d151d34884443269c2b7"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"sha": "4c84ff0c2e63c338a783d151d34884443269c2b7",
"node_id": "MDY6Q29tbWl0MjA2ODg4MjAxOjRjODRmZjBjMmU2M2MzMzhhNzgzZDE1MWQzNDg4NDQ0MzI2OWMyYjc=",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits/4c84ff0c2e63c338a783d151d34884443269c2b7",
"html_url": "https://github.com/hub4j-test-org/github-api/commit/4c84ff0c2e63c338a783d151d34884443269c2b7",
"author": {
"name": "Tadas Giniotis",
"email": "61763026+tginiotis-at-work@users.noreply.github.com",
"date": "2020-09-30T22:23:51Z"
},
"committer": {
"name": "Tadas Giniotis",
"email": "61763026+tginiotis-at-work@users.noreply.github.com",
"date": "2020-09-30T22:23:51Z"
},
"tree": {
"sha": "496d6428b9cf92981dc9495211e6e1120fb6f2ba",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees/496d6428b9cf92981dc9495211e6e1120fb6f2ba"
},
"message": "test signing",
"parents": [],
"verification": {
"verified": false,
"reason": "unknown_signature_type",
"signature": "unknown",
"payload": "tree 496d6428b9cf92981dc9495211e6e1120fb6f2ba\nauthor Tadas Giniotis <61763026+tginiotis-at-work@users.noreply.github.com> 1601504631 +0300\ncommitter Tadas Giniotis <61763026+tginiotis-at-work@users.noreply.github.com> 1601504631 +0300\n\ntest signing"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sha": "496d6428b9cf92981dc9495211e6e1120fb6f2ba",
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees/496d6428b9cf92981dc9495211e6e1120fb6f2ba",
"tree": [
{
"path": "a",
"mode": "100644",
"type": "blob",
"sha": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"size": 0,
"url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs/e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
}
],
"truncated": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "a350645c-1938-4c8d-b164-fa9e0c67801f",
"name": "orgs_hub4j-test-org",
"request": {
"url": "/orgs/hub4j-test-org",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org-1.json",
"headers": {
"Date": "Wed, 30 Sep 2020 22:23:49 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"5c55d16bf1d59fa9c42072f73eac7e9484cb6b90e83ce9fecee1423b52bf612f\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4941",
"X-RateLimit-Reset": "1601504639",
"X-RateLimit-Used": "59",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "EDA2:11A07:1BDDC5BB:212F8CC2:5F750575"
}
},
"uuid": "a350645c-1938-4c8d-b164-fa9e0c67801f",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": "3fb900d8-a015-469c-99f9-4f8a8464a3a1",
"name": "repos_hub4j-test-org_github-api",
"request": {
"url": "/repos/hub4j-test-org/github-api",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_hub4j-test-org_github-api-2.json",
"headers": {
"Date": "Wed, 30 Sep 2020 22:23:50 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With",
"Accept-Encoding"
],
"ETag": "W/\"c8ad35a8cd7fe9644ddeb7b67d913887a2344f1572826dfde27f697035eba391\"",
"Last-Modified": "Wed, 10 Jun 2020 23:27:59 GMT",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4940",
"X-RateLimit-Reset": "1601504639",
"X-RateLimit-Used": "60",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "EDA2:11A07:1BDDC698:212F8D26:5F750575"
}
},
"uuid": "3fb900d8-a015-469c-99f9-4f8a8464a3a1",
"persistent": true,
"insertionIndex": 2
}
Loading