Skip to content
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
19 changes: 18 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2850,14 +2850,31 @@ public GHMilestone createMilestone(String title, String description) throws IOEx
* the io exception
*/
public GHDeployKey addDeployKey(String title, String key) throws IOException {
return addDeployKey(title, key, false);
}

/**
* Add deploy key gh deploy key.
*
* @param title
* the title
* @param key
* the key
* @param readOnly
* read-only ability of the key
* @return the gh deploy key
* @throws IOException
* the io exception
*/
public GHDeployKey addDeployKey(String title, String key, boolean readOnly) throws IOException {
return root().createRequest()
.method("POST")
.with("title", title)
.with("key", key)
.with("read_only", readOnly)
.withUrlPath(getApiTailUrl("keys"))
.fetch(GHDeployKey.class)
.lateBind(this);

}

/**
Expand Down
31 changes: 28 additions & 3 deletions src/test/java/org/kohsuke/github/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1283,18 +1283,43 @@ public void directoryListing() throws IOException {
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Ignore("Needs mocking check")
@Test
public void testAddDeployKey() throws IOException {
GHRepository myRepository = getTestRepository();
final GHDeployKey newDeployKey = myRepository.addDeployKey("test",
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUt0RAycC5cS42JKh6SecfFZBR1RrF+2hYMctz4mk74/arBE+wFb7fnSHGzdGKX2h5CFOWODifRCJVhB7hlVxodxe+QkQQYAEL/x1WVCJnGgTGQGOrhOMj95V3UE5pQKhsKD608C+u5tSofcWXLToP1/wZ7U4/AHjqYi08OLsWToHCax55TZkvdt2jo0hbIoYU+XI9Q8Uv4ONDN1oabiOdgeKi8+crvHAuvNleiBhWVBzFh8KdfzaH5uNdw7ihhFjEd1vzqACsjCINCjdMfzl6jD9ExuWuE92nZJnucls2cEoNC6k2aPmrZDg9hA32FXVpyseY+bDUWFU6LO2LG6PB kohsuke@atlas");
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATWwMLytklB44O66isWRKOB3Qd7Ysc7q7EyWTmT0bG9 [email protected]");
try {
assertThat(newDeployKey.getId(), notNullValue());

GHDeployKey k = Iterables.find(myRepository.getDeployKeys(), new Predicate<GHDeployKey>() {
public boolean apply(GHDeployKey deployKey) {
return newDeployKey.getId() == deployKey.getId() && !deployKey.isRead_only();
}
});
assertThat(k, notNullValue());
} finally {
newDeployKey.delete();
}
}

/**
* Test add deploy key read-only.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testAddDeployKeyAsReadOnly() throws IOException {
GHRepository myRepository = getTestRepository();
final GHDeployKey newDeployKey = myRepository.addDeployKey("test",
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATWwMLytklB44O66isWRKOB3Qd7Ysc7q7EyWTmT0bG9 [email protected]",
true);
try {
assertThat(newDeployKey.getId(), notNullValue());

GHDeployKey k = Iterables.find(myRepository.getDeployKeys(), new Predicate<GHDeployKey>() {
public boolean apply(GHDeployKey deployKey) {
return newDeployKey.getId() == deployKey.getId();
return newDeployKey.getId() == deployKey.getId() && deployKey.isRead_only();
}
});
assertThat(k, notNullValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"id": 611473997,
"node_id": "R_kgDOJHJaTQ",
"name": "github-api-test",
"full_name": "hub4j-test-org/github-api-test",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 238558,
"node_id": "MDQ6VXNlcjIzODU1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/238558?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/github-api-test",
"description": "A test repository for testing the github-api project: github-api-test",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments",
"created_at": "2023-03-08T22:36:45Z",
"updated_at": "2023-03-08T22:36:45Z",
"pushed_at": "2023-03-08T22:36:45Z",
"git_url": "git://github.com/hub4j-test-org/github-api-test.git",
"ssh_url": "[email protected]:hub4j-test-org/github-api-test.git",
"clone_url": "https://github.com/hub4j-test-org/github-api-test.git",
"svn_url": "https://github.com/hub4j-test-org/github-api-test",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"security_and_analysis": {
"secret_scanning": {
"status": "disabled"
},
"secret_scanning_push_protection": {
"status": "disabled"
}
},
"network_count": 0,
"subscribers_count": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": 78869617,
"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATWwMLytklB44O66isWRKOB3Qd7Ysc7q7EyWTmT0bG9",
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test/keys/78869617",
"title": "test",
"verified": true,
"created_at": "2023-03-08T22:36:50Z",
"read_only": false,
"last_used": null,
"added_by": "hub4j-test-org"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"id": 78869617,
"key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATWwMLytklB44O66isWRKOB3Qd7Ysc7q7EyWTmT0bG9",
"url": "https://api.github.com/repos/hub4j-test-org/github-api-test/keys/78869617",
"title": "test",
"verified": true,
"created_at": "2023-03-08T22:36:50Z",
"read_only": false,
"last_used": null,
"added_by": "hub4j-test-org"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDQ6VXNlcjIzODU1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "User",
"site_admin": false,
"name": "hub4j-test-org",
"company": null,
"blog": "",
"location": "",
"email": null,
"hireable": null,
"bio": "",
"twitter_username": null,
"public_repos": 13,
"public_gists": 4,
"followers": 6,
"following": 1,
"created_at": "2010-04-07T08:30:12Z",
"updated_at": "2022-11-28T20:54:46Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"id": "8b7ef826-893b-4288-b625-4492949cd9b1",
"name": "repos_hub4j-test-org_github-api-test",
"request": {
"url": "/repos/hub4j-test-org/github-api-test",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_hub4j-test-org_github-api-test-2.json",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 08 Mar 2023 22:36:49 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "W/\"9a25876ca00d328a54c1400dffe501009cdcbc3410dd90140b0c33cc19608961\"",
"Last-Modified": "Wed, 08 Mar 2023 22:36:45 GMT",
"github-authentication-token-expiration": "2023-04-07 23:24:34 +0200",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4903",
"X-RateLimit-Reset": "1678317208",
"X-RateLimit-Used": "97",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "E5D8:ACE5:B4A8F2D:B741C36:64090E01"
}
},
"uuid": "8b7ef826-893b-4288-b625-4492949cd9b1",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"id": "f648e6ad-c2ec-42b2-bc75-017ac64e67d9",
"name": "repos_hub4j-test-org_github-api-test_keys",
"request": {
"url": "/repos/hub4j-test-org/github-api-test/keys",
"method": "POST",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
},
"bodyPatterns": [
{
"equalToJson": "{\"read_only\":false,\"title\":\"test\",\"key\":\"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATWwMLytklB44O66isWRKOB3Qd7Ysc7q7EyWTmT0bG9 [email protected]\"}",
"ignoreArrayOrder": true,
"ignoreExtraElements": false
}
]
},
"response": {
"status": 201,
"bodyFileName": "repos_hub4j-test-org_github-api-test_keys-3.json",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 08 Mar 2023 22:36:50 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "\"0a4e82c98d34824d431a19b779f7fcc35e1a3c1142ff9c1a7132d8840630f8a6\"",
"github-authentication-token-expiration": "2023-04-07 23:24:34 +0200",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4902",
"X-RateLimit-Reset": "1678317208",
"X-RateLimit-Used": "98",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "E5DE:A9BF:A40D94B:A69E360:64090E01",
"Location": "https://api.github.com/repos/hub4j-test-org/github-api-test/keys/78869617"
}
},
"uuid": "f648e6ad-c2ec-42b2-bc75-017ac64e67d9",
"persistent": true,
"insertionIndex": 3
}
Loading