Merge pull request #1139 from akashRindhe/feature/1080

(feat) Add method to check if Organization has projects enabled
This commit is contained in:
Liam Newman
2021-05-13 11:26:07 -07:00
committed by GitHub
12 changed files with 544 additions and 0 deletions

View File

@@ -18,6 +18,9 @@ import static org.kohsuke.github.internal.Previews.INERTIA;
* @author Kohsuke Kawaguchi
*/
public class GHOrganization extends GHPerson {
private boolean has_organization_projects;
GHOrganization wrapUp(GitHub root) {
return (GHOrganization) super.wrapUp(root);
}
@@ -367,6 +370,35 @@ public class GHOrganization extends GHPerson {
root.createRequest().method("DELETE").withUrlPath("/orgs/" + login + "/public_members/" + u.getLogin()).send();
}
/**
* Are projects enabled for organization boolean.
*
* @return the boolean
*/
public boolean areOrganizationProjectsEnabled() {
return has_organization_projects;
}
/**
* Sets organization projects enabled status boolean
*
* @param newStatus
* enable status
* @throws IOException
* the io exception
*/
public void enableOrganizationProjects(boolean newStatus) throws IOException {
edit("has_organization_projects", newStatus);
}
private void edit(String key, Object value) throws IOException {
root.createRequest()
.withUrlPath(String.format("/orgs/%s", login))
.method("PATCH")
.with(key, value)
.fetchInto(this);
}
/**
* Returns the projects for this organization.
*

View File

@@ -29,6 +29,8 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
if (team != null) {
team.delete();
}
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
}
@Test
@@ -231,4 +233,28 @@ public class GHOrganizationTest extends AbstractGitHubWireMockTest {
assertThat(team.getDescription(), equalTo("Team description"));
assertThat(team.getPrivacy(), equalTo(GHTeam.Privacy.CLOSED));
}
@Test
public void testAreOrganizationProjectsEnabled() throws IOException {
// Arrange
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
// Act
boolean result = org.areOrganizationProjectsEnabled();
// Assert
assertThat(result, is(true));
}
@Test
public void testEnableOrganizationProjects() throws IOException {
// Arrange
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
// Act
org.enableOrganizationProjects(false);
// Assert
assertThat(org.areOrganizationProjectsEnabled(), is(false));
}
}

View File

@@ -0,0 +1,50 @@
{
"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://avatars.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": 17,
"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": 2,
"owned_private_repos": 2,
"private_gists": 0,
"disk_usage": 31,
"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,
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 23,
"seats": 3
}
}

View File

@@ -0,0 +1,46 @@
{
"login": "akashRindhe",
"id": 14114123,
"node_id": "MDQ6VXNlcjE0MTE0MTIz",
"avatar_url": "https://avatars.githubusercontent.com/u/14114123?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/akashRindhe",
"html_url": "https://github.com/akashRindhe",
"followers_url": "https://api.github.com/users/akashRindhe/followers",
"following_url": "https://api.github.com/users/akashRindhe/following{/other_user}",
"gists_url": "https://api.github.com/users/akashRindhe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/akashRindhe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/akashRindhe/subscriptions",
"organizations_url": "https://api.github.com/users/akashRindhe/orgs",
"repos_url": "https://api.github.com/users/akashRindhe/repos",
"events_url": "https://api.github.com/users/akashRindhe/events{/privacy}",
"received_events_url": "https://api.github.com/users/akashRindhe/received_events",
"type": "User",
"site_admin": false,
"name": "Akash Rindhe",
"company": null,
"blog": "",
"location": "Singapore",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 9,
"public_gists": 0,
"followers": 0,
"following": 6,
"created_at": "2015-09-03T18:07:43Z",
"updated_at": "2021-05-12T08:30:12Z",
"private_gists": 0,
"total_private_repos": 4,
"owned_private_repos": 4,
"disk_usage": 24551,
"collaborators": 1,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}

View File

@@ -0,0 +1,47 @@
{
"id": "d0322427-888c-40d9-a47d-b7c0f1d2fc71",
"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-2.json",
"headers": {
"Server": "GitHub.com",
"Date": "Thu, 13 May 2021 16:11:19 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/\"43be1c5d1d3fa4718ddcd58ebd6be4a41f81ddb5c2102d6ddd628548059db30d\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-OAuth-Scopes": "admin:enterprise, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4958",
"X-RateLimit-Reset": "1620924638",
"X-RateLimit-Used": "42",
"X-RateLimit-Resource": "core",
"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": "8358:203B:A245B6:B13792:609D4FA7"
}
},
"uuid": "d0322427-888c-40d9-a47d-b7c0f1d2fc71",
"persistent": true,
"insertionIndex": 2
}

View File

@@ -0,0 +1,47 @@
{
"id": "28895477-e3e7-4621-9a69-834956cf26d7",
"name": "user",
"request": {
"url": "/user",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "user-1.json",
"headers": {
"Server": "GitHub.com",
"Date": "Thu, 13 May 2021 16:11:17 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/\"848579fd41f059ee3a1a46f41bea53042fd2303af9d8670074420dc05bcfbd73\"",
"Last-Modified": "Wed, 12 May 2021 08:30:12 GMT",
"X-OAuth-Scopes": "admin:enterprise, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4963",
"X-RateLimit-Reset": "1620924638",
"X-RateLimit-Used": "37",
"X-RateLimit-Resource": "core",
"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": "8358:203B:A24554:B13727:609D4FA5"
}
},
"uuid": "28895477-e3e7-4621-9a69-834956cf26d7",
"persistent": true,
"insertionIndex": 1
}

View File

@@ -0,0 +1,50 @@
{
"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://avatars.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": 17,
"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": 2,
"owned_private_repos": 2,
"private_gists": 0,
"disk_usage": 31,
"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,
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 23,
"seats": 3
}
}

View File

@@ -0,0 +1,50 @@
{
"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://avatars.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": false,
"has_repository_projects": true,
"public_repos": 17,
"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": 2,
"owned_private_repos": 2,
"private_gists": 0,
"disk_usage": 31,
"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,
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 23,
"seats": 3
}
}

View File

@@ -0,0 +1,46 @@
{
"login": "akashRindhe",
"id": 14114123,
"node_id": "MDQ6VXNlcjE0MTE0MTIz",
"avatar_url": "https://avatars.githubusercontent.com/u/14114123?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/akashRindhe",
"html_url": "https://github.com/akashRindhe",
"followers_url": "https://api.github.com/users/akashRindhe/followers",
"following_url": "https://api.github.com/users/akashRindhe/following{/other_user}",
"gists_url": "https://api.github.com/users/akashRindhe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/akashRindhe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/akashRindhe/subscriptions",
"organizations_url": "https://api.github.com/users/akashRindhe/orgs",
"repos_url": "https://api.github.com/users/akashRindhe/repos",
"events_url": "https://api.github.com/users/akashRindhe/events{/privacy}",
"received_events_url": "https://api.github.com/users/akashRindhe/received_events",
"type": "User",
"site_admin": false,
"name": "Akash Rindhe",
"company": null,
"blog": "",
"location": "Singapore",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 9,
"public_gists": 0,
"followers": 0,
"following": 6,
"created_at": "2015-09-03T18:07:43Z",
"updated_at": "2021-05-12T08:30:12Z",
"private_gists": 0,
"total_private_repos": 4,
"owned_private_repos": 4,
"disk_usage": 24551,
"collaborators": 1,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}

View File

@@ -0,0 +1,47 @@
{
"id": "47c14d2c-d8d5-4f11-8208-fb790e6fccca",
"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-2.json",
"headers": {
"Server": "GitHub.com",
"Date": "Thu, 13 May 2021 16:07:24 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/\"43be1c5d1d3fa4718ddcd58ebd6be4a41f81ddb5c2102d6ddd628548059db30d\"",
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
"X-OAuth-Scopes": "admin:enterprise, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4966",
"X-RateLimit-Reset": "1620924638",
"X-RateLimit-Used": "34",
"X-RateLimit-Resource": "core",
"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": "834A:6C69:7FCEDB:8CA6DB:609D4EBC"
}
},
"uuid": "47c14d2c-d8d5-4f11-8208-fb790e6fccca",
"persistent": true,
"insertionIndex": 2
}

View File

@@ -0,0 +1,56 @@
{
"id": "eb95bb02-84c4-4e04-bfd4-851985556513",
"name": "orgs_hub4j-test-org",
"request": {
"url": "/orgs/hub4j-test-org",
"method": "POST",
"headers": {
"X-HTTP-Method-Override": {
"equalTo": "PATCH"
},
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
},
"bodyPatterns": [
{
"equalToJson": "{\"has_organization_projects\":false}",
"ignoreArrayOrder": true,
"ignoreExtraElements": false
}
]
},
"response": {
"status": 200,
"bodyFileName": "orgs_hub4j-test-org-3.json",
"headers": {
"Server": "GitHub.com",
"Date": "Thu, 13 May 2021 16:07:25 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/\"5ec2678c3553042c50562ea4033d38b2719d9a5b624a7d95dfcef66108c719f5\"",
"X-OAuth-Scopes": "admin:enterprise, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "admin:org, repo",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4965",
"X-RateLimit-Reset": "1620924638",
"X-RateLimit-Used": "35",
"X-RateLimit-Resource": "core",
"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": "834A:6C69:7FCEED:8CA6EE:609D4EBC"
}
},
"uuid": "eb95bb02-84c4-4e04-bfd4-851985556513",
"persistent": true,
"insertionIndex": 3
}

View File

@@ -0,0 +1,47 @@
{
"id": "b9ae2ae4-ec5c-425c-9144-5863690aabf5",
"name": "user",
"request": {
"url": "/user",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "user-1.json",
"headers": {
"Server": "GitHub.com",
"Date": "Thu, 13 May 2021 16:07:22 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/\"848579fd41f059ee3a1a46f41bea53042fd2303af9d8670074420dc05bcfbd73\"",
"Last-Modified": "Wed, 12 May 2021 08:30:12 GMT",
"X-OAuth-Scopes": "admin:enterprise, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "unknown, github.v3",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4971",
"X-RateLimit-Reset": "1620924638",
"X-RateLimit-Used": "29",
"X-RateLimit-Resource": "core",
"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": "834A:6C69:7FCE81:8CA67D:609D4EB9"
}
},
"uuid": "b9ae2ae4-ec5c-425c-9144-5863690aabf5",
"persistent": true,
"insertionIndex": 1
}