Skip to content

Commit 66de069

Browse files
authored
Merge pull request hub4j#696 from nobe0716/feature/delete_branch_automatically
Add automatic deletion of branches that merged by PR
2 parents 5ac65aa + 713dd62 commit 66de069

22 files changed

Lines changed: 2688 additions & 0 deletions

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class GHRepository extends GHObject {
8080
private boolean allow_merge_commit;
8181
private boolean allow_rebase_merge;
8282

83+
private boolean delete_branch_on_merge;
84+
8385
@JsonProperty("private")
8486
private boolean _private;
8587
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
@@ -605,6 +607,15 @@ public boolean isAllowRebaseMerge() {
605607
return allow_rebase_merge;
606608
}
607609

610+
/**
611+
* Automatically deleting head branches when pull requests are merged
612+
*
613+
* @return the boolean
614+
*/
615+
public boolean isDeleteBranchOnMerge() {
616+
return delete_branch_on_merge;
617+
}
618+
608619
/**
609620
* Returns the number of all forks of this repository. This not only counts direct forks, but also forks of forks,
610621
* and so on.
@@ -1089,6 +1100,18 @@ public void allowRebaseMerge(boolean value) throws IOException {
10891100
edit("allow_rebase_merge", Boolean.toString(value));
10901101
}
10911102

1103+
/**
1104+
* After pull requests are merged, you can have head branches deleted automatically.
1105+
*
1106+
* @param value
1107+
* the value
1108+
* @throws IOException
1109+
* the io exception
1110+
*/
1111+
public void deleteBranchOnMerge(boolean value) throws IOException {
1112+
edit("delete_branch_on_merge", Boolean.toString(value));
1113+
}
1114+
10921115
/**
10931116
* Deletes this repository.
10941117
*

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,29 @@ public void setMergeOptions() throws IOException {
309309
assertFalse(r.isAllowSquashMerge());
310310
}
311311

312+
@Test
313+
public void getDeleteBranchOnMerge() throws IOException {
314+
GHRepository r = getRepository();
315+
assertNotNull(r.isDeleteBranchOnMerge());
316+
}
317+
318+
@Test
319+
public void setDeleteBranchOnMerge() throws IOException {
320+
GHRepository r = getRepository();
321+
322+
// enable auto delete
323+
r.deleteBranchOnMerge(true);
324+
325+
r = gitHub.getRepository(r.getFullName());
326+
assertTrue(r.isDeleteBranchOnMerge());
327+
328+
// flip the last value
329+
r.deleteBranchOnMerge(false);
330+
331+
r = gitHub.getRepository(r.getFullName());
332+
assertFalse(r.isDeleteBranchOnMerge());
333+
}
334+
312335
@Test
313336
public void testSetTopics() throws Exception {
314337
GHRepository repo = getRepository(gitHub);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 11,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization"
25+
}

src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/getDeleteBranchOnMerge/__files/repos_github-api-test-org_github-api-99deb429-da7c-4f6c-9d82-b7e637586210.json

Lines changed: 328 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "nobe0716",
3+
"id": 5964919,
4+
"node_id": "MDQ6VXNlcjU5NjQ5MTk=",
5+
"avatar_url": "https://avatars0.githubusercontent.com/u/5964919?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/nobe0716",
8+
"html_url": "https://github.com/nobe0716",
9+
"followers_url": "https://api.github.com/users/nobe0716/followers",
10+
"following_url": "https://api.github.com/users/nobe0716/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/nobe0716/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/nobe0716/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/nobe0716/subscriptions",
14+
"organizations_url": "https://api.github.com/users/nobe0716/orgs",
15+
"repos_url": "https://api.github.com/users/nobe0716/repos",
16+
"events_url": "https://api.github.com/users/nobe0716/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/nobe0716/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Noah J.",
21+
"company": "Naver",
22+
"blog": "https://nobe0716.github.io/",
23+
"location": "South Korea",
24+
"email": null,
25+
"hireable": null,
26+
"bio": "Software Engineer \\\r\n\r\nRecommendation Platform",
27+
"public_repos": 10,
28+
"public_gists": 3,
29+
"followers": 3,
30+
"following": 3,
31+
"created_at": "2013-11-18T03:01:22Z",
32+
"updated_at": "2020-02-13T16:27:32Z",
33+
"private_gists": 1,
34+
"total_private_repos": 0,
35+
"owned_private_repos": 0,
36+
"disk_usage": 833,
37+
"collaborators": 0,
38+
"two_factor_authentication": false,
39+
"plan": {
40+
"name": "free",
41+
"space": 976562499,
42+
"collaborators": 0,
43+
"private_repos": 10000
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "94de530c-025f-4dae-b829-8a7b7ea73c4b",
3+
"name": "orgs_github-api-test-org",
4+
"request": {
5+
"url": "/orgs/github-api-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_github-api-test-org-94de530c-025f-4dae-b829-8a7b7ea73c4b.json",
16+
"headers": {
17+
"Date": "Mon, 17 Feb 2020 09:43:18 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4232",
23+
"X-RateLimit-Reset": "1581934415",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"e7c7cb36e47554d75f93855cf5c90046\"",
30+
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
31+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages",
32+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "1EF4:3DA9:D624B:1255A1:5E4A6035"
43+
}
44+
},
45+
"uuid": "94de530c-025f-4dae-b829-8a7b7ea73c4b",
46+
"persistent": true,
47+
"insertionIndex": 2
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "99deb429-da7c-4f6c-9d82-b7e637586210",
3+
"name": "repos_github-api-test-org_github-api",
4+
"request": {
5+
"url": "/repos/github-api-test-org/github-api",
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": "repos_github-api-test-org_github-api-99deb429-da7c-4f6c-9d82-b7e637586210.json",
16+
"headers": {
17+
"Date": "Mon, 17 Feb 2020 09:43:18 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4231",
23+
"X-RateLimit-Reset": "1581934416",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"640184c01e642ec2bae0a7caa1722f3c\"",
30+
"Last-Modified": "Thu, 16 Jan 2020 21:22:56 GMT",
31+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages",
32+
"X-Accepted-OAuth-Scopes": "repo",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "1EF4:3DA9:D624C:1255A2:5E4A6036"
43+
}
44+
},
45+
"uuid": "99deb429-da7c-4f6c-9d82-b7e637586210",
46+
"persistent": true,
47+
"insertionIndex": 3
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"id": "98b2b906-bc8f-4f1c-9077-87f686c19718",
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-98b2b906-bc8f-4f1c-9077-87f686c19718.json",
16+
"headers": {
17+
"Date": "Thu, 13 Feb 2020 16:28:33 GMT",
18+
"Content-Type": "application/json; charset=utf-8",
19+
"Server": "GitHub.com",
20+
"Status": "200 OK",
21+
"X-RateLimit-Limit": "5000",
22+
"X-RateLimit-Remaining": "4868",
23+
"X-RateLimit-Reset": "1581614535",
24+
"Cache-Control": "private, max-age=60, s-maxage=60",
25+
"Vary": [
26+
"Accept, Authorization, Cookie, X-GitHub-OTP",
27+
"Accept-Encoding, Accept, X-Requested-With"
28+
],
29+
"ETag": "W/\"cb9e78930d7aef9b591b0da528f352cb\"",
30+
"Last-Modified": "Thu, 13 Feb 2020 16:27:32 GMT",
31+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages",
32+
"X-Accepted-OAuth-Scopes": "",
33+
"X-GitHub-Media-Type": "unknown, github.v3",
34+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
35+
"Access-Control-Allow-Origin": "*",
36+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
37+
"X-Frame-Options": "deny",
38+
"X-Content-Type-Options": "nosniff",
39+
"X-XSS-Protection": "1; mode=block",
40+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
41+
"Content-Security-Policy": "default-src 'none'",
42+
"X-GitHub-Request-Id": "F579:449D:14F0E1:1B6DD1:5E457931"
43+
}
44+
},
45+
"uuid": "98b2b906-bc8f-4f1c-9077-87f686c19718",
46+
"persistent": true,
47+
"insertionIndex": 1
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 11,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 147,
29+
"collaborators": 0,
30+
"billing_email": "kk@kohsuke.org",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 13,
39+
"seats": 0
40+
}
41+
}

0 commit comments

Comments
 (0)