Repository navigation
Conversation
getCommit() now takes the repository and throws IOException with the message "Repository information is unavailable for this commit pointer" when it is null. Javadoc on getCommit() and getRepository() states that the repository can be null and that getCommit() throws IOException in that case. A WireMock test stubs a pull request whose head repo is JSON null, then asserts getRepository() is null and that getCommit() throws that IOException. Fixes hub4j#2035
|
This looks like an exact duplicate of #2265 and I commented at #2265 (comment) that this wasn't a fix. It just replaces NPE with IOE. |
When the head repository of a pull request has been deleted, GitHub reports head.repo as null, but the head commit is still reachable in the base repository. GHPullRequest now binds its head and base pointers to itself, and getCommit() falls back to the pull request's repository when the pointer has none. Only a pointer with neither still throws. The test replays checkstyle/checkstyle#1, the case from the issue. Fixes hub4j#2035
|
@rnveach You're right. The first version only swapped the NPE for an IOException, which is the same thing #2265 did. I've reworked it in 90e9ae6 so getCommit() actually returns the commit. When a fork is deleted, GitHub sends So now The new test is a WireMock snapshot of checkstyle/checkstyle#1, your example from the issue. It checks that |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2340 +/- ##
============================================
+ Coverage 85.41% 85.45% +0.03%
- Complexity 2568 2576 +8
============================================
Files 242 242
Lines 7577 7584 +7
Branches 399 401 +2
============================================
+ Hits 6472 6481 +9
+ Misses 869 867 -2
Partials 236 236 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Codecov reported three partial branches on this PR: the null checks in GHPullRequest.getHead()/getBase() and the repository check in GHCommitPointer.getCommit(). Add a base-pointer getCommit() case that resolves through the base repository, and a test for a pull request whose head and base are unset. Production code is unchanged.
|
Added tests in 9ce33d1 for the three partial branches Codecov flagged: a base-pointer |
Description
When a pull request's head fork has been deleted, GitHub returns
head.repoas null, andGHCommitPointer.getCommit()threw a NullPointerException because it calledgetRepository().getCommit(getSha()).The head commit is still reachable in the base repository, since GitHub keeps pull request commits there.
GHPullRequest.getHead()andgetBase()now link each pointer back to its pull request, andgetCommit()looks the SHA up in the pull request's repository when the pointer has none.getRepository()still returns null in that case, and its javadoc says so. An IOException is left only for a pointer with neither a repository nor a pull request.GHCommitPointerTest.getCommitFromDeletedHeadRepositoryreplays a snapshot of checkstyle/checkstyle#1, the example from the issue, and checks that the head repository is null and thatgetCommit()returns 4889a777.GHCommitPointerTest,GHPullRequestTest,GHEventPayloadTestandArchTestspass, andspotless:checkandclean install -DskipTestspass.Fixes #2035
Before submitting a PR:
@linkJavaDoc entries to the relevant documentation on https://docs.github.com/en/rest .mvn -D enable-ci clean install site "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED"locally. If this command doesn't succeed, your change will not pass CI.main. You will create your PR from that branch.When creating a PR: