Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change withURLPath to setRawURLPath #770

Merged
merged 9 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public URL getProtectionUrl() {
* the io exception
*/
public GHBranchProtection getProtection() throws IOException {
return root.createRequest().withUrlPath(protection_url).fetch(GHBranchProtection.class).wrap(this);
return root.createRequest().setRawUrlPath(protection_url).fetch(GHBranchProtection.class).wrap(this);
}

/**
Expand All @@ -120,7 +120,7 @@ public String getSHA1() {
* if disabling protection fails
*/
public void disableProtection() throws IOException {
root.createRequest().method("DELETE").withUrlPath(protection_url).send();
root.createRequest().method("DELETE").setRawUrlPath(protection_url).send();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitwiseman protection_url is a full url http://localhost:36413/repos/github-api-test-org/temp-testDisableProtectionOnly/branches/master/protection, so I changed it , is this similar to what you have in mind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add the wire mock snapshot soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the kind of change that I'm looking for.

}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/kohsuke/github/GHBranchProtectionTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public void testEnableProtectionOnly() throws Exception {
assertTrue(repo.getBranch(BRANCH).isProtected());
}

@Test
public void testDisableProtectionOnly() throws Exception {
GHBranchProtection protection = branch.enableProtection().enable();
assertTrue(repo.getBranch(BRANCH).isProtected());
branch.disableProtection();
assertFalse(repo.getBranch(BRANCH).isProtected());
}

@Test
public void testEnableRequireReviewsOnly() throws Exception {
GHBranchProtection protection = branch.enableProtection().requireReviews().enable();
Expand All @@ -73,4 +81,12 @@ public void testSignedCommits() throws Exception {
protection.disableSignedCommits();
assertFalse(protection.getRequiredSignatures());
}

@Test
public void testGetProtection() throws Exception {
GHBranchProtection protection = branch.enableProtection().enable();
GHBranchProtection protectionTest = repo.getBranch(BRANCH).getProtection();
assertTrue(protectionTest instanceof GHBranchProtection);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though the above branch master is already protected it still throws a message that the branch is not protected. It seems a bit strange

 "body": "{\"message\":\"Branch not protected\",\"documentation_url\":\"https://developer.github.com/v3/repos/branches/#remove-branch-protection\"}",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub doesn't think it is protected. The data files definitely show that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any solution ? Because manually changing doesn't seem to work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sladyn98
Not sure. I'll take a look.

assertTrue(repo.getBranch(BRANCH).isProtected());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"id": 258288342,
"node_id": "MDEwOlJlcG9zaXRvcnkyNTgyODgzNDI=",
"name": "temp-testDisableProtectionOnly",
"full_name": "github-api-test-org/temp-testDisableProtectionOnly",
"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/temp-testDisableProtectionOnly",
"description": "A test repository for testing the github-api project: temp-testDisableProtectionOnly",
"fork": false,
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly",
"forks_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/forks",
"keys_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/teams",
"hooks_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/hooks",
"issue_events_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/issues/events{/number}",
"events_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/events",
"assignees_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/assignees{/user}",
"branches_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/branches{/branch}",
"tags_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/tags",
"blobs_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/statuses/{sha}",
"languages_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/languages",
"stargazers_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/stargazers",
"contributors_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/contributors",
"subscribers_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/subscribers",
"subscription_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/subscription",
"commits_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/contents/{+path}",
"compare_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/merges",
"archive_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/downloads",
"issues_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/issues{/number}",
"pulls_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/pulls{/number}",
"milestones_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/milestones{/number}",
"notifications_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/labels{/name}",
"releases_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/releases{/id}",
"deployments_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/deployments",
"created_at": "2020-04-23T17:59:02Z",
"updated_at": "2020-04-23T17:59:06Z",
"pushed_at": "2020-04-23T17:59:04Z",
"git_url": "git://github.com/github-api-test-org/temp-testDisableProtectionOnly.git",
"ssh_url": "[email protected]:github-api-test-org/temp-testDisableProtectionOnly.git",
"clone_url": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly.git",
"svn_url": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly",
"homepage": "http://github-api.kohsuke.org/",
"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
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"delete_branch_on_merge": false,
"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": 8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "master",
"commit": {
"sha": "dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"node_id": "MDY6Q29tbWl0MjU4Mjg4MzQyOmRkOGNlMjUwMzRlODU5NzNhOGNmYWNiMWIzNzk1NzFlYTNiNGE4YTY=",
"commit": {
"author": {
"name": "Liam Newman",
"email": "[email protected]",
"date": "2020-04-23T17:59:03Z"
},
"committer": {
"name": "GitHub",
"email": "[email protected]",
"date": "2020-04-23T17:59:03Z"
},
"message": "Initial commit",
"tree": {
"sha": "e0f408fb90498b93fb29f15f65a716d635b935aa",
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/trees/e0f408fb90498b93fb29f15f65a716d635b935aa"
},
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJeoddnCRBK7hj4Ov3rIwAAdHIIAIv1r34nroEHWPNwCvI3P/A7\ng3nDhupwv9OerOc+bvMeovLfsKIkpiHmz3qESI2ei5XL6ZNPffbhe1w7GG8ISF5g\ncJLQ84D+qk/rcOni3PJZj2n/3ChB+//lid6Op2O6TUuZ1omoxIeNzurIUJ7H0gux\nUB0siDrXMc5XXZw5kGQBWwVbc0HVB6lyxQ6s1Ct8w3KgcEGkxv97QsAVR7SvKir2\naI/uu0TB61KnsKh5igvGyT5i+a+fgMXsyV9i/qGSCvoueehSRa5XUHWD8hyDJOBG\nXwOzn696UNyl+0xZo/zHq2fyTeJY8siEyASpAh4KQkGbSHYNakLu+vxzwBB9U28=\n=3X5V\n-----END PGP SIGNATURE-----\n",
"payload": "tree e0f408fb90498b93fb29f15f65a716d635b935aa\nauthor Liam Newman <[email protected]> 1587664743 -0700\ncommitter GitHub <[email protected]> 1587664743 -0700\n\nInitial commit"
}
},
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"html_url": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly/commit/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"comments_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6/comments",
"author": {
"login": "bitwiseman",
"id": 1958953,
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitwiseman",
"html_url": "https://github.com/bitwiseman",
"followers_url": "https://api.github.com/users/bitwiseman/followers",
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
"repos_url": "https://api.github.com/users/bitwiseman/repos",
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "web-flow",
"id": 19864447,
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
"avatar_url": "https://avatars3.githubusercontent.com/u/19864447?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/web-flow",
"html_url": "https://github.com/web-flow",
"followers_url": "https://api.github.com/users/web-flow/followers",
"following_url": "https://api.github.com/users/web-flow/following{/other_user}",
"gists_url": "https://api.github.com/users/web-flow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/web-flow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/web-flow/subscriptions",
"organizations_url": "https://api.github.com/users/web-flow/orgs",
"repos_url": "https://api.github.com/users/web-flow/repos",
"events_url": "https://api.github.com/users/web-flow/events{/privacy}",
"received_events_url": "https://api.github.com/users/web-flow/received_events",
"type": "User",
"site_admin": false
},
"parents": []
},
"_links": {
"self": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/branches/master",
"html": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly/tree/master"
},
"protected": false,
"protection": {
"enabled": false,
"required_status_checks": {
"enforcement_level": "off",
"contexts": []
}
},
"protection_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/branches/master/protection"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"name": "master",
"commit": {
"sha": "dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"node_id": "MDY6Q29tbWl0MjU4Mjg4MzQyOmRkOGNlMjUwMzRlODU5NzNhOGNmYWNiMWIzNzk1NzFlYTNiNGE4YTY=",
"commit": {
"author": {
"name": "Liam Newman",
"email": "[email protected]",
"date": "2020-04-23T17:59:03Z"
},
"committer": {
"name": "GitHub",
"email": "[email protected]",
"date": "2020-04-23T17:59:03Z"
},
"message": "Initial commit",
"tree": {
"sha": "e0f408fb90498b93fb29f15f65a716d635b935aa",
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/trees/e0f408fb90498b93fb29f15f65a716d635b935aa"
},
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/git/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJeoddnCRBK7hj4Ov3rIwAAdHIIAIv1r34nroEHWPNwCvI3P/A7\ng3nDhupwv9OerOc+bvMeovLfsKIkpiHmz3qESI2ei5XL6ZNPffbhe1w7GG8ISF5g\ncJLQ84D+qk/rcOni3PJZj2n/3ChB+//lid6Op2O6TUuZ1omoxIeNzurIUJ7H0gux\nUB0siDrXMc5XXZw5kGQBWwVbc0HVB6lyxQ6s1Ct8w3KgcEGkxv97QsAVR7SvKir2\naI/uu0TB61KnsKh5igvGyT5i+a+fgMXsyV9i/qGSCvoueehSRa5XUHWD8hyDJOBG\nXwOzn696UNyl+0xZo/zHq2fyTeJY8siEyASpAh4KQkGbSHYNakLu+vxzwBB9U28=\n=3X5V\n-----END PGP SIGNATURE-----\n",
"payload": "tree e0f408fb90498b93fb29f15f65a716d635b935aa\nauthor Liam Newman <[email protected]> 1587664743 -0700\ncommitter GitHub <[email protected]> 1587664743 -0700\n\nInitial commit"
}
},
"url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"html_url": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly/commit/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6",
"comments_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/commits/dd8ce25034e85973a8cfacb1b379571ea3b4a8a6/comments",
"author": {
"login": "bitwiseman",
"id": 1958953,
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitwiseman",
"html_url": "https://github.com/bitwiseman",
"followers_url": "https://api.github.com/users/bitwiseman/followers",
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
"repos_url": "https://api.github.com/users/bitwiseman/repos",
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "web-flow",
"id": 19864447,
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
"avatar_url": "https://avatars3.githubusercontent.com/u/19864447?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/web-flow",
"html_url": "https://github.com/web-flow",
"followers_url": "https://api.github.com/users/web-flow/followers",
"following_url": "https://api.github.com/users/web-flow/following{/other_user}",
"gists_url": "https://api.github.com/users/web-flow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/web-flow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/web-flow/subscriptions",
"organizations_url": "https://api.github.com/users/web-flow/orgs",
"repos_url": "https://api.github.com/users/web-flow/repos",
"events_url": "https://api.github.com/users/web-flow/events{/privacy}",
"received_events_url": "https://api.github.com/users/web-flow/received_events",
"type": "User",
"site_admin": false
},
"parents": []
},
"_links": {
"self": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/branches/master",
"html": "https://github.com/github-api-test-org/temp-testDisableProtectionOnly/tree/master"
},
"protected": true,
"protection": {
"enabled": true,
"required_status_checks": {
"enforcement_level": "off",
"contexts": []
}
},
"protection_url": "https://api.github.com/repos/github-api-test-org/temp-testDisableProtectionOnly/branches/master/protection"
}
Loading