Repository: hub4j/github-api
Pull request #1913 (2024-08-19 11:43:52)

Extend license by spdx id field
# Description

Github offers `spdx_id` field on all license related rest calls. This PR adds this to the `GHLicense` class.

# 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 explaining the behavior. 
- [x] When adding or updating methods that fetch entities, add `@link` JavaDoc entries to the 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. If not including links, explain why not.
- [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".


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/hub4j/github-api/pull/1913?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 81.36%. Comparing base [(`f80d9f8`)](https://app.codecov.io/gh/hub4j/github-api/commit/f80d9f89e23b05064d559ecbf7dc24f4cc437f45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j) to head [(`5cd85dd`)](https://app.codecov.io/gh/hub4j/github-api/commit/5cd85ddc06c92ad4d23063565f39782b7401c81f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##               main    #1913   +/-   ##
=========================================
  Coverage     81.36%   81.36%           
- Complexity     2463     2464    +1     
=========================================
  Files           239      239           
  Lines          7469     7470    +1     
  Branches        401      401           
=========================================
+ Hits           6077     6078    +1     
  Misses         1146     1146           
  Partials        246      246           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/hub4j/github-api/pull/1913?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).


Patch:
diff --git a/src/main/java/org/kohsuke/github/GHLicense.java b/src/main/java/org/kohsuke/github/GHLicense.java
index 89cc08cf2..be9bb48fd 100644
--- a/src/main/java/org/kohsuke/github/GHLicense.java
+++ b/src/main/java/org/kohsuke/github/GHLicense.java
@@ -49,7 +49,7 @@ public class GHLicense extends GHObject {
 
     /** The name. */
     // these fields are always present, even in the short form
-    protected String key, name;
+    protected String key, name, spdxId;
 
     /** The featured. */
     // the rest is only after populated
@@ -85,6 +85,15 @@ public class GHLicense extends GHObject {
         return name;
     }
 
+    /**
+     * Gets SPDX ID.
+     *
+     * @return the spdx id
+     */
+    public String getSpdxId() {
+        return spdxId;
+    }
+
     /**
      * Featured licenses are bold in the new repository drop-down.
      *
diff --git a/src/main/java/org/kohsuke/github/GHUser.java b/src/main/java/org/kohsuke/github/GHUser.java
index b072fc52c..dc25a3fd5 100644
--- a/src/main/java/org/kohsuke/github/GHUser.java
+++ b/src/main/java/org/kohsuke/github/GHUser.java
@@ -275,6 +275,7 @@ public class GHUser extends GHPerson {
      *             on error
      */
     public Date getSuspendedAt() throws IOException {
+        super.populate();
         return GitHubClient.parseDate(suspendedAt);
     }
 


Test patch:
diff --git a/src/test/java/org/kohsuke/github/GHLicenseTest.java b/src/test/java/org/kohsuke/github/GHLicenseTest.java
index 0ae1730b0..fc47e7206 100644
--- a/src/test/java/org/kohsuke/github/GHLicenseTest.java
+++ b/src/test/java/org/kohsuke/github/GHLicenseTest.java
@@ -83,6 +83,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
         GHLicense license = gitHub.getLicense(key);
         assertThat(license, notNullValue());
         assertThat("The name is correct", license.getName(), equalTo("MIT License"));
+        assertThat("The SPDX ID is correct", license.getSpdxId(), is(equalTo("MIT")));
         assertThat("The HTML URL is correct",
                 license.getHtmlUrl(),
                 equalTo(new URL("http://choosealicense.com/licenses/mit/")));
@@ -111,6 +112,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
         GHLicense license = repo.getLicense();
         assertThat("The license is populated", license, notNullValue());
         assertThat("The key is correct", license.getKey(), equalTo("mit"));
+        assertThat("The SPDX ID is correct", license.getSpdxId(), is(equalTo("MIT")));
         assertThat("The name is correct", license.getName(), equalTo("MIT License"));
         assertThat("The URL is correct",
                 license.getUrl(),
@@ -129,6 +131,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
         GHLicense license = repo.getLicense();
         assertThat("The license is populated", license, notNullValue());
         assertThat("The key is correct", license.getKey(), equalTo("mit"));
+        assertThat("The SPDX ID is correct", license.getSpdxId(), is(equalTo("MIT")));
         assertThat("The name is correct", license.getName(), equalTo("MIT License"));
         assertThat("The URL is correct",
                 license.getUrl(),
@@ -148,6 +151,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
         GHLicense license = repo.getLicense();
         assertThat("The license is populated", license, notNullValue());
         assertThat("The key is correct", license.getKey(), equalTo("apache-2.0"));
+        assertThat("The SPDX ID is correct", license.getSpdxId(), is(equalTo("Apache-2.0")));
         assertThat("The name is correct", license.getName(), equalTo("Apache License 2.0"));
         assertThat("The URL is correct",
                 license.getUrl(),
@@ -181,6 +185,7 @@ public class GHLicenseTest extends AbstractGitHubWireMockTest {
         GHLicense license = repo.getLicense();
         assertThat("The license is populated", license, notNullValue());
         assertThat("The key is correct", license.getKey(), equalTo("mit"));
+        assertThat("The SPDX ID is correct", license.getSpdxId(), is(equalTo("MIT")));
         assertThat("The name is correct", license.getName(), equalTo("MIT License"));
         assertThat("The URL is correct",
                 license.getUrl(),