From c905bb4b6cedc24a8b207f1059ead0b960080fc8 Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Tue, 11 Jun 2019 17:27:07 +1200 Subject: [PATCH 01/10] Implement GitHub App API methods --- src/main/java/org/kohsuke/github/GHApp.java | 172 ++++++++++++++++++ .../github/GHAppCreateTokenBuilder.java | 50 +++++ .../org/kohsuke/github/GHAppInstallation.java | 165 +++++++++++++++++ .../github/GHAppInstallationToken.java | 76 ++++++++ .../kohsuke/github/GHRepositorySelection.java | 22 +++ .../java/org/kohsuke/github/GHTargetType.java | 24 +++ src/main/java/org/kohsuke/github/GitHub.java | 25 ++- .../org/kohsuke/github/GitHubBuilder.java | 15 +- .../java/org/kohsuke/github/Previews.java | 2 + .../java/org/kohsuke/github/Requester.java | 2 +- 10 files changed, 545 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHApp.java create mode 100644 src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java create mode 100644 src/main/java/org/kohsuke/github/GHAppInstallation.java create mode 100644 src/main/java/org/kohsuke/github/GHAppInstallationToken.java create mode 100644 src/main/java/org/kohsuke/github/GHRepositorySelection.java create mode 100644 src/main/java/org/kohsuke/github/GHTargetType.java diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java new file mode 100644 index 0000000000..7b07e0abb4 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -0,0 +1,172 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import static org.kohsuke.github.Previews.MACHINE_MAN; + +/** + * A Github App. + * + * @author Paulo Miguel Almeida + * + * @see GitHub#getApp() + */ + +public class GHApp extends GHObject { + + private GitHub root; + private GHUser owner; + private String name; + private String description; + @JsonProperty("external_url") + private String externalUrl; + private Map permissions; + private List events; + @JsonProperty("installations_count") + private long installationsCount; + @JsonProperty("html_url") + private String htmlUrl; + + + public GHUser getOwner() { + return owner; + } + + public void setOwner(GHUser owner) { + this.owner = owner; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getExternalUrl() { + return externalUrl; + } + + public void setExternalUrl(String externalUrl) { + this.externalUrl = externalUrl; + } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + public long getInstallationsCount() { + return installationsCount; + } + + public void setInstallationsCount(long installationsCount) { + this.installationsCount = installationsCount; + } + + public URL getHtmlUrl() { + return GitHub.parseURL(htmlUrl); + } + + public Map getPermissions() { + return permissions; + } + + public void setPermissions(Map permissions) { + this.permissions = permissions; + } + + /*package*/ GHApp wrapUp(GitHub root) { + this.root = root; + return this; + } + + /** + * Obtains all the installations associated with this app. + * + * You must use a JWT to access this endpoint. + * + * @see List installations + */ + public PagedIterable listInstallations() { + return new PagedIterable() { + public PagedIterator _iterator(int pageSize) { + return new PagedIterator(root.retrieve().withPreview(MACHINE_MAN).asIterator("/app/installations", GHAppInstallation[].class, pageSize)) { + protected void wrapUp(GHAppInstallation[] page) { + for (GHAppInstallation appInstallation : page) { + appInstallation.wrapUp(root); + } + } + }; + } + }; + } + + /** + * Obtain an installation associated with this app + * @param id - Installation Id + * + * You must use a JWT to access this endpoint. + * + * @see Get an installation + */ + public GHAppInstallation getInstallationById(long id) throws IOException { + return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root); + } + + /** + * Obtain an organization installation associated with this app + * @param name - Organization name + * + * You must use a JWT to access this endpoint. + * + * @see Get an organization installation + */ + public GHAppInstallation getInstallationByOrganization(String name) throws IOException { + return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root); + } + + /** + * Obtain an repository installation associated with this app + * @param ownerName - Organization or user name + * @param repositoryName - Repository name + * + * You must use a JWT to access this endpoint. + * + * @see Get a repository installation + */ + public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { + return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class).wrapUp(root); + } + + /** + * Obtain a user installation associated with this app + * @param name - user name + * + * You must use a JWT to access this endpoint. + * + * @see Get a user installation + */ + public GHAppInstallation getInstallationByUser(String name) throws IOException { + return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root); + } + +} + diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java new file mode 100644 index 0000000000..1ff3e2e92d --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -0,0 +1,50 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import static org.kohsuke.github.Previews.MACHINE_MAN; + +/** + * Creates a access token for a GitHub App Installation + * + * @author Paulo Miguel Almeida + * + * @see GHAppInstallation#createToken(Map) + */ +public class GHAppCreateTokenBuilder { + private final GitHub root; + protected final Requester builder; + private final String apiUrlTail; + + /*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { + this.root = root; + this.apiUrlTail = apiUrlTail; + this.builder = new Requester(root); + this.builder.with("permissions",permissions); + } + + /** + * By default the installation token has access to all repositories that the installation can access. To restrict + * the access to specific repositories, you can provide the repository_ids when creating the token. When you omit + * repository_ids, the response does not contain neither the repositories nor the permissions key. + * + * @param repositoryIds - Array containing the repositories Ids + * + */ + public GHAppCreateTokenBuilder repositoryIds(List repositoryIds) { + this.builder.with("repository_ids",repositoryIds); + return this; + } + + /** + * Creates an app token with all the parameters. + * + * You must use a JWT to access this endpoint. + */ + public GHAppInstallationToken create() throws IOException { + return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class).wrapUp(root); + } + +} diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java new file mode 100644 index 0000000000..093730b826 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -0,0 +1,165 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import static org.kohsuke.github.Previews.GAMBIT; + +/** + * A Github App Installation. + * + * @author Paulo Miguel Almeida + * + * @see GHApp#listInstallations() + * @see GHApp#getInstallationById(long) + * @see GHApp#getInstallationByOrganization(String) + * @see GHApp#getInstallationByRepository(String, String) + * @see GHApp#getInstallationByUser(String) + */ + +public class GHAppInstallation extends GHObject { + private GitHub root; + private GHUser account; + + @JsonProperty("access_tokens_url") + private String accessTokenUrl; + @JsonProperty("repositories_url") + private String repositoriesUrl; + @JsonProperty("app_id") + private long appId; + @JsonProperty("target_id") + private long targetId; + @JsonProperty("target_type") + private GHTargetType targetType; + private Map permissions; + private List events; + @JsonProperty("single_file_name") + private String singleFileName; + @JsonProperty("repository_selection") + private GHRepositorySelection repositorySelection; + private String htmlUrl; + + public URL getHtmlUrl() { + return GitHub.parseURL(htmlUrl); + } + + public GitHub getRoot() { + return root; + } + + public void setRoot(GitHub root) { + this.root = root; + } + + public GHUser getAccount() { + return account; + } + + public void setAccount(GHUser account) { + this.account = account; + } + + public String getAccessTokenUrl() { + return accessTokenUrl; + } + + public void setAccessTokenUrl(String accessTokenUrl) { + this.accessTokenUrl = accessTokenUrl; + } + + public String getRepositoriesUrl() { + return repositoriesUrl; + } + + public void setRepositoriesUrl(String repositoriesUrl) { + this.repositoriesUrl = repositoriesUrl; + } + + public long getAppId() { + return appId; + } + + public void setAppId(long appId) { + this.appId = appId; + } + + public long getTargetId() { + return targetId; + } + + public void setTargetId(long targetId) { + this.targetId = targetId; + } + + public GHTargetType getTargetType() { + return targetType; + } + + public void setTargetType(GHTargetType targetType) { + this.targetType = targetType; + } + + public Map getPermissions() { + return permissions; + } + + public void setPermissions(Map permissions) { + this.permissions = permissions; + } + + public List getEvents() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + public String getSingleFileName() { + return singleFileName; + } + + public void setSingleFileName(String singleFileName) { + this.singleFileName = singleFileName; + } + + public GHRepositorySelection getRepositorySelection() { + return repositorySelection; + } + + public void setRepositorySelection(GHRepositorySelection repositorySelection) { + this.repositorySelection = repositorySelection; + } + + /*package*/ GHAppInstallation wrapUp(GitHub root) { + this.root = root; + return this; + } + + /** + * Delete a Github App installation + * + * You must use a JWT to access this endpoint. + * + * @see Delete an installation + */ + public void deleteInstallation() throws IOException { + root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id)); + } + + + /** + * Starts a builder that creates a new App Installation Token. + * + *

+ * You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} + * to finally create an access token. + */ + public GHAppCreateTokenBuilder createToken(Map permissions){ + return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions); + } +} diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java new file mode 100644 index 0000000000..2388024d8a --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -0,0 +1,76 @@ +package org.kohsuke.github; + +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + +import java.io.IOException; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * A Github App Installation Token. + * + * @author Paulo Miguel Almeida + * + * @see GHAppInstallation#createToken(Map) + */ + +public class GHAppInstallationToken { + private GitHub root; + + private String token; + protected String expires_at; + private Map permissions; + private List repositories; + + public GitHub getRoot() { + return root; + } + + public void setRoot(GitHub root) { + this.root = root; + } + + public Map getPermissions() { + return permissions; + } + + public void setPermissions(Map permissions) { + this.permissions = permissions; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public List getRepositories() { + return repositories; + } + + public void setRepositories(List repositories) { + this.repositories = repositories; + } + + /** + * When was this tokens expires? + */ + @WithBridgeMethods(value=String.class, adapterMethod="expiresAtStr") + public Date getExpiresAt() throws IOException { + return GitHub.parseDate(expires_at); + } + + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "Bridge method of getExpiresAt") + private Object expiresAtStr(Date id, Class type) { + return expires_at; + } + + /*package*/ GHAppInstallationToken wrapUp(GitHub root) { + this.root = root; + return this; + } +} diff --git a/src/main/java/org/kohsuke/github/GHRepositorySelection.java b/src/main/java/org/kohsuke/github/GHRepositorySelection.java new file mode 100644 index 0000000000..afba38aaa2 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHRepositorySelection.java @@ -0,0 +1,22 @@ +package org.kohsuke.github; + +import java.util.Locale; + +/** + * App installation repository selection. + * + * @author Paulo Miguel Almeida + * + * @see GHAppInstallation + */ +public enum GHRepositorySelection { + SELECTED, + ALL; + + /** + * Returns GitHub's internal representation of this event. + */ + String symbol() { + return name().toLowerCase(Locale.ENGLISH); + } +} diff --git a/src/main/java/org/kohsuke/github/GHTargetType.java b/src/main/java/org/kohsuke/github/GHTargetType.java new file mode 100644 index 0000000000..42a23d8726 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHTargetType.java @@ -0,0 +1,24 @@ +package org.kohsuke.github; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Locale; + +/** + * App installation target type. + * + * @author Paulo Miguel Almeida + * + * @see GHAppInstallation + */ +public enum GHTargetType { + ORGANIZATION, + USER; + + /** + * Returns GitHub's internal representation of this event. + */ + String symbol() { + return StringUtils.capitalize(name().toLowerCase(Locale.ENGLISH)); + } +} diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 0f3726c28e..55ba3c72c5 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -115,6 +115,12 @@ public class GitHub { *

Specify oauthAccessToken, and optionally specify the login. Leave password null. * This will send OAuth token to the GitHub API. If the login parameter is null, * The constructor makes an API call to figure out the user name that owns the token. + * + *
Log in with JWT token + *
Specify jwtToken. Leave password null. + * This will send JWT token to the GitHub API via the Authorization HTTP header. + * Please note thatonly operations in which permissions have been previously configured and accepted during + * the GitHub App will be executed successfully. * * * @param apiUrl @@ -132,7 +138,7 @@ public class GitHub { * @param connector * HttpConnector to use. Pass null to use default connector. */ - /* package */ GitHub(String apiUrl, String login, String oauthAccessToken, String password, HttpConnector connector, RateLimitHandler rateLimitHandler, AbuseLimitHandler abuseLimitHandler) throws IOException { + /* package */ GitHub(String apiUrl, String login, String oauthAccessToken, String jwtToken, String password, HttpConnector connector, RateLimitHandler rateLimitHandler, AbuseLimitHandler abuseLimitHandler) throws IOException { if (apiUrl.endsWith("/")) apiUrl = apiUrl.substring(0, apiUrl.length()-1); // normalize this.apiUrl = apiUrl; if (null != connector) this.connector = connector; @@ -140,7 +146,9 @@ public class GitHub { if (oauthAccessToken!=null) { encodedAuthorization = "token "+oauthAccessToken; } else { - if (password!=null) { + if(jwtToken!=null){ + encodedAuthorization = "Bearer "+jwtToken; + }else if (password!=null) { String authorization = (login + ':' + password); String charsetName = Charsets.UTF_8.name(); encodedAuthorization = "Basic "+new String(Base64.encodeBase64(authorization.getBytes(charsetName)), charsetName); @@ -154,7 +162,7 @@ public class GitHub { this.rateLimitHandler = rateLimitHandler; this.abuseLimitHandler = abuseLimitHandler; - if (login==null && encodedAuthorization!=null) + if (login==null && encodedAuthorization!=null && jwtToken == null) login = getMyself().getLogin(); this.login = login; } @@ -697,6 +705,17 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces return retrieve().method("POST").to("/applications/" + clientId + "/tokens/" + accessToken, GHAuthorization.class); } + /** + * Returns the GitHub App associated with the authentication credentials used. + * + * You must use a JWT to access this endpoint. + * + * @see Get the authenticated GitHub App + */ + public GHApp getApp() throws IOException { + return retrieve().withPreview(MACHINE_MAN).to("/app", GHApp.class).wrapUp(this); + } + /** * Ensures that the credential is valid. */ diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index e54359892c..fbb5bc5c2e 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -26,7 +26,8 @@ public class GitHubBuilder { /* private */ String user; /* private */ String password; /* private */ String oauthToken; - + /* private */ String jwtToken; + private HttpConnector connector; private RateLimitHandler rateLimitHandler = RateLimitHandler.WAIT; @@ -53,7 +54,7 @@ public static GitHubBuilder fromCredentials() throws IOException { try { builder = fromPropertyFile(); - if (builder.oauthToken != null || builder.user != null) + if (builder.oauthToken != null || builder.user != null || builder.jwtToken != null) return builder; } catch (FileNotFoundException e) { // fall through @@ -62,7 +63,7 @@ public static GitHubBuilder fromCredentials() throws IOException { builder = fromEnvironment(); - if (builder.oauthToken != null || builder.user != null) + if (builder.oauthToken != null || builder.user != null || builder.jwtToken != null) return builder; else throw (IOException)new IOException("Failed to resolve credentials from ~/.github or the environment.").initCause(cause); @@ -108,6 +109,7 @@ public static GitHubBuilder fromEnvironment(String loginVariableName, String pas *
  • GITHUB_PASSWORD: raw password *
  • GITHUB_OAUTH: OAuth token to login *
  • GITHUB_ENDPOINT: URL of the API endpoint + *
  • GITHUB_JWT: JWT token to login * * *

    @@ -149,6 +151,7 @@ public static GitHubBuilder fromPropertyFile(String propertyFileName) throws IOE public static GitHubBuilder fromProperties(Properties props) { GitHubBuilder self = new GitHubBuilder(); self.withOAuthToken(props.getProperty("oauth"), props.getProperty("login")); + self.withJwtToken(props.getProperty("jwt")); self.withPassword(props.getProperty("login"), props.getProperty("password")); self.withEndpoint(props.getProperty("endpoint", GitHub.GITHUB_URL)); return self; @@ -177,6 +180,10 @@ public GitHubBuilder withOAuthToken(String oauthToken, String user) { this.user = user; return this; } + public GitHubBuilder withJwtToken(String jwtToken){ + this.jwtToken = jwtToken; + return this; + } public GitHubBuilder withConnector(HttpConnector connector) { this.connector = connector; return this; @@ -204,6 +211,6 @@ public HttpURLConnection connect(URL url) throws IOException { } public GitHub build() throws IOException { - return new GitHub(endpoint, user, oauthToken, password, connector, rateLimitHandler, abuseLimitHandler); + return new GitHub(endpoint, user, oauthToken, jwtToken, password, connector, rateLimitHandler, abuseLimitHandler); } } diff --git a/src/main/java/org/kohsuke/github/Previews.java b/src/main/java/org/kohsuke/github/Previews.java index 41ac7e155b..bf7a66f2d2 100644 --- a/src/main/java/org/kohsuke/github/Previews.java +++ b/src/main/java/org/kohsuke/github/Previews.java @@ -9,4 +9,6 @@ static final String SQUIRREL_GIRL = "application/vnd.github.squirrel-girl-preview"; static final String CLOAK = "application/vnd.github.cloak-preview"; static final String ZZZAX = "application/vnd.github.zzzax-preview+json"; + static final String MACHINE_MAN = "application/vnd.github.machine-man-preview+json"; + static final String GAMBIT = "application/vnd.github.gambit-preview+json"; } diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 4670e311e5..014c559b8f 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -165,7 +165,7 @@ public Requester with(String key, String value) { return _with(key, value); } - public Requester with(String key, Collection value) { + public Requester with(String key, Collection value) { return _with(key, value); } From 9f35eb1a8543395c649183901bbd3fface0e6866 Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Wed, 12 Jun 2019 11:32:03 +1200 Subject: [PATCH 02/10] Add @Preview and @Deprecated annotations to methods in which the API is still in preview --- src/main/java/org/kohsuke/github/GHApp.java | 5 +++++ .../java/org/kohsuke/github/GHAppCreateTokenBuilder.java | 3 +++ src/main/java/org/kohsuke/github/GHAppInstallation.java | 2 ++ src/main/java/org/kohsuke/github/GitHub.java | 1 + src/test/java/org/kohsuke/github/GitHubTest.java | 6 ++++-- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java index 7b07e0abb4..97de867ccf 100644 --- a/src/main/java/org/kohsuke/github/GHApp.java +++ b/src/main/java/org/kohsuke/github/GHApp.java @@ -105,6 +105,7 @@ public void setPermissions(Map permissions) { * * @see List installations */ + @Preview @Deprecated public PagedIterable listInstallations() { return new PagedIterable() { public PagedIterator _iterator(int pageSize) { @@ -127,6 +128,7 @@ protected void wrapUp(GHAppInstallation[] page) { * * @see Get an installation */ + @Preview @Deprecated public GHAppInstallation getInstallationById(long id) throws IOException { return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/app/installations/%d", id), GHAppInstallation.class).wrapUp(root); } @@ -139,6 +141,7 @@ public GHAppInstallation getInstallationById(long id) throws IOException { * * @see Get an organization installation */ + @Preview @Deprecated public GHAppInstallation getInstallationByOrganization(String name) throws IOException { return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/orgs/%s/installation", name), GHAppInstallation.class).wrapUp(root); } @@ -152,6 +155,7 @@ public GHAppInstallation getInstallationByOrganization(String name) throws IOExc * * @see Get a repository installation */ + @Preview @Deprecated public GHAppInstallation getInstallationByRepository(String ownerName, String repositoryName) throws IOException { return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/repos/%s/%s/installation", ownerName, repositoryName), GHAppInstallation.class).wrapUp(root); } @@ -164,6 +168,7 @@ public GHAppInstallation getInstallationByRepository(String ownerName, String re * * @see Get a user installation */ + @Preview @Deprecated public GHAppInstallation getInstallationByUser(String name) throws IOException { return root.retrieve().withPreview(MACHINE_MAN).to(String.format("/users/%s/installation", name), GHAppInstallation.class).wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 1ff3e2e92d..5eac119e5b 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -18,6 +18,7 @@ public class GHAppCreateTokenBuilder { protected final Requester builder; private final String apiUrlTail; + @Preview @Deprecated /*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; @@ -33,6 +34,7 @@ public class GHAppCreateTokenBuilder { * @param repositoryIds - Array containing the repositories Ids * */ + @Preview @Deprecated public GHAppCreateTokenBuilder repositoryIds(List repositoryIds) { this.builder.with("repository_ids",repositoryIds); return this; @@ -43,6 +45,7 @@ public GHAppCreateTokenBuilder repositoryIds(List repositoryIds) { * * You must use a JWT to access this endpoint. */ + @Preview @Deprecated public GHAppInstallationToken create() throws IOException { return builder.method("POST").withPreview(MACHINE_MAN).to(apiUrlTail, GHAppInstallationToken.class).wrapUp(root); } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 093730b826..7a6ee40fd1 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -147,6 +147,7 @@ public void setRepositorySelection(GHRepositorySelection repositorySelection) { * * @see Delete an installation */ + @Preview @Deprecated public void deleteInstallation() throws IOException { root.retrieve().method("DELETE").withPreview(GAMBIT).to(String.format("/app/installations/%d", id)); } @@ -159,6 +160,7 @@ public void deleteInstallation() throws IOException { * You use the returned builder to set various properties, then call {@link GHAppCreateTokenBuilder#create()} * to finally create an access token. */ + @Preview @Deprecated public GHAppCreateTokenBuilder createToken(Map permissions){ return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions); } diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 55ba3c72c5..5e78805954 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -712,6 +712,7 @@ public GHAuthorization resetAuth(@Nonnull String clientId, @Nonnull String acces * * @see Get the authenticated GitHub App */ + @Preview @Deprecated public GHApp getApp() throws IOException { return retrieve().withPreview(MACHINE_MAN).to("/app", GHApp.class).wrapUp(this); } diff --git a/src/test/java/org/kohsuke/github/GitHubTest.java b/src/test/java/org/kohsuke/github/GitHubTest.java index f4b77b8271..91b8738043 100644 --- a/src/test/java/org/kohsuke/github/GitHubTest.java +++ b/src/test/java/org/kohsuke/github/GitHubTest.java @@ -61,7 +61,8 @@ public void testGitHubBuilderFromEnvironment() throws IOException { props.put("login", "bogus"); props.put("oauth", "bogus"); props.put("password", "bogus"); - + props.put("jwt", "bogus"); + setupEnvironment(props); GitHubBuilder builder = GitHubBuilder.fromEnvironment(); @@ -69,7 +70,8 @@ public void testGitHubBuilderFromEnvironment() throws IOException { assertEquals("bogus", builder.user); assertEquals("bogus", builder.oauthToken); assertEquals("bogus", builder.password); - + assertEquals("bogus", builder.jwtToken); + } /* From 756d298f046e1c9d24b302404c8c2bc889ede22a Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Tue, 18 Jun 2019 10:50:08 +1200 Subject: [PATCH 03/10] Add missing INTEGRATION_INSTALLATION_REPOSITORIES github event --- src/main/java/org/kohsuke/github/GHEvent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/kohsuke/github/GHEvent.java b/src/main/java/org/kohsuke/github/GHEvent.java index 970b6afbf7..e54de3ec9f 100644 --- a/src/main/java/org/kohsuke/github/GHEvent.java +++ b/src/main/java/org/kohsuke/github/GHEvent.java @@ -23,6 +23,7 @@ public enum GHEvent { GOLLUM, INSTALLATION, INSTALLATION_REPOSITORIES, + INTEGRATION_INSTALLATION_REPOSITORIES, ISSUE_COMMENT, ISSUES, LABEL, From 2d15bef76dc1fe22a558283476b01fd84a65c097 Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Tue, 18 Jun 2019 11:24:59 +1200 Subject: [PATCH 04/10] Add missing CHECK_SUITE github event --- pom.xml | 24 +++++++++++++++++++ src/main/java/org/kohsuke/github/GHEvent.java | 1 + 2 files changed, 25 insertions(+) diff --git a/pom.xml b/pom.xml index 4a318bdb49..51515ac299 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,13 @@ + + + + + + + maven-surefire-plugin 2.22.1 @@ -176,6 +183,23 @@ 3.0.1 provided + + io.jsonwebtoken + jjwt-api + 0.10.5 + + + io.jsonwebtoken + jjwt-impl + 0.10.5 + runtime + + + io.jsonwebtoken + jjwt-jackson + 0.10.5 + runtime + diff --git a/src/main/java/org/kohsuke/github/GHEvent.java b/src/main/java/org/kohsuke/github/GHEvent.java index e54de3ec9f..8ad6368fe5 100644 --- a/src/main/java/org/kohsuke/github/GHEvent.java +++ b/src/main/java/org/kohsuke/github/GHEvent.java @@ -24,6 +24,7 @@ public enum GHEvent { INSTALLATION, INSTALLATION_REPOSITORIES, INTEGRATION_INSTALLATION_REPOSITORIES, + CHECK_SUITE, ISSUE_COMMENT, ISSUES, LABEL, From 15b3bc6a636f295fde6f2cce9aebd0b38582e480 Mon Sep 17 00:00:00 2001 From: Paulo Almeida Date: Tue, 18 Jun 2019 13:36:00 +1200 Subject: [PATCH 05/10] Remove JWT dependencies used for testing purposes --- pom.xml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pom.xml b/pom.xml index 51515ac299..4a318bdb49 100644 --- a/pom.xml +++ b/pom.xml @@ -34,13 +34,6 @@ - - - - - - - maven-surefire-plugin 2.22.1 @@ -183,23 +176,6 @@ 3.0.1 provided - - io.jsonwebtoken - jjwt-api - 0.10.5 - - - io.jsonwebtoken - jjwt-impl - 0.10.5 - runtime - - - io.jsonwebtoken - jjwt-jackson - 0.10.5 - runtime - From 4703f2d1f5e11f1f959ae5a863780444b7d7a9f6 Mon Sep 17 00:00:00 2001 From: Paulo Miguel Almeida Date: Sat, 10 Aug 2019 19:01:12 +1200 Subject: [PATCH 06/10] Add tests for GithubApp integration; Add wiremock-standalone library; Signed-off-by: Paulo Almeida --- pom.xml | 12 ++ .../github/GHAppCreateTokenBuilder.java | 4 +- .../org/kohsuke/github/GHAppInstallation.java | 8 +- .../github/GHAppInstallationToken.java | 11 + src/main/java/org/kohsuke/github/GitHub.java | 8 +- .../java/org/kohsuke/github/Requester.java | 26 ++- .../java/org/kohsuke/github/GHAppTest.java | 204 ++++++++++++++++++ ...bapp-create-installation-accesstokens.json | 107 +++++++++ .../__files/body-mapping-githubapp-app.json | 41 ++++ ...-mapping-githubapp-installation-by-id.json | 43 ++++ ...ithubapp-installation-by-organization.json | 43 ++++ ...-githubapp-installation-by-repository.json | 43 ++++ ...apping-githubapp-installation-by-user.json | 43 ++++ .../body-mapping-githubapp-installations.json | 45 ++++ .../api/mappings/mapping-githubapp-app.json | 34 +++ ...bapp-create-installation-accesstokens.json | 39 ++++ ...mapping-githubapp-delete-installation.json | 33 +++ .../mapping-githubapp-installation-by-id.json | 34 +++ ...ithubapp-installation-by-organization.json | 34 +++ ...-githubapp-installation-by-repository.json | 34 +++ ...apping-githubapp-installation-by-user.json | 34 +++ .../mapping-githubapp-installations.json | 34 +++ 22 files changed, 901 insertions(+), 13 deletions(-) create mode 100644 src/test/java/org/kohsuke/github/GHAppTest.java create mode 100644 src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-app.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json create mode 100644 src/test/resources/api/__files/body-mapping-githubapp-installations.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-app.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-delete-installation.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json create mode 100644 src/test/resources/api/mappings/mapping-githubapp-installations.json diff --git a/pom.xml b/pom.xml index 4a318bdb49..33291cf3b4 100644 --- a/pom.xml +++ b/pom.xml @@ -138,6 +138,12 @@ org.kohsuke.stapler stapler-jetty 1.1 + + + javax.servlet + servlet-api + + test @@ -170,6 +176,12 @@ 1.10.19 test + + com.github.tomakehurst + wiremock-standalone + 2.24.1 + test + com.google.code.findbugs annotations diff --git a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java index 5eac119e5b..cf19dd99af 100644 --- a/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java +++ b/src/main/java/org/kohsuke/github/GHAppCreateTokenBuilder.java @@ -19,11 +19,11 @@ public class GHAppCreateTokenBuilder { private final String apiUrlTail; @Preview @Deprecated - /*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { + /*package*/ GHAppCreateTokenBuilder(GitHub root, String apiUrlTail, Map permissions) { this.root = root; this.apiUrlTail = apiUrlTail; this.builder = new Requester(root); - this.builder.with("permissions",permissions); + this.builder.withPermissions("permissions",permissions); } /** diff --git a/src/main/java/org/kohsuke/github/GHAppInstallation.java b/src/main/java/org/kohsuke/github/GHAppInstallation.java index 7a6ee40fd1..3925742162 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallation.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallation.java @@ -35,7 +35,7 @@ public class GHAppInstallation extends GHObject { private long targetId; @JsonProperty("target_type") private GHTargetType targetType; - private Map permissions; + private Map permissions; private List events; @JsonProperty("single_file_name") private String singleFileName; @@ -103,11 +103,11 @@ public void setTargetType(GHTargetType targetType) { this.targetType = targetType; } - public Map getPermissions() { + public Map getPermissions() { return permissions; } - public void setPermissions(Map permissions) { + public void setPermissions(Map permissions) { this.permissions = permissions; } @@ -161,7 +161,7 @@ public void deleteInstallation() throws IOException { * to finally create an access token. */ @Preview @Deprecated - public GHAppCreateTokenBuilder createToken(Map permissions){ + public GHAppCreateTokenBuilder createToken(Map permissions){ return new GHAppCreateTokenBuilder(root,String.format("/app/installations/%d/access_tokens", id), permissions); } } diff --git a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java index 2388024d8a..2b6e78fdee 100644 --- a/src/main/java/org/kohsuke/github/GHAppInstallationToken.java +++ b/src/main/java/org/kohsuke/github/GHAppInstallationToken.java @@ -1,5 +1,6 @@ package org.kohsuke.github; +import com.fasterxml.jackson.annotation.JsonProperty; import com.infradna.tool.bridge_method_injector.WithBridgeMethods; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -23,6 +24,8 @@ public class GHAppInstallationToken { protected String expires_at; private Map permissions; private List repositories; + @JsonProperty("repository_selection") + private GHRepositorySelection repositorySelection; public GitHub getRoot() { return root; @@ -56,6 +59,14 @@ public void setRepositories(List repositories) { this.repositories = repositories; } + public GHRepositorySelection getRepositorySelection() { + return repositorySelection; + } + + public void setRepositorySelection(GHRepositorySelection repositorySelection) { + this.repositorySelection = repositorySelection; + } + /** * When was this tokens expires? */ diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 5e78805954..9d46dea70b 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -119,7 +119,7 @@ public class GitHub { *

    Log in with JWT token *
    Specify jwtToken. Leave password null. * This will send JWT token to the GitHub API via the Authorization HTTP header. - * Please note thatonly operations in which permissions have been previously configured and accepted during + * Please note that only operations in which permissions have been previously configured and accepted during * the GitHub App will be executed successfully. * * @@ -940,7 +940,11 @@ public Reader renderMarkdown(String text) throws IOException { /*package*/ static final ObjectMapper MAPPER = new ObjectMapper(); - private static final String[] TIME_FORMATS = {"yyyy/MM/dd HH:mm:ss ZZZZ","yyyy-MM-dd'T'HH:mm:ss'Z'"}; + private static final String[] TIME_FORMATS = { + "yyyy/MM/dd HH:mm:ss ZZZZ", + "yyyy-MM-dd'T'HH:mm:ss'Z'", + "yyyy-MM-dd'T'HH:mm:ss.S'Z'" // GitHub App endpoints return a different date format + }; static { MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY)); diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index 014c559b8f..bbaeea25ff 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -154,11 +154,7 @@ public Requester with(String key, Boolean value) { public Requester with(String key, Enum e) { if (e==null) return _with(key, null); - - // by convention Java constant names are upper cases, but github uses - // lower-case constants. GitHub also uses '-', which in Java we always - // replace by '_' - return with(key, e.toString().toLowerCase(Locale.ENGLISH).replace('_', '-')); + return with(key, transformEnum(e)); } public Requester with(String key, String value) { @@ -181,6 +177,14 @@ public Requester with(String key, Map value) { return _with(key, value); } + public Requester withPermissions(String key, Map value) { + Map retMap = new HashMap(); + for (Map.Entry entry : value.entrySet()) { + retMap.put(entry.getKey(), transformEnum(entry.getValue())); + } + return _with(key, retMap); + } + public Requester with(@WillClose/*later*/ InputStream body) { this.body = body; return this; @@ -726,6 +730,18 @@ private InputStream wrapStream(InputStream in) throws IOException { throw e; } + /** + * Transform Java Enum into Github constants given its conventions + * @param en - Enum to be transformed + * @return a String containing the value of a Github constant + */ + private String transformEnum(Enum en){ + // by convention Java constant names are upper cases, but github uses + // lower-case constants. GitHub also uses '-', which in Java we always + // replace by '_' + return en.toString().toLowerCase(Locale.ENGLISH).replace('_', '-'); + } + private static final List METHODS_WITHOUT_BODY = asList("GET", "DELETE"); private static final Logger LOGGER = Logger.getLogger(Requester.class.getName()); } diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java new file mode 100644 index 0000000000..e7c81d3764 --- /dev/null +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -0,0 +1,204 @@ +package org.kohsuke.github; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; +import java.util.*; + +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.*; + +public class GHAppTest { + + @Rule + public WireMockRule githubApi = new WireMockRule(WireMockConfiguration.options() + .dynamicPort().usingFilesUnderClasspath("api")); + public GitHub github; + + @Before + public void prepareMockGitHub() throws Exception { + githubApi.stubFor(get(urlMatching(".*")).atPriority(10)); + github = new GitHubBuilder().withJwtToken("bogus").withEndpoint("http://localhost:" + githubApi.port()).build(); + } + + @Test + public void getGitHubApp() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-app.json"); + JsonNode ownerNode = rootNode.get("owner"); + + GHApp app = github.getApp(); + assertThat(app.id, is(rootNode.get("id").asLong())); + assertThat(app.getOwner().id, is(ownerNode.get("id").asLong())); + assertThat(app.getOwner().login, is(ownerNode.get("login").asText())); + assertThat(app.getName(), is(rootNode.get("name").asText())); + assertThat(app.getDescription(), is(rootNode.get("description").asText())); + assertThat(app.getExternalUrl(), is(rootNode.get("external_url").asText())); + assertThat(app.getHtmlUrl().toString(), is(rootNode.get("html_url").asText())); + assertThat(app.getCreatedAt(), is(GitHub.parseDate(rootNode.get("created_at").asText()))); + assertThat(app.getUpdatedAt(), is(GitHub.parseDate(rootNode.get("updated_at").asText()))); + assertThat(app.getPermissions().size(), is(rootNode.get("permissions").size())); + assertThat(app.getEvents().size(), is(rootNode.get("events").size())); + assertThat(app.getInstallationsCount(), is(rootNode.get("installations_count").asLong())); + } + + @Test + public void listInstallations() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-installations.json"); + + GHApp app = github.getApp(); + List installations = app.listInstallations().asList(); + assertThat(installations.size(), is(rootNode.size())); + + GHAppInstallation appInstallation = installations.get(0); + JsonNode installationNode = rootNode.get(0); + testAppInstallation(installationNode, appInstallation); + } + + @Test + public void getInstallationById() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-id.json"); + + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationById(1111111); + testAppInstallation(rootNode, installation); + } + + @Test + public void getInstallationByOrganization() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-organization.json"); + + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationByOrganization("bogus"); + testAppInstallation(rootNode, installation); + } + + @Test + public void getInstallationByRepository() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-organization.json"); + + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationByRepository("bogus", "bogus"); + testAppInstallation(rootNode, installation); + } + + @Test + public void getInstallationByUser() throws IOException { + JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-user.json"); + + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationByUser("bogus"); + testAppInstallation(rootNode, installation); + } + + @Test + public void deleteInstallation() throws IOException { + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationByUser("bogus"); + try { + installation.deleteInstallation(); + } catch (IOException e) { + fail("deleteInstallation wasn't suppose to fail in this test"); + } + } + + @Test + public void createToken() throws IOException { + JsonNode rootNode = readPayload("/body-githubapp-create-installation-accesstokens.json"); + + GHApp app = github.getApp(); + GHAppInstallation installation = app.getInstallationByUser("bogus"); + + Map permissions = new HashMap(); + permissions.put("checks", GHPermissionType.WRITE); + permissions.put("pull_requests", GHPermissionType.WRITE); + permissions.put("contents", GHPermissionType.READ); + permissions.put("metadata", GHPermissionType.READ); + + GHAppInstallationToken installationToken = installation.createToken(permissions) + .repositoryIds(Arrays.asList(111111111)) + .create(); + + assertThat(installationToken.getToken(), is(rootNode.get("token").asText())); + assertThat(installation.getPermissions(), is(convertToMap(rootNode.get("permissions"), GHPermissionType.class))); + assertThat(installationToken.getRepositorySelection(), + is(convertToEnum(rootNode.get("repository_selection").asText(), GHRepositorySelection.class))); + assertThat(installationToken.getExpiresAt(), is(GitHub.parseDate(rootNode.get("expires_at").asText()))); + + ArrayNode repositoriesNode = (ArrayNode) rootNode.get("repositories"); + JsonNode repositoryNode = repositoriesNode.get(0); + GHRepository repository = installationToken.getRepositories().get(0); + assertThat(installationToken.getRepositories().size(), is(repositoriesNode.size())); + assertThat(repository.getId(), is(repositoryNode.get("id").asLong())); + assertThat(repository.getName(), is(repositoryNode.get("name").asText())); + } + + private void testAppInstallation(JsonNode installationNode, GHAppInstallation appInstallation) throws IOException { + Map appPermissions = appInstallation.getPermissions(); + GHUser appAccount = appInstallation.getAccount(); + JsonNode accountNode = installationNode.get("account"); + JsonNode permissionsNode = installationNode.get("permissions"); + + assertThat(appInstallation.id, is(installationNode.get("id").asLong())); + assertThat(appAccount.id, is(accountNode.get("id").asLong())); + assertThat(appAccount.login, is(accountNode.get("login").asText())); + assertThat(appInstallation.getRepositorySelection(), + is(convertToEnum(installationNode.get("repository_selection").asText(), GHRepositorySelection.class))); + assertThat(appInstallation.getAccessTokenUrl(), is(installationNode.get("access_tokens_url").asText())); + assertThat(appInstallation.getRepositoriesUrl(), is(installationNode.get("repositories_url").asText())); + assertThat(appInstallation.getAppId(), is(installationNode.get("app_id").asLong())); + assertThat(appInstallation.getTargetId(), is(installationNode.get("target_id").asLong())); + assertThat(appInstallation.getTargetType(), + is(convertToEnum(installationNode.get("target_type").asText(), GHTargetType.class))); + assertThat(appPermissions, is(convertToMap(permissionsNode, GHPermissionType.class))); + + List events = convertToEnumList((ArrayNode) installationNode.get("events"), GHEvent.class); + assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0]))); + assertThat(appInstallation.getCreatedAt(), is(GitHub.parseDate(installationNode.get("created_at").asText()))); + assertThat(appInstallation.getUpdatedAt(), is(GitHub.parseDate(installationNode.get("updated_at").asText()))); + assertNull(appInstallation.getSingleFileName()); + } + + private JsonNode readPayload(String relativeFilePath) throws IOException { + String payload = "/api/__files/".concat(relativeFilePath); + return new ObjectMapper().readTree(this.getClass().getResourceAsStream(payload)); + } + + private > List convertToEnumList(ArrayNode jsonValues, Class valueType) { + List retList = new ArrayList(jsonValues.size()); + for (int i = 0; i < jsonValues.size(); i++) { + retList.add(convertToEnum(jsonValues.get(i).asText(), valueType)); + } + return retList; + } + + private > Map convertToMap(JsonNode jsonNode, Class valueType) { + Map retMap = new HashMap(jsonNode.size()); + Iterator iterator = jsonNode.fieldNames(); + while (iterator.hasNext()) { + String current = iterator.next(); + retMap.put(current, convertToEnum(jsonNode.get(current).asText(), valueType)); + } + return retMap; + } + + private > T convertToEnum(String text, Class valueType) { + // by convention Java constant names are upper cases, but github uses + // lower-case constants. GitHub also uses '-', which in Java we always + // replace by '_' + String value = text.toUpperCase(Locale.ENGLISH).replace('-', '_'); + // special treatment this sdk has provided certain enums with + if (value.equals("*")) value = "ALL"; + return Enum.valueOf(valueType, value); + } + +} diff --git a/src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json b/src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json new file mode 100644 index 0000000000..d891cc0e7d --- /dev/null +++ b/src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json @@ -0,0 +1,107 @@ +{ + "token": "bogus", + "expires_at": "2019-08-10T05:54:58Z", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "repository_selection": "selected", + "repositories": [ + { + "id": 111111111, + "node_id": "asdfasdf", + "name": "bogus", + "full_name": "bogus/bogus", + "private": true, + "owner": { + "login": "bogus", + "id": 11111111, + "node_id": "asdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/11111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/bogus/bogus", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/bogus/bogus", + "forks_url": "https://api.github.com/repos/bogus/bogus/forks", + "keys_url": "https://api.github.com/repos/bogus/bogus/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/bogus/bogus/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/bogus/bogus/teams", + "hooks_url": "https://api.github.com/repos/bogus/bogus/hooks", + "issue_events_url": "https://api.github.com/repos/bogus/bogus/issues/events{/number}", + "events_url": "https://api.github.com/repos/bogus/bogus/events", + "assignees_url": "https://api.github.com/repos/bogus/bogus/assignees{/user}", + "branches_url": "https://api.github.com/repos/bogus/bogus/branches{/branch}", + "tags_url": "https://api.github.com/repos/bogus/bogus/tags", + "blobs_url": "https://api.github.com/repos/bogus/bogus/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/bogus/bogus/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/bogus/bogus/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/bogus/bogus/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/bogus/bogus/statuses/{sha}", + "languages_url": "https://api.github.com/repos/bogus/bogus/languages", + "stargazers_url": "https://api.github.com/repos/bogus/bogus/stargazers", + "contributors_url": "https://api.github.com/repos/bogus/bogus/contributors", + "subscribers_url": "https://api.github.com/repos/bogus/bogus/subscribers", + "subscription_url": "https://api.github.com/repos/bogus/bogus/subscription", + "commits_url": "https://api.github.com/repos/bogus/bogus/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/bogus/bogus/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/bogus/bogus/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/bogus/bogus/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/bogus/bogus/contents/{+path}", + "compare_url": "https://api.github.com/repos/bogus/bogus/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/bogus/bogus/merges", + "archive_url": "https://api.github.com/repos/bogus/bogus/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/bogus/bogus/downloads", + "issues_url": "https://api.github.com/repos/bogus/bogus/issues{/number}", + "pulls_url": "https://api.github.com/repos/bogus/bogus/pulls{/number}", + "milestones_url": "https://api.github.com/repos/bogus/bogus/milestones{/number}", + "notifications_url": "https://api.github.com/repos/bogus/bogus/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/bogus/bogus/labels{/name}", + "releases_url": "https://api.github.com/repos/bogus/bogus/releases{/id}", + "deployments_url": "https://api.github.com/repos/bogus/bogus/deployments", + "created_at": "2018-09-06T03:25:38Z", + "updated_at": "2018-09-30T22:04:06Z", + "pushed_at": "2019-08-08T22:22:34Z", + "git_url": "git://github.com/bogus/bogus.git", + "ssh_url": "git@github.com:bogus/bogus.git", + "clone_url": "https://github.com/bogus/bogus.git", + "svn_url": "https://github.com/bogus/bogus", + "homepage": null, + "size": 618, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "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": 5, + "license": null, + "forks": 0, + "open_issues": 5, + "watchers": 0, + "default_branch": "master" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-app.json b/src/test/resources/api/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installations.json b/src/test/resources/api/__files/body-mapping-githubapp-installations.json new file mode 100644 index 0000000000..dfda131a9c --- /dev/null +++ b/src/test/resources/api/__files/body-mapping-githubapp-installations.json @@ -0,0 +1,45 @@ +[ + { + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null + } +] \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-app.json b/src/test/resources/api/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json b/src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json new file mode 100644 index 0000000000..7996662d18 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json @@ -0,0 +1,39 @@ +{ + "request" : { + "url" : "/app/installations/11111111/access_tokens", + "method" : "POST", + "bodyPatterns" : [ { + "equalToJson" : "{\"repository_ids\":[111111111],\"permissions\":{\"pull_requests\":\"write\",\"metadata\":\"read\",\"checks\":\"write\",\"contents\":\"read\"}}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : false + } ], + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response" : { + "status" : 201, + "bodyFileName" : "body-githubapp-create-installation-accesstokens.json", + "headers" : { + "Date" : "Sat, 10 Aug 2019 04:54:58 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" : "\"c47070915d3f78d2c4aea4bd8a2c3351\"", + "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" : "EEC8:4357:E0DD17:110A2E7:5D4E4E22" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-delete-installation.json b/src/test/resources/api/mappings/mapping-githubapp-delete-installation.json new file mode 100644 index 0000000000..4fbf043a8f --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-delete-installation.json @@ -0,0 +1,33 @@ +{ + "request": { + "url": "/app/installations/11111111", + "method": "DELETE", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.gambit-preview+json" + } + } + }, + "response": { + "status": 204, + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "204 No Content", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json b/src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json new file mode 100644 index 0000000000..87ba55f445 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app/installations/1111111", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-id.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json b/src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json new file mode 100644 index 0000000000..bd94ed4800 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/orgs/bogus/installation", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-organization.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json b/src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json new file mode 100644 index 0000000000..3fd3c011c0 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/repos/bogus/bogus/installation", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-repository.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json b/src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json new file mode 100644 index 0000000000..573705fde7 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/users/bogus/installation", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-user.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installations.json b/src/test/resources/api/mappings/mapping-githubapp-installations.json new file mode 100644 index 0000000000..5b01455c26 --- /dev/null +++ b/src/test/resources/api/mappings/mapping-githubapp-installations.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app/installations", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installations.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file From 905bd1a4c9a20353d5df323c008556a9ef8f1edf Mon Sep 17 00:00:00 2001 From: Paulo Miguel Almeida Date: Mon, 26 Aug 2019 12:37:28 +1200 Subject: [PATCH 07/10] Fix typo Signed-off-by: Paulo Almeida --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d7bc3c5c2..8d86c0b099 100644 --- a/pom.xml +++ b/pom.xml @@ -161,7 +161,7 @@ 1.1 From 3d827313257c42f0ac5b7e7aa89bcbe5f13fe721 Mon Sep 17 00:00:00 2001 From: PauloMigAlmeida Date: Sun, 15 Sep 2019 10:52:22 +1200 Subject: [PATCH 08/10] Update tests using the new wiremock structure as per requested Signed-off-by: PauloMigAlmeida --- .../java/org/kohsuke/github/GHAppTest.java | 206 +++++++----------- ...bapp-create-installation-accesstokens.json | 0 .../__files/body-mapping-githubapp-app.json | 0 ...apping-githubapp-installation-by-user.json | 0 .../mappings/mapping-githubapp-app.json | 0 ...bapp-create-installation-accesstokens.json | 0 ...apping-githubapp-installation-by-user.json | 0 .../__files/body-mapping-githubapp-app.json | 41 ++++ ...pping-githubapp-installation-by-user.json} | 0 .../mappings/mapping-githubapp-app.json | 34 +++ ...mapping-githubapp-delete-installation.json | 0 ...apping-githubapp-installation-by-user.json | 34 +++ .../__files/body-mapping-githubapp-app.json | 41 ++++ .../mappings/mapping-githubapp-app.json | 34 +++ .../__files/body-mapping-githubapp-app.json | 41 ++++ ...mapping-githubapp-installation-by-id.json} | 0 .../mappings/mapping-githubapp-app.json | 34 +++ .../mapping-githubapp-installation-by-id.json | 0 .../__files/body-mapping-githubapp-app.json | 41 ++++ ...thubapp-installation-by-organization.json} | 0 .../mappings/mapping-githubapp-app.json | 34 +++ ...ithubapp-installation-by-organization.json | 0 .../__files/body-mapping-githubapp-app.json | 41 ++++ ...-githubapp-installation-by-repository.json | 43 ++++ .../mappings/mapping-githubapp-app.json | 34 +++ ...-githubapp-installation-by-repository.json | 0 .../__files/body-mapping-githubapp-app.json | 41 ++++ ...apping-githubapp-installation-by-user.json | 43 ++++ .../mappings/mapping-githubapp-app.json | 34 +++ ...apping-githubapp-installation-by-user.json | 34 +++ .../__files/body-mapping-githubapp-app.json | 41 ++++ .../body-mapping-githubapp-installations.json | 4 +- .../mappings/mapping-githubapp-app.json | 34 +++ .../mapping-githubapp-installations.json | 0 34 files changed, 756 insertions(+), 133 deletions(-) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/__files/body-githubapp-create-installation-accesstokens.json (100%) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/__files/body-mapping-githubapp-app.json (100%) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/__files/body-mapping-githubapp-installation-by-user.json (100%) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/mappings/mapping-githubapp-app.json (100%) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/mappings/mapping-githubapp-create-installation-accesstokens.json (100%) rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/createToken}/mappings/mapping-githubapp-installation-by-user.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-app.json rename src/test/resources/{api/__files/body-mapping-githubapp-installation-by-id.json => org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-installation-by-user.json} (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/deleteInstallation}/mappings/mapping-githubapp-delete-installation.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-installation-by-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/body-mapping-githubapp-app.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/mapping-githubapp-app.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-app.json rename src/test/resources/{api/__files/body-mapping-githubapp-installation-by-organization.json => org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-installation-by-id.json} (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/getInstallationById}/mappings/mapping-githubapp-installation-by-id.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-app.json rename src/test/resources/{api/__files/body-mapping-githubapp-installation-by-repository.json => org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-installation-by-organization.json} (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization}/mappings/mapping-githubapp-installation-by-organization.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-app.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-installation-by-repository.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository}/mappings/mapping-githubapp-installation-by-repository.json (100%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-app.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-installation-by-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-app.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-installation-by-user.json create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/listInstallations}/__files/body-mapping-githubapp-installations.json (93%) create mode 100644 src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-app.json rename src/test/resources/{api => org/kohsuke/github/GHAppTest/wiremock/listInstallations}/mappings/mapping-githubapp-installations.json (100%) diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java index e7c81d3764..342312ff28 100644 --- a/src/test/java/org/kohsuke/github/GHAppTest.java +++ b/src/test/java/org/kohsuke/github/GHAppTest.java @@ -1,108 +1,88 @@ package org.kohsuke.github; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import java.io.IOException; -import java.util.*; - -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; - -public class GHAppTest { - - @Rule - public WireMockRule githubApi = new WireMockRule(WireMockConfiguration.options() - .dynamicPort().usingFilesUnderClasspath("api")); - public GitHub github; - - @Before - public void prepareMockGitHub() throws Exception { - githubApi.stubFor(get(urlMatching(".*")).atPriority(10)); - github = new GitHubBuilder().withJwtToken("bogus").withEndpoint("http://localhost:" + githubApi.port()).build(); +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.Matchers.*; + +/** + * Tests for the GitHub App API methods + * + * @author Paulo Miguel Almeida + */ +public class GHAppTest extends AbstractGitHubApiWireMockTest { + + protected GitHubBuilder getGitHubBuilder() { + return super.getGitHubBuilder() + // ensure that only JWT will be used against the tests below + .withPassword(null, null) + .withJwtToken("bogus"); } @Test public void getGitHubApp() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-app.json"); - JsonNode ownerNode = rootNode.get("owner"); - - GHApp app = github.getApp(); - assertThat(app.id, is(rootNode.get("id").asLong())); - assertThat(app.getOwner().id, is(ownerNode.get("id").asLong())); - assertThat(app.getOwner().login, is(ownerNode.get("login").asText())); - assertThat(app.getName(), is(rootNode.get("name").asText())); - assertThat(app.getDescription(), is(rootNode.get("description").asText())); - assertThat(app.getExternalUrl(), is(rootNode.get("external_url").asText())); - assertThat(app.getHtmlUrl().toString(), is(rootNode.get("html_url").asText())); - assertThat(app.getCreatedAt(), is(GitHub.parseDate(rootNode.get("created_at").asText()))); - assertThat(app.getUpdatedAt(), is(GitHub.parseDate(rootNode.get("updated_at").asText()))); - assertThat(app.getPermissions().size(), is(rootNode.get("permissions").size())); - assertThat(app.getEvents().size(), is(rootNode.get("events").size())); - assertThat(app.getInstallationsCount(), is(rootNode.get("installations_count").asLong())); + GHApp app = gitHub.getApp(); + assertThat(app.id, is((long) 11111)); + assertThat(app.getOwner().id, is((long) 111111111)); + assertThat(app.getOwner().login, is("bogus")); + assertThat(app.getName(), is("Bogus-Development")); + assertThat(app.getDescription(), is("")); + assertThat(app.getExternalUrl(), is("https://bogus.domain.com")); + assertThat(app.getHtmlUrl().toString(), is("https://github.com/apps/bogus-development")); + assertThat(app.getCreatedAt(), is(GitHub.parseDate("2019-06-10T04:21:41Z"))); + assertThat(app.getUpdatedAt(), is(GitHub.parseDate("2019-06-10T04:21:41Z"))); + assertThat(app.getPermissions().size(), is(4)); + assertThat(app.getEvents().size(), is(2)); + assertThat(app.getInstallationsCount(), is((long) 1)); } + @Test public void listInstallations() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-installations.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); List installations = app.listInstallations().asList(); - assertThat(installations.size(), is(rootNode.size())); + assertThat(installations.size(), is(1)); GHAppInstallation appInstallation = installations.get(0); - JsonNode installationNode = rootNode.get(0); - testAppInstallation(installationNode, appInstallation); + testAppInstallation(appInstallation); } @Test public void getInstallationById() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-id.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationById(1111111); - testAppInstallation(rootNode, installation); + testAppInstallation(installation); } @Test public void getInstallationByOrganization() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-organization.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationByOrganization("bogus"); - testAppInstallation(rootNode, installation); + testAppInstallation(installation); } @Test public void getInstallationByRepository() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-organization.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationByRepository("bogus", "bogus"); - testAppInstallation(rootNode, installation); + testAppInstallation(installation); } @Test public void getInstallationByUser() throws IOException { - JsonNode rootNode = readPayload("/body-mapping-githubapp-installation-by-user.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationByUser("bogus"); - testAppInstallation(rootNode, installation); + testAppInstallation(installation); } @Test public void deleteInstallation() throws IOException { - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationByUser("bogus"); try { installation.deleteInstallation(); @@ -113,9 +93,7 @@ public void deleteInstallation() throws IOException { @Test public void createToken() throws IOException { - JsonNode rootNode = readPayload("/body-githubapp-create-installation-accesstokens.json"); - - GHApp app = github.getApp(); + GHApp app = gitHub.getApp(); GHAppInstallation installation = app.getInstallationByUser("bogus"); Map permissions = new HashMap(); @@ -128,77 +106,43 @@ public void createToken() throws IOException { .repositoryIds(Arrays.asList(111111111)) .create(); - assertThat(installationToken.getToken(), is(rootNode.get("token").asText())); - assertThat(installation.getPermissions(), is(convertToMap(rootNode.get("permissions"), GHPermissionType.class))); - assertThat(installationToken.getRepositorySelection(), - is(convertToEnum(rootNode.get("repository_selection").asText(), GHRepositorySelection.class))); - assertThat(installationToken.getExpiresAt(), is(GitHub.parseDate(rootNode.get("expires_at").asText()))); + assertThat(installationToken.getToken(), is("bogus")); + assertThat(installation.getPermissions(), is(permissions)); + assertThat(installationToken.getRepositorySelection(),is(GHRepositorySelection.SELECTED)); + assertThat(installationToken.getExpiresAt(), is(GitHub.parseDate("2019-08-10T05:54:58Z"))); - ArrayNode repositoriesNode = (ArrayNode) rootNode.get("repositories"); - JsonNode repositoryNode = repositoriesNode.get(0); GHRepository repository = installationToken.getRepositories().get(0); - assertThat(installationToken.getRepositories().size(), is(repositoriesNode.size())); - assertThat(repository.getId(), is(repositoryNode.get("id").asLong())); - assertThat(repository.getName(), is(repositoryNode.get("name").asText())); + assertThat(installationToken.getRepositories().size(), is(1)); + assertThat(repository.getId(), is((long) 111111111)); + assertThat(repository.getName(), is("bogus")); } - private void testAppInstallation(JsonNode installationNode, GHAppInstallation appInstallation) throws IOException { + private void testAppInstallation(GHAppInstallation appInstallation) throws IOException { Map appPermissions = appInstallation.getPermissions(); GHUser appAccount = appInstallation.getAccount(); - JsonNode accountNode = installationNode.get("account"); - JsonNode permissionsNode = installationNode.get("permissions"); - - assertThat(appInstallation.id, is(installationNode.get("id").asLong())); - assertThat(appAccount.id, is(accountNode.get("id").asLong())); - assertThat(appAccount.login, is(accountNode.get("login").asText())); - assertThat(appInstallation.getRepositorySelection(), - is(convertToEnum(installationNode.get("repository_selection").asText(), GHRepositorySelection.class))); - assertThat(appInstallation.getAccessTokenUrl(), is(installationNode.get("access_tokens_url").asText())); - assertThat(appInstallation.getRepositoriesUrl(), is(installationNode.get("repositories_url").asText())); - assertThat(appInstallation.getAppId(), is(installationNode.get("app_id").asLong())); - assertThat(appInstallation.getTargetId(), is(installationNode.get("target_id").asLong())); - assertThat(appInstallation.getTargetType(), - is(convertToEnum(installationNode.get("target_type").asText(), GHTargetType.class))); - assertThat(appPermissions, is(convertToMap(permissionsNode, GHPermissionType.class))); - - List events = convertToEnumList((ArrayNode) installationNode.get("events"), GHEvent.class); + + assertThat(appInstallation.id, is((long) 11111111)); + assertThat(appAccount.id, is((long) 111111111)); + assertThat(appAccount.login, is("bogus")); + assertThat(appInstallation.getRepositorySelection(), is(GHRepositorySelection.SELECTED)); + assertThat(appInstallation.getAccessTokenUrl(), endsWith("/app/installations/11111111/access_tokens")); + assertThat(appInstallation.getRepositoriesUrl(), endsWith("/installation/repositories")); + assertThat(appInstallation.getAppId(), is((long) 11111)); + assertThat(appInstallation.getTargetId(), is((long) 111111111)); + assertThat(appInstallation.getTargetType(), is(GHTargetType.ORGANIZATION)); + + Map permissionsMap = new HashMap(); + permissionsMap.put("checks", GHPermissionType.WRITE); + permissionsMap.put("pull_requests", GHPermissionType.WRITE); + permissionsMap.put("contents", GHPermissionType.READ); + permissionsMap.put("metadata", GHPermissionType.READ); + assertThat(appPermissions, is(permissionsMap)); + + List events = Arrays.asList(GHEvent.PULL_REQUEST, GHEvent.PUSH); assertThat(appInstallation.getEvents(), containsInAnyOrder(events.toArray(new GHEvent[0]))); - assertThat(appInstallation.getCreatedAt(), is(GitHub.parseDate(installationNode.get("created_at").asText()))); - assertThat(appInstallation.getUpdatedAt(), is(GitHub.parseDate(installationNode.get("updated_at").asText()))); + assertThat(appInstallation.getCreatedAt(), is(GitHub.parseDate("2019-07-04T01:19:36.000Z"))); + assertThat(appInstallation.getUpdatedAt(), is(GitHub.parseDate("2019-07-30T22:48:09.000Z"))); assertNull(appInstallation.getSingleFileName()); } - private JsonNode readPayload(String relativeFilePath) throws IOException { - String payload = "/api/__files/".concat(relativeFilePath); - return new ObjectMapper().readTree(this.getClass().getResourceAsStream(payload)); - } - - private > List convertToEnumList(ArrayNode jsonValues, Class valueType) { - List retList = new ArrayList(jsonValues.size()); - for (int i = 0; i < jsonValues.size(); i++) { - retList.add(convertToEnum(jsonValues.get(i).asText(), valueType)); - } - return retList; - } - - private > Map convertToMap(JsonNode jsonNode, Class valueType) { - Map retMap = new HashMap(jsonNode.size()); - Iterator iterator = jsonNode.fieldNames(); - while (iterator.hasNext()) { - String current = iterator.next(); - retMap.put(current, convertToEnum(jsonNode.get(current).asText(), valueType)); - } - return retMap; - } - - private > T convertToEnum(String text, Class valueType) { - // by convention Java constant names are upper cases, but github uses - // lower-case constants. GitHub also uses '-', which in Java we always - // replace by '_' - String value = text.toUpperCase(Locale.ENGLISH).replace('-', '_'); - // special treatment this sdk has provided certain enums with - if (value.equals("*")) value = "ALL"; - return Enum.valueOf(valueType, value); - } - } diff --git a/src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-githubapp-create-installation-accesstokens.json similarity index 100% rename from src/test/resources/api/__files/body-githubapp-create-installation-accesstokens.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-githubapp-create-installation-accesstokens.json diff --git a/src/test/resources/api/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-mapping-githubapp-app.json similarity index 100% rename from src/test/resources/api/__files/body-mapping-githubapp-app.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-mapping-githubapp-app.json diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-mapping-githubapp-installation-by-user.json similarity index 100% rename from src/test/resources/api/__files/body-mapping-githubapp-installation-by-user.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/__files/body-mapping-githubapp-installation-by-user.json diff --git a/src/test/resources/api/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-app.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-app.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-app.json diff --git a/src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-create-installation-accesstokens.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-create-installation-accesstokens.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-create-installation-accesstokens.json diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-installation-by-user.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-installation-by-user.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/createToken/mappings/mapping-githubapp-installation-by-user.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-installation-by-user.json similarity index 100% rename from src/test/resources/api/__files/body-mapping-githubapp-installation-by-id.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/__files/body-mapping-githubapp-installation-by-user.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-delete-installation.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-delete-installation.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-delete-installation.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-delete-installation.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-installation-by-user.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-installation-by-user.json new file mode 100644 index 0000000000..573705fde7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/deleteInstallation/mappings/mapping-githubapp-installation-by-user.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/users/bogus/installation", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-user.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-installation-by-id.json similarity index 100% rename from src/test/resources/api/__files/body-mapping-githubapp-installation-by-organization.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/__files/body-mapping-githubapp-installation-by-id.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-installation-by-id.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-installation-by-id.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationById/mappings/mapping-githubapp-installation-by-id.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-installation-by-organization.json similarity index 100% rename from src/test/resources/api/__files/body-mapping-githubapp-installation-by-repository.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/__files/body-mapping-githubapp-installation-by-organization.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-installation-by-organization.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-installation-by-organization.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByOrganization/mappings/mapping-githubapp-installation-by-organization.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-installation-by-repository.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-installation-by-repository.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/__files/body-mapping-githubapp-installation-by-repository.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-installation-by-repository.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-installation-by-repository.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByRepository/mappings/mapping-githubapp-installation-by-repository.json diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-installation-by-user.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-installation-by-user.json new file mode 100644 index 0000000000..8975c0c55d --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/__files/body-mapping-githubapp-installation-by-user.json @@ -0,0 +1,43 @@ +{ + "id": 11111111, + "account": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "repository_selection": "selected", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "repositories_url": "https://api.github.com/installation/repositories", + "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", + "app_id": 11111, + "target_id": 111111111, + "target_type": "Organization", + "permissions": { + "checks": "write", + "pull_requests": "write", + "contents": "read", + "metadata": "read" + }, + "events": [ + "pull_request", + "push" + ], + "created_at": "2019-07-04T01:19:36.000Z", + "updated_at": "2019-07-30T22:48:09.000Z", + "single_file_name": null +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-installation-by-user.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-installation-by-user.json new file mode 100644 index 0000000000..573705fde7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getInstallationByUser/mappings/mapping-githubapp-installation-by-user.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/users/bogus/installation", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-installation-by-user.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-app.json new file mode 100644 index 0000000000..d36be086d7 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-app.json @@ -0,0 +1,41 @@ +{ + "id": 11111, + "node_id": "MDM6QXBwMzI2MTY=", + "owner": { + "login": "bogus", + "id": 111111111, + "node_id": "asdfasdfasdf", + "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/bogus", + "html_url": "https://github.com/bogus", + "followers_url": "https://api.github.com/users/bogus/followers", + "following_url": "https://api.github.com/users/bogus/following{/other_user}", + "gists_url": "https://api.github.com/users/bogus/gists{/gist_id}", + "starred_url": "https://api.github.com/users/bogus/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/bogus/subscriptions", + "organizations_url": "https://api.github.com/users/bogus/orgs", + "repos_url": "https://api.github.com/users/bogus/repos", + "events_url": "https://api.github.com/users/bogus/events{/privacy}", + "received_events_url": "https://api.github.com/users/bogus/received_events", + "type": "Organization", + "site_admin": false + }, + "name": "Bogus-Development", + "description": "", + "external_url": "https://bogus.domain.com", + "html_url": "https://github.com/apps/bogus-development", + "created_at": "2019-06-10T04:21:41Z", + "updated_at": "2019-06-10T04:21:41Z", + "permissions": { + "checks": "write", + "contents": "read", + "metadata": "read", + "pull_requests": "write" + }, + "events": [ + "pull_request", + "push" + ], + "installations_count": 1 +} \ No newline at end of file diff --git a/src/test/resources/api/__files/body-mapping-githubapp-installations.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-installations.json similarity index 93% rename from src/test/resources/api/__files/body-mapping-githubapp-installations.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-installations.json index dfda131a9c..d81bc3786e 100644 --- a/src/test/resources/api/__files/body-mapping-githubapp-installations.json +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/__files/body-mapping-githubapp-installations.json @@ -3,7 +3,7 @@ "id": 11111111, "account": { "login": "bogus", - "id": 111111111, + "id": 111111111, "node_id": "asdfasdfasdf", "avatar_url": "https://avatars2.githubusercontent.com/u/111111111?v=4", "gravatar_id": "", @@ -22,7 +22,7 @@ "site_admin": false }, "repository_selection": "selected", - "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", + "access_tokens_url": "https://api.github.com/app/installations/11111111/access_tokens", "repositories_url": "https://api.github.com/installation/repositories", "html_url": "https://github.com/organizations/bogus/settings/installations/11111111", "app_id": 11111, diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-app.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-app.json new file mode 100644 index 0000000000..999f4c8286 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-app.json @@ -0,0 +1,34 @@ +{ + "request": { + "url": "/app", + "method": "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/vnd.github.machine-man-preview+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "body-mapping-githubapp-app.json", + "headers": { + "Server": "GitHub.com", + "Date": "Fri, 09 Aug 2019 05:36:38 GMT", + "Content-Type": "application/json; charset=utf-8", + "Status": "200 OK", + "Cache-Control": "public, max-age=60, s-maxage=60", + "Vary": ["Accept","Accept-Encoding"], + "ETag": "W/\"01163b1a237898d328ed56cd0e9aefca\"", + "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": "*", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "deny", + "X-XSS-Protection": "1; mode=block", + "X-GitHub-Request-Id": "E0C4:3088:300C54:3ACB77:5D4D0666" + } + } +} \ No newline at end of file diff --git a/src/test/resources/api/mappings/mapping-githubapp-installations.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-installations.json similarity index 100% rename from src/test/resources/api/mappings/mapping-githubapp-installations.json rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/listInstallations/mappings/mapping-githubapp-installations.json From 59a973970e03f0943fa28a7b746f2578305afbf5 Mon Sep 17 00:00:00 2001 From: PauloMigAlmeida Date: Sun, 15 Sep 2019 10:57:22 +1200 Subject: [PATCH 09/10] Remove duplicated wiremock dependency Signed-off-by: PauloMigAlmeida --- pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 76b62c646d..518233b514 100644 --- a/pom.xml +++ b/pom.xml @@ -182,7 +182,7 @@ javax.servlet @@ -221,12 +221,6 @@ 3.0.0 test - - com.github.tomakehurst - wiremock-standalone - 2.24.1 - test - com.github.spotbugs spotbugs-annotations From 0f7a5f1c0802bed5b44d7e803e45ec329df0d321 Mon Sep 17 00:00:00 2001 From: PauloMigAlmeida Date: Fri, 4 Oct 2019 11:59:58 +1300 Subject: [PATCH 10/10] Merge from upstream; Remove servlet exclusion due to previous JDK version; Signed-off-by: PauloMigAlmeida --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index 55a774a204..937eb7951c 100644 --- a/pom.xml +++ b/pom.xml @@ -181,16 +181,6 @@ org.kohsuke.stapler stapler-jetty 1.1 - - - - javax.servlet - servlet-api - - test