Repository: hub4j/github-api
Pull request #1401 (2022-03-12 20:59:41)

Added user LDAP information.
# Description

<!-- Describe your change here -->
Changes for #1400 

# Before submitting a PR:

- [ ] 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.
- [ ] Add JavaDocs and other comments as appropriate. Consider including links in comments to relevant documentation on https://docs.github.com/en/rest .  
- [ ] Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [ ] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
- [ ] Push your changes to a branch other than `main`. You will create your PR from that branch.

# When creating a PR: 

- [ ] Fill in the "Description" above with clear summary of the changes. This includes:
  - [ ] If this PR fixes one or more issues, include "Fixes #<issue number>" lines for each issue. 
  - [ ] Provide links to relevant documentation on https://docs.github.com/en/rest where possible.
- [ ] 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."
- [ ] Enable "Allow edits from maintainers".



Patch:
diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java
index 1e36182f0..a46c0161c 100644
--- a/src/main/java/org/kohsuke/github/GHUser.java
+++ b/src/main/java/org/kohsuke/github/GHUser.java
@@ -37,6 +37,8 @@ import static org.kohsuke.github.internal.Previews.INERTIA;
  */
 public class GHUser extends GHPerson {
 
+    protected String ldap_dn;
+
     /**
      * Gets keys.
      *
@@ -242,6 +244,23 @@ public class GHUser extends GHPerson {
                 .toIterable(GHGist[].class, null);
     }
 
+    /**
+     * Gets LDAP information for user.
+     *
+     * @return The LDAP information
+     *
+     * @see <a
+     *      href=https://docs.github.com/en/enterprise-server@3.3/admin/identity-and-access-management/authenticating-users-for-your-github-enterprise-server-instance/using-ldap>Github
+     *      LDAP</a>
+     *
+     * @throws IOException
+     *             the io exception
+     */
+    public Optional<String> getLdapDn() throws IOException {
+        super.populate();
+        return Optional.ofNullable(ldap_dn);
+    }
+
     @Override
     public int hashCode() {
         return login.hashCode();


Test patch:
diff --git a/src/test/java/org/kohsuke/github/GHUserTest.java b/src/test/java/org/kohsuke/github/GHUserTest.java
index d682d1a56..c2446715a 100644
--- a/src/test/java/org/kohsuke/github/GHUserTest.java
+++ b/src/test/java/org/kohsuke/github/GHUserTest.java
@@ -6,6 +6,7 @@ import java.io.IOException;
 import java.util.*;
 
 import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.Matchers.emptyString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.is;
@@ -162,4 +163,10 @@ public class GHUserTest extends AbstractGitHubWireMockTest {
         assertThat(u.getPublicGistCount(), equalTo(4));
         assertThat(u.getPublicRepoCount(), equalTo(96));
     }
+
+    @Test
+    public void verifyLdapdn() throws IOException {
+        GHUser u = gitHub.getUser("kartikpatodi");
+        assertThat(u.getLdapDn().orElse(""), not(emptyString()));
+    }
 }
diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/createAndCountPrivateRepos/__files/user-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/createAndCountPrivateRepos/__files/user-1.json
index 1c08033b3..c446e8a32 100644
--- a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/createAndCountPrivateRepos/__files/user-1.json
+++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/createAndCountPrivateRepos/__files/user-1.json
@@ -16,14 +16,15 @@
   "events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
   "received_events_url": "https://api.github.com/users/kohsuke/received_events",
   "type": "User",
-  "site_admin": false,
+  "site_admin": true,
+  "ldap_dn": "CN=kohsuke,OU=Users,DC=github,DC=com",
   "name": "Sage Pierce",
   "company": "@Vrbo @ExpediaGroup",
   "blog": "",
   "location": null,
   "email": "sapierce@vrbo.com",
   "hireable": true,
-  "bio": "Software engineer with a Masters of Science in Electrical and Computer Engineering out of The University of Texas at Austin.",
+  "bio": "test",
   "public_repos": 9,
   "public_gists": 0,
   "followers": 4,
diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/__files/users_kartikpatodi-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/__files/users_kartikpatodi-1.json
new file mode 100644
index 000000000..11ffa2db9
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/__files/users_kartikpatodi-1.json
@@ -0,0 +1,35 @@
+{
+  "login": "kartikpatodi",
+  "id": 23272937,
+  "node_id": "MDQ6VXNlcjIzMjcyOTM3",
+  "avatar_url": "https://avatars.githubusercontent.com/u/23272937?v=4",
+  "gravatar_id": "",
+  "url": "https://api.github.com/users/kartikpatodi",
+  "html_url": "https://github.com/kartikpatodi",
+  "followers_url": "https://api.github.com/users/kartikpatodi/followers",
+  "following_url": "https://api.github.com/users/kartikpatodi/following{/other_user}",
+  "gists_url": "https://api.github.com/users/kartikpatodi/gists{/gist_id}",
+  "starred_url": "https://api.github.com/users/kartikpatodi/starred{/owner}{/repo}",
+  "subscriptions_url": "https://api.github.com/users/kartikpatodi/subscriptions",
+  "organizations_url": "https://api.github.com/users/kartikpatodi/orgs",
+  "repos_url": "https://api.github.com/users/kartikpatodi/repos",
+  "events_url": "https://api.github.com/users/kartikpatodi/events{/privacy}",
+  "received_events_url": "https://api.github.com/users/kartikpatodi/received_events",
+  "type": "User",
+  "ldap_dn": "CN=kartikpatodi,OU=Users,DC=github,DC=com",
+  "site_admin": false,
+  "name": "Kartik Patodi",
+  "company": null,
+  "blog": "",
+  "location": "Nimbahera, Rajasthan, India",
+  "email": null,
+  "hireable": null,
+  "bio": null,
+  "twitter_username": "kartikpatodi",
+  "public_repos": 12,
+  "public_gists": 0,
+  "followers": 2,
+  "following": 7,
+  "created_at": "2016-11-05T05:01:41Z",
+  "updated_at": "2022-02-24T13:54:34Z"
+}
\ No newline at end of file
diff --git a/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/mappings/users_kartikpatodi-1.json b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/mappings/users_kartikpatodi-1.json
new file mode 100644
index 000000000..e1ae5b74c
--- /dev/null
+++ b/src/test/resources/org/kohsuke/github/GHUserTest/wiremock/verifyLdapdn/mappings/users_kartikpatodi-1.json
@@ -0,0 +1,41 @@
+{
+  "name": "users_kartikpatodi",
+  "request": {
+    "url": "/users/kartikpatodi",
+    "method": "GET",
+    "headers": {
+      "Accept": {
+        "equalTo": "application/vnd.github.v3+json"
+      }
+    }
+  },
+  "response": {
+    "status": 200,
+    "bodyFileName": "users_kartikpatodi-1.json",
+    "headers": {
+      "server": "GitHub.com",
+      "date": "Mon, 04 Apr 2022 19:10:00 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, X-Requested-With",
+      "etag": "W/\"960f568b7a2dd1591a136e36748cc44e\"",
+      "last-modified": "Thu, 24 Feb 2022 13:54:34 GMT",
+      "x-github-media-type": "unknown, github.v3",
+      "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-Ratelimit-Limit": "60",
+      "X-Ratelimit-Remaining": "47",
+      "X-Ratelimit-Reset": "1649100347",
+      "Accept-Ranges": "bytes",
+      "X-GitHub-Request-Id": "45F4:0D15:1B4EE4:373E4C:624B4288"
+    }
+  },
+  "uuid": "39860a04-002b-45da-aae7-70c97031c79e",
+  "persistent": true,
+  "insertionIndex": 1
+}
\ No newline at end of file