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

Add GHApp#getSlug #1525

Merged
merged 2 commits into from Sep 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHApp.java
Expand Up @@ -22,6 +22,7 @@ public class GHApp extends GHObject {

private GHUser owner;
private String name;
private String slug;
private String description;
private String externalUrl;
private Map<String, String> permissions;
Expand Down Expand Up @@ -60,6 +61,15 @@ public String getName() {
return name;
}

/**
* Gets the slug name of the GitHub app.
*
* @return the slug name of the GitHub app
*/
public String getSlug() {
return slug;
}

/**
* Sets name.
*
Expand Down
29 changes: 17 additions & 12 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Expand Up @@ -17,29 +17,34 @@
*
* @author Paulo Miguel Almeida
*/
public class GHAppTest extends AbstractGitHubWireMockTest {
public class GHAppTest extends AbstractGHAppInstallationTest {

protected GitHubBuilder getGitHubBuilder() {
return super.getGitHubBuilder()
// ensure that only JWT will be used against the tests below
.withPassword(null, null)
.withJwtToken("bogus");
// Note that we used to provide a bogus token here and to rely on (apparently) manually crafted/edited
// Wiremock recordings, so most of the tests cannot actually be executed against GitHub without
// relying on the Wiremock recordings.
// Some tests have been updated, though (getGitHubApp in particular).
.withAuthorizationProvider(jwtProvider1);
}

@Test
public void getGitHubApp() throws IOException {
GHApp app = gitHub.getApp();
assertThat(app.getId(), is((long) 11111));
assertThat(app.getOwner().getId(), is((long) 111111111));
assertThat(app.getOwner().login, is("bogus"));
assertThat(app.getName(), is("Bogus-Development"));
assertThat(app.getId(), is((long) 82994));
assertThat(app.getOwner().getId(), is((long) 7544739));
assertThat(app.getOwner().getLogin(), is("hub4j-test-org"));
assertThat(app.getName(), is("GHApi Test app 1"));
assertThat(app.getSlug(), is("ghapi-test-app-1"));
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(GitHubClient.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getUpdatedAt(), is(GitHubClient.parseDate("2019-06-10T04:21:41Z")));
assertThat(app.getPermissions().size(), is(4));
assertThat(app.getEvents().size(), is(2));
assertThat(app.getExternalUrl(), is("http://localhost"));
assertThat(app.getHtmlUrl().toString(), is("https://github.com/apps/ghapi-test-app-1"));
assertThat(app.getCreatedAt(), is(GitHubClient.parseDate("2020-09-30T13:40:56Z")));
assertThat(app.getUpdatedAt(), is(GitHubClient.parseDate("2020-09-30T13:40:56Z")));
assertThat(app.getPermissions().size(), is(2));
assertThat(app.getEvents().size(), is(0));
assertThat(app.getInstallationsCount(), is((long) 1));

// Deprecated methods
Expand Down
@@ -0,0 +1,37 @@
{
"id": 82994,
"slug": "ghapi-test-app-1",
"node_id": "MDM6QXBwODI5OTQ=",
"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 1",
"description": "",
"external_url": "http://localhost",
"html_url": "https://github.com/apps/ghapi-test-app-1",
"created_at": "2020-09-30T13:40:56Z",
"updated_at": "2020-09-30T13:40:56Z",
"permissions": {
"contents": "read",
"metadata": "read"
},
"events": [],
"installations_count": 1
}

This file was deleted.

@@ -1,4 +1,6 @@
{
"id": "5d93739e-0223-463e-9d26-1a9b3b4d1cc9",
"name": "app",
"request": {
"url": "/app",
"method": "GET",
Expand All @@ -10,28 +12,28 @@
},
"response": {
"status": 200,
"bodyFileName": "body-mapping-githubapp-app.json",
"bodyFileName": "app-1.json",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 09 Aug 2019 05:36:38 GMT",
"Date": "Thu, 22 Sep 2022 12:34:57 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"Cache-Control": "public, max-age=60, s-maxage=60",
"Vary": [
"Accept",
"Accept-Encoding"
"Accept-Encoding, Accept, X-Requested-With"
],
"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'",
"ETag": "W/\"662c8ea184a852f605e0c94a9789fe43965f939e16e02ff0b3a8cc1043078a62\"",
"X-GitHub-Media-Type": "github.v3; param=machine-man-preview; format=json",
"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"
"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": "E69F:6970:A871C34:AACF01E:632C5670"
}
}
},
"uuid": "5d93739e-0223-463e-9d26-1a9b3b4d1cc9",
"persistent": true,
"insertionIndex": 1
}