Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

implemented create from manifest action #1647

Merged
merged 9 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/org/kohsuke/github/GHAppFromManifest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.kohsuke.github;

/**
* A GitHub App with the additional attributes returned during its creation.
*
* @author Daniel Baur
* @see GitHub#createAppFromManifest(String)
*/
public class GHAppFromManifest extends GHApp {

private String clientId;
private String clientSecret;
private String webhookSecret;
private String pem;

/**
* Gets the client id
*
* @return the client id
*/
public String getClientId() {
return clientId;
}

/**
* Gets the client secret
*
* @return the client secret
*/
public String getClientSecret() {
return clientSecret;
}

/**
* Gets the webhook secret
*
* @return the webhook secret
*/
public String getWebhookSecret() {
return webhookSecret;
}

/**
* Gets the pem
*
* @return the pem
*/
public String getPem() {
return pem;
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,38 @@ public GHApp getApp() throws IOException {
return createRequest().withPreview(MACHINE_MAN).withUrlPath("/app").fetch(GHApp.class);
}

/**
* Returns the GitHub App identified by the given slug
*
* @param slug
* the slug of the application
* @return the app
* @throws IOException
* the IO exception
* @see <a href="https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-app">Get an app</a>
*/
public GHApp getApp(@Nonnull String slug) throws IOException {
return createRequest().withUrlPath("/apps/" + slug).fetch(GHApp.class);
}

/**
* Creates a GitHub App from a manifest.
*
* @param code
* temporary code returned during the manifest flow
* @return the app
* @throws IOException
* the IO exception
* @see <a href=
* "https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-a-github-app-from-a-manifest">Get an
* app</a>
*/
public GHAppFromManifest createAppFromManifest(@Nonnull String code) throws IOException {
return createRequest().method("POST")
.withUrlPath("/app-manifests/" + code + "/conversions")
.fetch(GHAppFromManifest.class);
}

/**
* Returns the GitHub App Installation associated with the authentication credentials used.
* <p>
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/org/kohsuke/github/GHAppExtendedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.kohsuke.github;

import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

/**
* Tests for the GitHub App Api Test
*
* @author Daniel Baur
*/
public class GHAppExtendedTest extends AbstractGitHubWireMockTest {

private static final String APP_SLUG = "ghapi-test-app-4";

/**
* Gets the GitHub App by its slug.
*
* @throws IOException
* An IOException has occurred.
*/
@Test
public void getAppBySlugTest() throws IOException {
GHApp app = gitHub.getApp(APP_SLUG);

assertThat(app.getId(), is((long) 330762));
assertThat(app.getSlug(), equalTo(APP_SLUG));
assertThat(app.getName(), equalTo("GHApi Test app 4"));
assertThat(app.getExternalUrl(), equalTo("https://github.com/organizations/hub4j-test-org"));
assertThat(app.getHtmlUrl().toString(), equalTo("https://github.com/apps/ghapi-test-app-4"));
assertThat(app.getDescription(), equalTo("An app to test the GitHub getApp(slug) method."));
}

/**
* Tests App creation via the App Manifest Flow.
*
* The used code defined below was only valid for a short time, meaning that you can not replay the test against the
* GitHub API. Use the stored wire snapshot for executing those tests.
*
* @throws IOException
* An IOException has occurred.
*/
@Test
public void createAppByManifestFlowTest() throws IOException {
snapshotNotAllowed();
GHAppFromManifest appFromManifest = gitHub.createAppFromManifest("46fbe5453b245dee21b96753f80eace209a3cf01");

assertThat(appFromManifest.getClientId(), equalTo("Iv1.1c63d0b87c03d42e"));
assertThat(appFromManifest.getWebhookSecret(), equalTo("f4dafa9b05d8248d81f65f0e6cb108cb8bb76a0c"));
assertThat(appFromManifest.getClientSecret(), equalTo("f4b60603e85b3965492b393bca0809a914dcdf18"));
assertThat(appFromManifest.getPem(),
equalTo("-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA4UT2qvDbMK3hQtvrK7wu7y7B6hypYhsXyD6GN22Bcn3JZdSI\nWm/zhRMH/vKwU5r67YKcJCchHVbvLRWNt911r85D0uLMPIjOkdL+cnSOa5yRhTJy\nI/RhZqx8yoXHSSE5ToKwfPAn3hiv8N2gQEsEpWxdycqPOg7paFsAJ5hjstmS09uU\nKwrFcCQdWuidRnwn6bdgGt+bL9dsvRd4RDoP5sZj5pLNo1y8N9DnFvHihd1rQxQS\nIf9sRgGPDLasNkLvMdxKnsDTsufRBmmw72iaTJXc+EVZw2jYKrOjRVechTMEfbRp\nQRVZw9vysT2XhDB9J4bbJ6NopP/c7JC1ihUJfQIDAQABAoIBAQC0DwubVyncnx+O\n8XnoW2KojBczqfU6Fa3MwS1G4KC3gxOX8WmL4DAmDjA1+IY4TYiEkAF+ZEhzyyki\nQDgm3z1SaOyNg/r75941cRExKzkritpGPSw+0PeJuhWFS6kfKw9DUfL/6nXzcIgx\nXvTYbx4nm5bb1KznG0Q1xYc6HvSR3xb3DcXWXkRX6sMEX4J3M/x0PWxPWnDGvlBJ\nQyDgfqpOa6kra5uSm8qoHtb7httwE/a5NZ9P5jeLk3wXaQmCEl4RDEgSGeR4AOf5\nXVTWP936sVA3vBLd6LmddO3ZEE1HZhlb2XWnxCnGSKL4LoFZE7Jhf2Alp32nm0gm\nwsrQoVgBAoGBAPjxzs3Umlle0EZbfJa8c4rFPOJmMkL07aQu8PAAHiNGcbzzfUmK\n7kfNYXktHKB6pjyjkXEQrLCm9wdqCqI70wJ+AVn6E/0Z1ojPALIxdrjQuNS9xjRo\nCUAQqEXe+IWBZVArgy7t3to7XkAHrj+ky96eAhlsb88c9qiWtS7biXPtAoGBAOen\nYgTe8SbWdBRh7mqDgx9eruB6UCOt8BUlb1uFyt1kpCLZVelw1JYs7hq+roTdKds0\ny9pu+E6I7+g6LsVtjkMqf/VXuY0qomf9hbNE9Yj/Tqty5B4xU+gj01MCm5RRln9M\nKGKCeJAPDB5AEmyidPvLbPp5U6Rniu0Ds+AJ0FnRAoGBAMro/bGTuwNhXs4aP+D1\nVhAkWE4JEqq0zQZoJIba8bW683YZ2WMaVMI9y1djx9OeZOVERYYtGzUZwnxOmMBH\nluSPJDbcuXIxn0X/xAd6fdSCfEUbMfUBX5jSevYImfTn1VaVQOX9iQnEHjx+hi7l\n+i5ICFoEotXkO8CKpr+8vbq5AoGAOCfkZAfjb6XHB/XhhOKSk7UxMWuVJ8EPlSC5\nCPe7AMZX37bN08QtVKZZphQZXE38yo3W6QHDoc4iUipgki2HshKIaGI2sdjm+8yC\nb73Ew8wYNwmn8QXGMF0W6mWUb3UDxaIhnBfCwDFVn7Oqg7kyIKPkrCdjNlR/Ygtm\nvGXEozECgYAFpzntJpUdYN4OxutpNXdnTgN0CJ3TECkk/+0xbTHoWNuMpJ5dR/yQ\n7RLxwcu8CqizXCB750jSgHlWk5GF1yAQzFO9ozjx/mxdPp1PxHaeN/5kmx8VjT8W\nL7zhUMfZLeDMpIbQ/3gyq0EUxxHIEJc2Mx42C9/OY/fkEuZPFSEL2A==\n-----END RSA PRIVATE KEY-----\n"));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"id": 330788,
"slug": "ghapi-test-app-5",
"node_id": "A_kwHOAHMfo84ABQwk",
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"name": "GHApi Test app 5",
"description": null,
"external_url": "https://www.example.com",
"html_url": "https://github.com/apps/ghapi-test-app-5",
"created_at": "2023-05-08T09:22:36Z",
"updated_at": "2023-05-08T09:22:36Z",
"client_id": "Iv1.1c63d0b87c03d42e",
"webhook_secret": "f4dafa9b05d8248d81f65f0e6cb108cb8bb76a0c",
"pem": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA4UT2qvDbMK3hQtvrK7wu7y7B6hypYhsXyD6GN22Bcn3JZdSI\nWm/zhRMH/vKwU5r67YKcJCchHVbvLRWNt911r85D0uLMPIjOkdL+cnSOa5yRhTJy\nI/RhZqx8yoXHSSE5ToKwfPAn3hiv8N2gQEsEpWxdycqPOg7paFsAJ5hjstmS09uU\nKwrFcCQdWuidRnwn6bdgGt+bL9dsvRd4RDoP5sZj5pLNo1y8N9DnFvHihd1rQxQS\nIf9sRgGPDLasNkLvMdxKnsDTsufRBmmw72iaTJXc+EVZw2jYKrOjRVechTMEfbRp\nQRVZw9vysT2XhDB9J4bbJ6NopP/c7JC1ihUJfQIDAQABAoIBAQC0DwubVyncnx+O\n8XnoW2KojBczqfU6Fa3MwS1G4KC3gxOX8WmL4DAmDjA1+IY4TYiEkAF+ZEhzyyki\nQDgm3z1SaOyNg/r75941cRExKzkritpGPSw+0PeJuhWFS6kfKw9DUfL/6nXzcIgx\nXvTYbx4nm5bb1KznG0Q1xYc6HvSR3xb3DcXWXkRX6sMEX4J3M/x0PWxPWnDGvlBJ\nQyDgfqpOa6kra5uSm8qoHtb7httwE/a5N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ca0809a914dcdf18",
"permissions": {
"issues": "write",
"checks": "write",
"metadata": "read"
},
"events": [
"issues",
"issue_comment",
"check_suite",
"check_run"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"login": "dbaur",
"id": 7251904,
"node_id": "MDQ6VXNlcjcyNTE5MDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/7251904?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dbaur",
"html_url": "https://github.com/dbaur",
"followers_url": "https://api.github.com/users/dbaur/followers",
"following_url": "https://api.github.com/users/dbaur/following{/other_user}",
"gists_url": "https://api.github.com/users/dbaur/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dbaur/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dbaur/subscriptions",
"organizations_url": "https://api.github.com/users/dbaur/orgs",
"repos_url": "https://api.github.com/users/dbaur/repos",
"events_url": "https://api.github.com/users/dbaur/events{/privacy}",
"received_events_url": "https://api.github.com/users/dbaur/received_events",
"type": "User",
"site_admin": false,
"name": "Daniel Baur",
"company": null,
"blog": "",
"location": "Ulm",
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"public_repos": 48,
"public_gists": 0,
"followers": 7,
"following": 10,
"created_at": "2014-04-10T14:14:43Z",
"updated_at": "2023-04-28T11:26:17Z",
"private_gists": 3,
"total_private_repos": 13,
"owned_private_repos": 13,
"disk_usage": 104958,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"id": "14af1029-56b1-4d4b-9579-c2a30a4df4c4",
"name": "app-manifests_46fbe5453b245dee21b96753f80eace209a3cf01_conversions",
"request": {
"url": "/app-manifests/46fbe5453b245dee21b96753f80eace209a3cf01/conversions",
"method": "POST",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
},
"bodyPatterns": [
{
"equalToJson": "{}",
"ignoreArrayOrder": true,
"ignoreExtraElements": false
}
]
},
"response": {
"status": 201,
"bodyFileName": "app-manifests_46fbe5453b245dee21b96753f80eace209a3cf01_conversions-2.json",
"headers": {
"Server": "GitHub.com",
"Date": "Mon, 08 May 2023 09:22:37 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "\"11658fb48526e56c552184ab239fde425aef041a1d48fce2333682009b178a2c\"",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "",
"github-authentication-token-expiration": "2023-06-07 08:27:57 UTC",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4999",
"X-RateLimit-Reset": "1683541357",
"X-RateLimit-Used": "1",
"X-RateLimit-Resource": "integration_manifest",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "CC01:67BE:362DA52:36DD95C:6458BF5C"
}
},
"uuid": "14af1029-56b1-4d4b-9579-c2a30a4df4c4",
"persistent": true,
"insertionIndex": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": "e173459b-205e-447b-9c70-70bddd564b12",
"name": "user",
"request": {
"url": "/user",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "application/vnd.github.v3+json"
}
}
},
"response": {
"status": 200,
"bodyFileName": "user-1.json",
"headers": {
"Server": "GitHub.com",
"Date": "Mon, 08 May 2023 09:22:35 GMT",
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"ETag": "W/\"ed2b1866194223c334b01088179c15c223bc73dc80a5611a2dd5df357b0f0b30\"",
"Last-Modified": "Fri, 28 Apr 2023 11:26:17 GMT",
"X-OAuth-Scopes": "admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
"X-Accepted-OAuth-Scopes": "",
"github-authentication-token-expiration": "2023-06-07 08:27:57 UTC",
"X-GitHub-Media-Type": "github.v3; format=json",
"x-github-api-version-selected": "2022-11-28",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4960",
"X-RateLimit-Reset": "1683538171",
"X-RateLimit-Used": "40",
"X-RateLimit-Resource": "core",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "0",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "D3E6:CDC9:7C734B0:7DDAE36:6458BF5B"
}
},
"uuid": "e173459b-205e-447b-9c70-70bddd564b12",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"id": 330762,
"slug": "ghapi-test-app-4",
"node_id": "A_kwHOAHMfo84ABQwK",
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"name": "GHApi Test app 4",
"description": "An app to test the GitHub getApp(slug) method.",
"external_url": "https://github.com/organizations/hub4j-test-org",
"html_url": "https://github.com/apps/ghapi-test-app-4",
"created_at": "2023-05-08T08:32:35Z",
"updated_at": "2023-05-08T08:32:35Z",
"permissions": {},
"events": []
}
Loading