Repository: hub4j/github-api
Pull request #1525 (2022-09-22 12:55:20)

Add GHApp#getSlug
# Description

`getSlug()` exposes the `slug` property of the GitHub app, e.g. `ghapi-test-app-1`.
See "Response schema" in https://docs.github.com/en/rest/apps/apps#get-the-authenticated-app.

# Before submitting a PR:

- [X] Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [X] Add JavaDocs and other comments as appropriate. Consider including links in comments to relevant documentation on https://docs.github.com/en/rest .  
- [X] Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [X] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
- [X] Push your changes to a branch other than `main`. You will create your PR from that branch.

# When creating a PR: 

- [X] Fill in the "Description" above with clear summary of the changes. This includes:
  - [X] If this PR fixes one or more issues, include "Fixes #<issue number>" lines for each issue. 
  - [X] Provide links to relevant documentation on https://docs.github.com/en/rest where possible.
- [X] All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
- [X] Enable "Allow edits from maintainers".



Patch:
diff --git a/src/main/java/org/kohsuke/github/GHApp.java b/src/main/java/org/kohsuke/github/GHApp.java
index 2dbd69726..fefdeee7f 100644
--- a/src/main/java/org/kohsuke/github/GHApp.java
+++ b/src/main/java/org/kohsuke/github/GHApp.java
@@ -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;
@@ -60,6 +61,15 @@ public class GHApp extends GHObject {
         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.
      *


Test patch:
diff --git a/src/test/java/org/kohsuke/github/GHAppTest.java b/src/test/java/org/kohsuke/github/GHAppTest.java
index 29e0da23c..90dfe04f1 100644
--- a/src/test/java/org/kohsuke/github/GHAppTest.java
+++ b/src/test/java/org/kohsuke/github/GHAppTest.java
@@ -17,29 +17,34 @@ import static org.junit.Assert.assertThrows;
  *
  * @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
diff --git a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/app-1.json b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/app-1.json
new file mode 100644
index 000000000..47e828ca8
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/app-1.json
@@ -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
+}
\ 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
deleted file mode 100644
index d36be086d..000000000
--- a/src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/__files/body-mapping-githubapp-app.json
+++ /dev/null
@@ -1,41 +0,0 @@
-{
-  "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/app-1.json
similarity index 52%
rename from src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/mapping-githubapp-app.json
rename to src/test/resources/org/kohsuke/github/GHAppTest/wiremock/getGitHubApp/mappings/app-1.json
index 2e7a553f6..162baaec3 100644
--- 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/app-1.json
@@ -1,4 +1,6 @@
 {
+  "id": "5d93739e-0223-463e-9d26-1a9b3b4d1cc9",
+  "name": "app",
   "request": {
     "url": "/app",
     "method": "GET",
@@ -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
 }
\ No newline at end of file