Skip to content

Commit

Permalink
Merge remote-tracking branch 'github-api/master' into impsort
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Nov 19, 2019
2 parents a8dbe65 + d2ce7c1 commit d44cd4a
Show file tree
Hide file tree
Showing 9 changed files with 586 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonMappingException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.Objects;

import static org.kohsuke.github.Previews.*;

Expand All @@ -28,6 +30,12 @@ public class GHBranch {
private boolean protection;
private String protection_url;

@JsonCreator
GHBranch(@JsonProperty(value = "name", required = true) String name) throws Exception {
Objects.requireNonNull(name);
this.name = name;
}

/**
* The type Commit.
*/
Expand Down
26 changes: 24 additions & 2 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.kohsuke.github;

import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.*;

/**
Expand Down Expand Up @@ -48,6 +49,27 @@ public void getBranch_URLEncoded() throws Exception {
assertThat(branch.getName(), is("test/#UrlEncode"));
}

// Issue #607
@Test
public void getBranchNonExistentBut200Status() throws Exception {
// Manually changed the returned status to 200 so dont take a new snapshot
this.snapshotNotAllowed();

// This should *never* happen but with mocking it was discovered
GHRepository repo = getRepository();
try {
GHBranch branch = repo.getBranch("test/NonExistent");
fail();
} catch (Exception e) {
// I dont really love this but I wanted to get to the root wrapped cause
assertThat(e, instanceOf(IOException.class));
assertThat(e.getMessage(),
equalTo("Server returned HTTP response code: 200, message: 'OK' for URL: "
+ mockGitHub.apiServer().baseUrl()
+ "/repos/github-api-test-org/github-api/branches/test%2FNonExistent"));
}
}

@Test
public void subscription() throws Exception {
GHRepository r = getRepository();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 10,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization"
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"login": "alexanderrtaylor",
"id": 852179,
"node_id": "MDQ6VXNlcjg1MjE3OQ==",
"avatar_url": "https://avatars0.githubusercontent.com/u/852179?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexanderrtaylor",
"html_url": "https://github.com/alexanderrtaylor",
"followers_url": "https://api.github.com/users/alexanderrtaylor/followers",
"following_url": "https://api.github.com/users/alexanderrtaylor/following{/other_user}",
"gists_url": "https://api.github.com/users/alexanderrtaylor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexanderrtaylor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexanderrtaylor/subscriptions",
"organizations_url": "https://api.github.com/users/alexanderrtaylor/orgs",
"repos_url": "https://api.github.com/users/alexanderrtaylor/repos",
"events_url": "https://api.github.com/users/alexanderrtaylor/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexanderrtaylor/received_events",
"type": "User",
"site_admin": false,
"name": "Alex Taylor",
"company": "Cloudbees",
"blog": "",
"location": null,
"email": null,
"hireable": null,
"bio": null,
"public_repos": 39,
"public_gists": 1,
"followers": 5,
"following": 0,
"created_at": "2011-06-15T16:35:58Z",
"updated_at": "2019-07-23T14:01:42Z",
"private_gists": 1,
"total_private_repos": 13,
"owned_private_repos": 0,
"disk_usage": 265,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "cadf65cc-4434-4d3a-b4cf-4b1b79272f46",
"name": "orgs_github-api-test-org",
"request": {
"url": "/orgs/github-api-test-org",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "orgs_github-api-test-org-cadf65cc-4434-4d3a-b4cf-4b1b79272f46.json",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 13 Nov 2019 19:55:40 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4976",
"X-RateLimit-Reset": "1573678486",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "W/\"46db056d052e79900ccf2bffefb0e863\"",
"Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
"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": "F3E5:680D:1B5AF:4044E:5DCC5FBB"
}
},
"uuid": "cadf65cc-4434-4d3a-b4cf-4b1b79272f46",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "228f0322-215d-487e-9132-17bc4c3bf020",
"name": "repos_github-api-test-org_github-api",
"request": {
"url": "/repos/github-api-test-org/github-api",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "repos_github-api-test-org_github-api-228f0322-215d-487e-9132-17bc4c3bf020.json",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 13 Nov 2019 19:55:40 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4975",
"X-RateLimit-Reset": "1573678486",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "W/\"30a14752ec6a3eede9a30843cc286a50\"",
"Last-Modified": "Thu, 07 Nov 2019 22:27:11 GMT",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"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": "F3E5:680D:1B5B8:4048B:5DCC5FBC"
}
},
"uuid": "228f0322-215d-487e-9132-17bc4c3bf020",
"persistent": true,
"insertionIndex": 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"id": "b14df6ec-ff32-4838-8b38-934766abd880",
"name": "repos_github-api-test-org_github-api_branches_test_nonexistent",
"request": {
"url": "/repos/github-api-test-org/github-api/branches/test%2FNonExistent",
"method": "GET"
},
"response": {
"status": 200,
"body": "{\"message\":\"Branch not found\",\"documentation_url\":\"https://developer.github.com/v3/repos/branches/#get-branch\"}",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 13 Nov 2019 19:55:40 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "404 Not Found",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4974",
"X-RateLimit-Reset": "1573678486",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"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": "F3E5:680D:1B5C1:4049C:5DCC5FBC"
}
},
"uuid": "b14df6ec-ff32-4838-8b38-934766abd880",
"persistent": true,
"insertionIndex": 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "87afc711-0c63-4cc6-96b5-26eb391105de",
"name": "user",
"request": {
"url": "/user",
"method": "GET"
},
"response": {
"status": 200,
"bodyFileName": "user-87afc711-0c63-4cc6-96b5-26eb391105de.json",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 13 Nov 2019 19:55:39 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4978",
"X-RateLimit-Reset": "1573678486",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "W/\"38c5719328738c2ec6c612f367ae1b59\"",
"Last-Modified": "Tue, 23 Jul 2019 14:01:42 GMT",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"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": "F3E5:680D:1B592:40447:5DCC5FBB"
}
},
"uuid": "87afc711-0c63-4cc6-96b5-26eb391105de",
"persistent": true,
"insertionIndex": 1
}

0 comments on commit d44cd4a

Please sign in to comment.