Skip to content

Commit

Permalink
Merge pull request #1672 from MarkEWaite/pbeitz/maintain-permission
Browse files Browse the repository at this point in the history
Add MAINTAIN and TRIAGE permissions
  • Loading branch information
car-roll authored Jun 5, 2023
2 parents 7403e25 + ff16417 commit 4cbae90
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package org.kohsuke.github;

import java.util.Locale;
import org.kohsuke.github.internal.EnumUtils;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -52,7 +52,7 @@ public String getPermission() {
* @return the permission type
*/
public GHPermissionType getPermissionType() {
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
return EnumUtils.getEnumOrDefault(GHPermissionType.class, permission, GHPermissionType.UNKNOWN);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/kohsuke/github/GHPermissionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ public enum GHPermissionType {

/** The admin. */
ADMIN(30),
/** The maintain. */
MAINTAIN(25),
/** The write. */
WRITE(20),
/** The triage. */
TRIAGE(15),
/** The read. */
READ(10),
/** The none. */
NONE(0);
NONE(0),
/** The unknown permission type returned when an unrecognized permission type is returned. */
UNKNOWN(-5);

private final int level;

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/kohsuke/github/EnumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void touchEnums() {
assertThat(GHOrganization.Role.values().length, equalTo(2));
assertThat(GHOrganization.Permission.values().length, equalTo(5));

assertThat(GHPermissionType.values().length, equalTo(4));
assertThat(GHPermissionType.values().length, equalTo(7));

assertThat(GHProject.ProjectState.values().length, equalTo(2));
assertThat(GHProject.ProjectStateFilter.values().length, equalTo(3));
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1594,4 +1594,17 @@ public void testRepoActionVariable() throws Exception {
GHRepositoryVariable variable = repository.getRepoVariable("myvar");
assertThat(variable.getValue(), is("this is my var value"));
}

/**
* Test demoing the issue with a user having the maintain permission on a repository.
*
* @throws IOException
* the exception
*/
@Test
public void cannotRetrievePermissionMaintainUser() throws IOException {
GHRepository r = gitHub.getRepository("hub4j-test-org/maintain-permission-issue");
GHPermissionType permission = r.getPermission("alecharp");
assertThat(permission.toString(), is("MAINTAIN"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"id": 649600716,
"node_id": "R_kgDOJrgezA",
"name": "maintain-permission-issue",
"full_name": "hub4j-test-org/maintain-permission-issue",
"private": true,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"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": "Organization",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/maintain-permission-issue",
"description": "A repository to demo the maintain permission issue",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue",
"forks_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/maintain-permission-issue/deployments",
"created_at": "2023-06-05T08:29:48Z",
"updated_at": "2023-06-05T08:29:48Z",
"pushed_at": "2023-06-05T08:29:48Z",
"git_url": "git://github.com/hub4j-test-org/maintain-permission-issue.git",
"ssh_url": "[email protected]:hub4j-test-org/maintain-permission-issue.git",
"clone_url": "https://github.com/hub4j-test-org/maintain-permission-issue.git",
"svn_url": "https://github.com/hub4j-test-org/maintain-permission-issue",
"homepage": null,
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": false,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": false,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "private",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "ACLMQO62GXXZCCUB5ECCP3DEPWSHO",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"use_squash_pr_title_as_default": false,
"squash_merge_commit_message": "COMMIT_MESSAGES",
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
"merge_commit_message": "PR_TITLE",
"merge_commit_title": "MERGE_MESSAGE",
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"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": "Organization",
"site_admin": false
},
"network_count": 0,
"subscribers_count": 21
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"permission": "maintain",
"user": {
"login": "alecharp",
"id": 985955,
"node_id": "MDQ6VXNlcjk4NTk1NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/985955?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alecharp",
"html_url": "https://github.com/alecharp",
"followers_url": "https://api.github.com/users/alecharp/followers",
"following_url": "https://api.github.com/users/alecharp/following{/other_user}",
"gists_url": "https://api.github.com/users/alecharp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alecharp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alecharp/subscriptions",
"organizations_url": "https://api.github.com/users/alecharp/orgs",
"repos_url": "https://api.github.com/users/alecharp/repos",
"events_url": "https://api.github.com/users/alecharp/events{/privacy}",
"received_events_url": "https://api.github.com/users/alecharp/received_events",
"type": "User",
"site_admin": false,
"permissions": {
"admin": false,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"role_name": "maintain"
},
"role_name": "maintain"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"login": "PierreBtz",
"id": 9881659,
"node_id": "MDQ6VXNlcjk4ODE2NTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/9881659?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PierreBtz",
"html_url": "https://github.com/PierreBtz",
"followers_url": "https://api.github.com/users/PierreBtz/followers",
"following_url": "https://api.github.com/users/PierreBtz/following{/other_user}",
"gists_url": "https://api.github.com/users/PierreBtz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PierreBtz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PierreBtz/subscriptions",
"organizations_url": "https://api.github.com/users/PierreBtz/orgs",
"repos_url": "https://api.github.com/users/PierreBtz/repos",
"events_url": "https://api.github.com/users/PierreBtz/events{/privacy}",
"received_events_url": "https://api.github.com/users/PierreBtz/received_events",
"type": "User",
"site_admin": false,
"name": "Pierre Beitz",
"company": "@cloudbees ",
"blog": "",
"location": null,
"email": "[email protected]",
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 89,
"public_gists": 7,
"followers": 12,
"following": 11,
"created_at": "2014-11-21T10:26:34Z",
"updated_at": "2023-05-31T07:47:04Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": "1c85c1aa-c054-4ee0-88ac-7a1f093140ce",
"name": "repos_hub4j-test-org_maintain-permission-issue",
"request": {
"url": "/repos/hub4j-test-org/maintain-permission-issue",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_hub4j-test-org_maintain-permission-issue-2.json",
"headers": {
"Server": "GitHub.com",
"Date": "Mon, 05 Jun 2023 08:56:43 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/\"aff085d3b49db6fbe3ef8f48e6ca4fe314d68abfdbd7b6e866c4122a3eb0e611\"",
"Last-Modified": "Mon, 05 Jun 2023 08:29:48 GMT",
"X-OAuth-Scopes": "admin:org, repo",
"X-Accepted-OAuth-Scopes": "repo",
"github-authentication-token-expiration": "2023-07-05 08:21:35 UTC",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4953",
"X-RateLimit-Reset": "1685955508",
"X-RateLimit-Used": "47",
"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": "C925:6C90:53F8419:AC45847:647DA34A"
}
},
"uuid": "1c85c1aa-c054-4ee0-88ac-7a1f093140ce",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"id": "003b11c3-6e12-4da6-a439-02095d7d1328",
"name": "repos_hub4j-test-org_maintain-permission-issue_collaborators_alecharp_permission",
"request": {
"url": "/repos/hub4j-test-org/maintain-permission-issue/collaborators/alecharp/permission",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_hub4j-test-org_maintain-permission-issue_collaborators_alecharp_permission-3.json",
"headers": {
"Server": "GitHub.com",
"Date": "Mon, 05 Jun 2023 08:56:43 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/\"e2dc20577322b0be94a78538a4d6c166b39c016f02cb4db80cb63ba33bbf8afb\"",
"X-OAuth-Scopes": "admin:org, repo",
"X-Accepted-OAuth-Scopes": "",
"github-authentication-token-expiration": "2023-07-05 08:21:35 UTC",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4952",
"X-RateLimit-Reset": "1685955508",
"X-RateLimit-Used": "48",
"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": "C926:0FAC:4E05B5D:A05855E:647DA34B"
}
},
"uuid": "003b11c3-6e12-4da6-a439-02095d7d1328",
"persistent": true,
"insertionIndex": 3
}
Loading

0 comments on commit 4cbae90

Please sign in to comment.