Skip to content

Commit

Permalink
Merge pull request #567 from jberglund-BSFT/master
Browse files Browse the repository at this point in the history
Add merge options to GHRepository
  • Loading branch information
bitwiseman authored Oct 9, 2019
2 parents ce97eb5 + 3c739d8 commit 5990f5a
Show file tree
Hide file tree
Showing 26 changed files with 1,951 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public class GHRepository extends GHObject {
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
private GHUser owner; // not fully populated. beware.
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived;

private boolean allow_squash_merge;
private boolean allow_merge_commit;
private boolean allow_rebase_merge;

@JsonProperty("private")
private boolean _private;
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
Expand Down Expand Up @@ -405,6 +410,18 @@ public boolean isFork() {
public boolean isArchived() {
return archived;
}

public boolean isAllowSquashMerge() {
return allow_squash_merge;
}

public boolean isAllowMergeCommit() {
return allow_merge_commit;
}

public boolean isAllowRebaseMerge() {
return allow_rebase_merge;
}

/**
* Returns the number of all forks of this repository.
Expand Down Expand Up @@ -631,7 +648,19 @@ public void setDefaultBranch(String value) throws IOException {
public void setPrivate(boolean value) throws IOException {
edit("private", Boolean.toString(value));
}


public void allowSquashMerge(boolean value) throws IOException {
edit("allow_squash_merge", Boolean.toString(value));
}

public void allowMergeCommit(boolean value) throws IOException {
edit("allow_merge_commit", Boolean.toString(value));
}

public void allowRebaseMerge(boolean value) throws IOException {
edit("allow_rebase_merge", Boolean.toString(value));
}

/**
* Deletes this repository.
*/
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,43 @@ public void markDown() throws Exception {
assertTrue(actual.contains("class=\"issue-link "));
assertTrue(actual.contains("to fix issue"));
}

@Test
public void getMergeOptions() throws IOException {
GHRepository r = gitHub.getRepository("github-api-test-org/test-mergeoptions");
assertNotNull(r.isAllowMergeCommit());
assertNotNull(r.isAllowRebaseMerge());
assertNotNull(r.isAllowSquashMerge());
}

@Test
public void setMergeOptions() throws IOException {
String repoName = "github-api-test-org/test-mergeoptions";
GHRepository r = gitHub.getRepository(repoName);

// at least one merge option must be selected
// flip all the values at least once
r.allowMergeCommit(false);
r.allowRebaseMerge(false);
r.allowSquashMerge(true);

r = gitHub.getRepository(repoName);
assertFalse(r.isAllowMergeCommit());
assertFalse(r.isAllowRebaseMerge());
assertTrue(r.isAllowSquashMerge());

// flip the last value
r.allowMergeCommit(true);
r.allowRebaseMerge(true);
r.allowSquashMerge(false);

r = gitHub.getRepository(repoName);
assertTrue(r.isAllowMergeCommit());
assertTrue(r.isAllowRebaseMerge());
assertFalse(r.isAllowSquashMerge());

// no need to reset the values
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"id": 213687745,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTM2ODc3NDU=",
"name": "test-mergeoptions",
"full_name": "github-api-test-org/test-mergeoptions",
"private": false,
"owner": {
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api-test-org",
"html_url": "https://github.com/github-api-test-org",
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/github-api-test-org/test-mergeoptions",
"description": "GHRepositoryTest.setMergeOptions() fixture",
"fork": false,
"url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions",
"forks_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/forks",
"keys_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/teams",
"hooks_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/hooks",
"issue_events_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/issues/events{/number}",
"events_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/events",
"assignees_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/assignees{/user}",
"branches_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/branches{/branch}",
"tags_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/tags",
"blobs_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/statuses/{sha}",
"languages_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/languages",
"stargazers_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/stargazers",
"contributors_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/contributors",
"subscribers_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/subscribers",
"subscription_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/subscription",
"commits_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/contents/{+path}",
"compare_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/merges",
"archive_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/downloads",
"issues_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/issues{/number}",
"pulls_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/pulls{/number}",
"milestones_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/milestones{/number}",
"notifications_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/labels{/name}",
"releases_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/releases{/id}",
"deployments_url": "https://api.github.com/repos/github-api-test-org/test-mergeoptions/deployments",
"created_at": "2019-10-08T15:53:14Z",
"updated_at": "2019-10-08T15:53:14Z",
"pushed_at": "2019-10-08T15:53:14Z",
"git_url": "git://github.com/github-api-test-org/test-mergeoptions.git",
"ssh_url": "[email protected]:github-api-test-org/test-mergeoptions.git",
"clone_url": "https://github.com/github-api-test-org/test-mergeoptions.git",
"svn_url": "https://github.com/github-api-test-org/test-mergeoptions",
"homepage": null,
"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,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"organization": {
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api-test-org",
"html_url": "https://github.com/github-api-test-org",
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"network_count": 0,
"subscribers_count": 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"login": "jberglund-BSFT",
"id": 19560713,
"node_id": "MDQ6VXNlcjE5NTYwNzEz",
"avatar_url": "https://avatars3.githubusercontent.com/u/19560713?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jberglund-BSFT",
"html_url": "https://github.com/jberglund-BSFT",
"followers_url": "https://api.github.com/users/jberglund-BSFT/followers",
"following_url": "https://api.github.com/users/jberglund-BSFT/following{/other_user}",
"gists_url": "https://api.github.com/users/jberglund-BSFT/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jberglund-BSFT/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jberglund-BSFT/subscriptions",
"organizations_url": "https://api.github.com/users/jberglund-BSFT/orgs",
"repos_url": "https://api.github.com/users/jberglund-BSFT/repos",
"events_url": "https://api.github.com/users/jberglund-BSFT/events{/privacy}",
"received_events_url": "https://api.github.com/users/jberglund-BSFT/received_events",
"type": "User",
"site_admin": false,
"name": "Joey Berglund",
"company": "Broadsoft",
"blog": "www.broadsoft.com",
"location": "Richardson, TX",
"email": null,
"hireable": null,
"bio": null,
"public_repos": 7,
"public_gists": 0,
"followers": 1,
"following": 0,
"created_at": "2016-05-24T22:21:22Z",
"updated_at": "2019-08-05T15:08:10Z",
"private_gists": 0,
"total_private_repos": 0,
"owned_private_repos": 0,
"disk_usage": 0,
"collaborators": 0,
"two_factor_authentication": false,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "bd0d3859-e45e-45eb-8b5d-362a325fe5a6",
"name": "repos_github-api-test-org_test-mergeoptions",
"request": {
"url": "/repos/github-api-test-org/test-mergeoptions",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "repos_github-api-test-org_test-mergeoptions-bd0d3859-e45e-45eb-8b5d-362a325fe5a6.json",
"headers": {
"Date": "Tue, 08 Oct 2019 16:05:32 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4993",
"X-RateLimit-Reset": "1570554322",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding"
],
"ETag": "W/\"bc67de8fb9554a459188fac7692140dc\"",
"Last-Modified": "Tue, 08 Oct 2019 15:53:14 GMT",
"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",
"X-Accepted-OAuth-Scopes": "repo",
"X-GitHub-Media-Type": "unknown, github.v3",
"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",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "475C:474C:74D678:CBCD73:5D9CB3C4"
}
},
"uuid": "bd0d3859-e45e-45eb-8b5d-362a325fe5a6",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"id": "fa21aff1-992c-421c-af40-afdbce06db9c",
"name": "user",
"request": {
"url": "/user",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "user-fa21aff1-992c-421c-af40-afdbce06db9c.json",
"headers": {
"Date": "Tue, 08 Oct 2019 16:05:24 GMT",
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4995",
"X-RateLimit-Reset": "1570554322",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding"
],
"ETag": "W/\"a06eea6fc1dc3e447db0d26c9cd88717\"",
"Last-Modified": "Mon, 05 Aug 2019 15:08:10 GMT",
"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",
"X-Accepted-OAuth-Scopes": "",
"X-GitHub-Media-Type": "unknown, github.v3",
"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",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "475C:474C:74D66C:CBCD64:5D9CB3C4"
}
},
"uuid": "fa21aff1-992c-421c-af40-afdbce06db9c",
"persistent": true,
"insertionIndex": 1
}
Loading

0 comments on commit 5990f5a

Please sign in to comment.