Skip to content

Commit 4689b8f

Browse files
committed
(feat) Add method to set projects enabled flag for Organization
[#1080]
1 parent c4de682 commit 4689b8f

File tree

8 files changed

+330
-6
lines changed

8 files changed

+330
-6
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,26 @@ public boolean areOrganizationProjectsEnabled() {
379379
return has_organization_projects;
380380
}
381381

382+
/**
383+
* Sets organization projects enabled status boolean
384+
*
385+
* @param newStatus
386+
* enable status
387+
* @throws IOException
388+
* the io exception
389+
*/
390+
public void enableOrganizationProjects(boolean newStatus) throws IOException {
391+
edit("has_organization_projects", newStatus);
392+
}
393+
394+
private void edit(String key, Object value) throws IOException {
395+
root.createRequest()
396+
.withUrlPath(String.format("/orgs/%s", login))
397+
.method("PATCH")
398+
.with(key, value)
399+
.fetchInto(this);
400+
}
401+
382402
/**
383403
* Returns the projects for this organization.
384404
*

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public void cleanUpTeam() throws IOException {
3030
team.delete();
3131
}
3232

33-
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).root.createRequest()
34-
.withUrlPath("/orgs/" + GITHUB_API_TEST_ORG)
35-
.method("PATCH")
36-
.with("has_organization_projects", true)
37-
.send();
33+
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
3834
}
3935

4036
@Test
@@ -246,7 +242,19 @@ public void testAreOrganizationProjectsEnabled() throws IOException {
246242
// Act
247243
boolean result = org.areOrganizationProjectsEnabled();
248244

249-
// Assert that projects are enabled
245+
// Assert
250246
assertThat(result, is(true));
251247
}
248+
249+
@Test
250+
public void testEnableOrganizationProjects() throws IOException {
251+
// Arrange
252+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
253+
254+
// Act
255+
org.enableOrganizationProjects(false);
256+
257+
// Assert
258+
assertThat(org.areOrganizationProjectsEnabled(), is(false));
259+
}
252260
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "[email protected]",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 17,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 2,
32+
"owned_private_repos": 2,
33+
"private_gists": 0,
34+
"disk_usage": 31,
35+
"collaborators": 0,
36+
"billing_email": "[email protected]",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"members_can_create_pages": true,
41+
"members_can_create_public_pages": true,
42+
"members_can_create_private_pages": true,
43+
"plan": {
44+
"name": "free",
45+
"space": 976562499,
46+
"private_repos": 10000,
47+
"filled_seats": 23,
48+
"seats": 3
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "[email protected]",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": false,
22+
"has_repository_projects": true,
23+
"public_repos": 17,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 2,
32+
"owned_private_repos": 2,
33+
"private_gists": 0,
34+
"disk_usage": 31,
35+
"collaborators": 0,
36+
"billing_email": "[email protected]",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"members_can_create_pages": true,
41+
"members_can_create_public_pages": true,
42+
"members_can_create_private_pages": true,
43+
"plan": {
44+
"name": "free",
45+
"space": 976562499,
46+
"private_repos": 10000,
47+
"filled_seats": 23,
48+
"seats": 3
49+
}
50+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "akashRindhe",
3+
"id": 14114123,
4+
"node_id": "MDQ6VXNlcjE0MTE0MTIz",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/14114123?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/akashRindhe",
8+
"html_url": "https://github.com/akashRindhe",
9+
"followers_url": "https://api.github.com/users/akashRindhe/followers",
10+
"following_url": "https://api.github.com/users/akashRindhe/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/akashRindhe/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/akashRindhe/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/akashRindhe/subscriptions",
14+
"organizations_url": "https://api.github.com/users/akashRindhe/orgs",
15+
"repos_url": "https://api.github.com/users/akashRindhe/repos",
16+
"events_url": "https://api.github.com/users/akashRindhe/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/akashRindhe/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Akash Rindhe",
21+
"company": null,
22+
"blog": "",
23+
"location": "Singapore",
24+
"email": null,
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 9,
29+
"public_gists": 0,
30+
"followers": 0,
31+
"following": 6,
32+
"created_at": "2015-09-03T18:07:43Z",
33+
"updated_at": "2021-05-12T08:30:12Z",
34+
"private_gists": 0,
35+
"total_private_repos": 4,
36+
"owned_private_repos": 4,
37+
"disk_usage": 24551,
38+
"collaborators": 1,
39+
"two_factor_authentication": true,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "47c14d2c-d8d5-4f11-8208-fb790e6fccca",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "orgs_hub4j-test-org-2.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 13 May 2021 16:07:24 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"43be1c5d1d3fa4718ddcd58ebd6be4a41f81ddb5c2102d6ddd628548059db30d\"",
26+
"Last-Modified": "Thu, 04 Jun 2020 05:56:10 GMT",
27+
"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",
28+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4966",
32+
"X-RateLimit-Reset": "1620924638",
33+
"X-RateLimit-Used": "34",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "834A:6C69:7FCEDB:8CA6DB:609D4EBC"
42+
}
43+
},
44+
"uuid": "47c14d2c-d8d5-4f11-8208-fb790e6fccca",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"id": "eb95bb02-84c4-4e04-bfd4-851985556513",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org",
6+
"method": "POST",
7+
"headers": {
8+
"X-HTTP-Method-Override": {
9+
"equalTo": "PATCH"
10+
},
11+
"Accept": {
12+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
13+
}
14+
},
15+
"bodyPatterns": [
16+
{
17+
"equalToJson": "{\"has_organization_projects\":false}",
18+
"ignoreArrayOrder": true,
19+
"ignoreExtraElements": false
20+
}
21+
]
22+
},
23+
"response": {
24+
"status": 200,
25+
"bodyFileName": "orgs_hub4j-test-org-3.json",
26+
"headers": {
27+
"Server": "GitHub.com",
28+
"Date": "Thu, 13 May 2021 16:07:25 GMT",
29+
"Content-Type": "application/json; charset=utf-8",
30+
"Cache-Control": "private, max-age=60, s-maxage=60",
31+
"Vary": [
32+
"Accept, Authorization, Cookie, X-GitHub-OTP",
33+
"Accept-Encoding, Accept, X-Requested-With"
34+
],
35+
"ETag": "W/\"5ec2678c3553042c50562ea4033d38b2719d9a5b624a7d95dfcef66108c719f5\"",
36+
"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",
37+
"X-Accepted-OAuth-Scopes": "admin:org, repo",
38+
"X-GitHub-Media-Type": "unknown, github.v3",
39+
"X-RateLimit-Limit": "5000",
40+
"X-RateLimit-Remaining": "4965",
41+
"X-RateLimit-Reset": "1620924638",
42+
"X-RateLimit-Used": "35",
43+
"X-RateLimit-Resource": "core",
44+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
45+
"X-Frame-Options": "deny",
46+
"X-Content-Type-Options": "nosniff",
47+
"X-XSS-Protection": "0",
48+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
49+
"Content-Security-Policy": "default-src 'none'",
50+
"X-GitHub-Request-Id": "834A:6C69:7FCEED:8CA6EE:609D4EBC"
51+
}
52+
},
53+
"uuid": "eb95bb02-84c4-4e04-bfd4-851985556513",
54+
"persistent": true,
55+
"insertionIndex": 3
56+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "b9ae2ae4-ec5c-425c-9144-5863690aabf5",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "user-1.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 13 May 2021 16:07:22 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"848579fd41f059ee3a1a46f41bea53042fd2303af9d8670074420dc05bcfbd73\"",
26+
"Last-Modified": "Wed, 12 May 2021 08:30:12 GMT",
27+
"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",
28+
"X-Accepted-OAuth-Scopes": "",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4971",
32+
"X-RateLimit-Reset": "1620924638",
33+
"X-RateLimit-Used": "29",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "834A:6C69:7FCE81:8CA67D:609D4EB9"
42+
}
43+
},
44+
"uuid": "b9ae2ae4-ec5c-425c-9144-5863690aabf5",
45+
"persistent": true,
46+
"insertionIndex": 1
47+
}

0 commit comments

Comments
 (0)