Merge branch 'master' of https://github.com/kohsuke/github-api into marketplace_endpoints

This commit is contained in:
PauloMigAlmeida
2019-12-20 12:46:48 +13:00
20 changed files with 117 additions and 48 deletions

View File

@@ -12,6 +12,7 @@ import static org.kohsuke.github.Previews.MACHINE_MAN;
*
* @author Paulo Miguel Almeida
* @see GHAppInstallation#createToken(Map) GHAppInstallation#createToken(Map)
* @see GHAppInstallation#createToken() GHAppInstallation#createToken()
*/
public class GHAppCreateTokenBuilder {
private final GitHub root;
@@ -20,11 +21,17 @@ public class GHAppCreateTokenBuilder {
@Preview
@Deprecated
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = root.createRequest();
withPermissions(builder, permissions);
}
@Preview
@Deprecated
GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map<String, GHPermissionType> permissions) {
this(root, apiUrlTail);
permissions(permissions);
}
/**
@@ -43,6 +50,25 @@ public class GHAppCreateTokenBuilder {
return this;
}
/**
* Set the permissions granted to the access token. The permissions object includes the permission names and their
* access type.
*
* @param permissions
* Map containing the permission names and types.
* @return a GHAppCreateTokenBuilder
*/
@Preview
@Deprecated
public GHAppCreateTokenBuilder permissions(Map<String, GHPermissionType> permissions) {
Map<String, String> retMap = new HashMap<>();
for (Map.Entry<String, GHPermissionType> entry : permissions.entrySet()) {
retMap.put(entry.getKey(), Requester.transformEnum(entry.getValue()));
}
builder.with("permissions", retMap);
return this;
}
/**
* Creates an app token with all the parameters.
* <p>
@@ -62,12 +88,4 @@ public class GHAppCreateTokenBuilder {
.wrapUp(root);
}
private static Requester withPermissions(Requester builder, Map<String, GHPermissionType> value) {
Map<String, String> retMap = new HashMap<String, String>();
for (Map.Entry<String, GHPermissionType> entry : value.entrySet()) {
retMap.put(entry.getKey(), Requester.transformEnum(entry.getValue()));
}
return builder.with("permissions", retMap);
}
}

View File

@@ -287,11 +287,27 @@ public class GHAppInstallation extends GHObject {
*
* @param permissions
* map of permissions for the created token
* @return a GHAppCreateTokenBuilder on error
* @return a GHAppCreateTokenBuilder instance
* @deprecated Use {@link GHAppInstallation#createToken()} instead.
*/
@Preview
@Deprecated
public GHAppCreateTokenBuilder createToken(Map<String, GHPermissionType> permissions) {
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", id), permissions);
}
/**
* Starts a builder that creates a new App Installation Token.
*
* <p>
* You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} to
* finally create an access token.
*
* @return a GHAppCreateTokenBuilder instance
*/
@Preview
@Deprecated
public GHAppCreateTokenBuilder createToken() {
return new GHAppCreateTokenBuilder(root, String.format("/app/installations/%d/access_tokens", id));
}
}

View File

@@ -6,8 +6,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Objects;
import static org.kohsuke.github.Previews.SYMMETRA;
/**
* The type GHLabel.
*
@@ -51,8 +49,6 @@ public class GHLabel {
*
* @return the description
*/
@Preview
@Deprecated
public String getDescription() {
return description;
}
@@ -83,7 +79,6 @@ public class GHLabel {
public void setColor(String newColor) throws IOException {
repo.root.createRequest()
.method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", newColor)
.with("description", description)
@@ -99,12 +94,9 @@ public class GHLabel {
* @throws IOException
* the io exception
*/
@Preview
@Deprecated
public void setDescription(String newDescription) throws IOException {
repo.root.createRequest()
.method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", color)
.with("description", newDescription)

View File

@@ -1782,7 +1782,6 @@ public class GHRepository extends GHObject {
*/
public PagedIterable<GHLabel> listLabels() throws IOException {
return root.createRequest()
.withPreview(SYMMETRA)
.asPagedIterable(getApiTailUrl("labels"), GHLabel[].class, item -> item.wrapUp(GHRepository.this));
}
@@ -1796,11 +1795,7 @@ public class GHRepository extends GHObject {
* the io exception
*/
public GHLabel getLabel(String name) throws IOException {
return root.createRequest()
.withPreview(SYMMETRA)
.withUrlPath(getApiTailUrl("labels/" + name))
.fetch(GHLabel.class)
.wrapUp(this);
return root.createRequest().withUrlPath(getApiTailUrl("labels/" + name)).fetch(GHLabel.class).wrapUp(this);
}
/**
@@ -1831,12 +1826,9 @@ public class GHRepository extends GHObject {
* @throws IOException
* the io exception
*/
@Preview
@Deprecated
public GHLabel createLabel(String name, String color, String description) throws IOException {
return root.createRequest()
.method("POST")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", color)
.with("description", description)

View File

@@ -66,14 +66,6 @@ class Previews {
*/
static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview";
/**
* Label emoji, search, and descriptions
*
* @see <a href="https://developer.github.com/v3/previews/#label-emoji-search-and-descriptions">GitHub API
* Previews</a>
*/
static final String SYMMETRA = "application/vnd.github.symmetra-preview+json";
/**
* Require signed commits
*

View File

@@ -25,4 +25,8 @@ permissions.put("pull_requests", GHPermissionType.WRITE);
GHAppInstallationToken appInstallationToken = appInstallation
.createToken(permissions)
.create();
// Or
GHAppInstallationToken appInstallationToken = appInstallation.createToken().create();
+-----+

View File

@@ -4,6 +4,7 @@ import org.junit.Test;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -101,8 +102,9 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
permissions.put("contents", GHPermissionType.READ);
permissions.put("metadata", GHPermissionType.READ);
// Create token specifying both permissions and repository ids
GHAppInstallationToken installationToken = installation.createToken(permissions)
.repositoryIds(Arrays.asList((long) 111111111))
.repositoryIds(Collections.singletonList((long) 111111111))
.create();
assertThat(installationToken.getToken(), is("bogus"));
@@ -114,6 +116,16 @@ public class GHAppTest extends AbstractGitHubWireMockTest {
assertThat(installationToken.getRepositories().size(), is(1));
assertThat(repository.getId(), is((long) 111111111));
assertThat(repository.getName(), is("bogus"));
// Create token with no payload
GHAppInstallationToken installationToken2 = installation.createToken().create();
assertThat(installationToken2.getToken(), is("bogus"));
assertThat(installationToken2.getPermissions().size(), is(4));
assertThat(installationToken2.getRepositorySelection(), is(GHRepositorySelection.ALL));
assertThat(installationToken2.getExpiresAt(), is(GitHub.parseDate("2019-12-19T12:27:59Z")));
assertNull(installationToken2.getRepositories());;
}
private void testAppInstallation(GHAppInstallation appInstallation) throws IOException {

View File

@@ -11,6 +11,6 @@ public class GHObjectTest extends org.kohsuke.github.AbstractGitHubWireMockTest
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
assertThat(org.toString(),
containsString(
"login=github-api-test-org,location=<null>,blog=<null>,email=<null>,name=<null>,company=<null>,followers=0,following=0"));
"login=github-api-test-org,location=<null>,blog=<null>,email=<null>,name=<null>,company=<null>,type=Organization,followers=0,following=0"));
}
}

View File

@@ -32,7 +32,6 @@
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"X-Accepted-OAuth-Scopes": "",
"Location": "https://api.github.com/repos/github-api-test-org/test-labels/labels/test2",
"X-GitHub-Media-Type": "github.symmetra-preview; format=json",
"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",

View File

@@ -24,7 +24,6 @@
"ETag": "W/\"70c6bea1b42c9775915fdf6e8279aa26\"",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -32,7 +32,6 @@
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion",
"X-Accepted-OAuth-Scopes": "",
"Location": "https://api.github.com/repos/github-api-test-org/test-labels/labels/test",
"X-GitHub-Media-Type": "github.symmetra-preview; format=json",
"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",

View File

@@ -25,7 +25,6 @@
"Last-Modified": "Sun, 15 Feb 2015 14:49:10 GMT",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -25,7 +25,6 @@
"Last-Modified": "Sat, 05 Oct 2019 05:21:23 GMT",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -25,7 +25,6 @@
"Last-Modified": "Sat, 05 Oct 2019 05:21:23 GMT",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -31,7 +31,6 @@
"ETag": "W/\"b6be68c4a5dbc522147f58e4b1b1aed1\"",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -25,7 +25,6 @@
"Last-Modified": "Sat, 05 Oct 2019 05:21:23 GMT",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -31,7 +31,6 @@
"ETag": "W/\"cd828b300f3803bcda7512b44c762a69\"",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -25,7 +25,6 @@
"Last-Modified": "Sat, 05 Oct 2019 05:21:24 GMT",
"X-OAuth-Scopes": "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": "github.symmetra-preview; format=json",
"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",

View File

@@ -0,0 +1,11 @@
{
"token": "bogus",
"expires_at": "2019-12-19T12:27:59Z",
"permissions": {
"checks": "write",
"pull_requests": "write",
"contents": "read",
"metadata": "read"
},
"repository_selection": "all"
}

View File

@@ -0,0 +1,42 @@
{
"id" : "ae92606f-6db0-3ebf-87ed-b20c38645208",
"request" : {
"url" : "/app/installations/11111111/access_tokens",
"method" : "POST",
"bodyPatterns" : [ {
"equalToJson" : "{}",
"ignoreArrayOrder" : true,
"ignoreExtraElements": false
}
],
"headers": {
"Accept": {
"equalTo": "application/vnd.github.machine-man-preview+json"
}
}
},
"response" : {
"status" : 201,
"bodyFileName" : "body-app-installations-3755540-access_tokens-7W6Uy.json",
"headers" : {
"Date" : "Thu, 19 Dec 2019 11:27:59 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Server" : "GitHub.com",
"Status" : "201 Created",
"Cache-Control" : "public, max-age=60, s-maxage=60",
"Vary" : [ "Accept", "Accept-Encoding" ],
"ETag" : "\"d408f945674845ed4d6d9a31d81d0e4d\"",
"X-GitHub-Media-Type" : "github.machine-man-preview; format=json",
"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" : "DC42:5297:3DD9A:4A550:5DFB5EBE"
}
},
"uuid" : "ae92606f-6db0-3ebf-87ed-b20c38645208"
}