Skip to content

Fix lock() and unlock() on GHPullRequest - #2342

Open
Haarolean wants to merge 3 commits into
hub4j:mainfrom
Haarolean:fix/issue-lock-on-pull-request
Open

Haarolean wants to merge 3 commits into
hub4j:mainfrom
Haarolean:fix/issue-lock-on-pull-request

Conversation

@Haarolean

@Haarolean Haarolean commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

GHIssue.lock() and unlock() built their URL from getApiRoute(), which GHPullRequest overrides to /repos/{owner}/{repo}/pulls/{number}. On a pull request they sent PUT/DELETE .../pulls/{number}/lock, which GitHub doesn't serve, so both failed with a 404. The lock endpoints exist only under /issues/{issue_number}/lock and cover pull requests too ("Users with push access can lock an issue or pull request's conversation."). Both methods now use getIssuesApiRoute(), like the other issue-only endpoints in GHIssue (comments, labels, assignees, reactions).

Fixes #2341

Verification

Test data

The WireMock data for lockAndUnlock is synthetic, not a takeSnapshot recording. The org, repo and pull request responses are reused from the markReadyForReviewNonDraft recording (with the title changed). The two lock stubs were written by hand and match real traffic captured against a pull request in another repository: same methods, same /issues/{number}/lock path, empty response bodies. The two GET .../pulls/487 stubs reuse the same pull request body with locked set to true, then false; active_lock_reason stays null, as in the real AppTest#testCreateIssue recording. Happy to swap in a proper recording if preferred.

Prepared with LLM assistance; verified as described above.

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 for details.
  • Add JavaDocs and other comments explaining the behavior. (n/a: no new API)
  • When adding or updating methods that fetch entities, add @link JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest . (n/a: no fetch methods changed)
  • Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See CONTRIBUTING.md for details.
  • Run 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.
  • 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 #" lines for each issue.
    • Provide links to relevant documentation on https://docs.github.com/en/rest where possible. If not including links, explain why not.
  • 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".

GHPullRequest overrides getApiRoute() to /pulls/{n}, so lock() and
unlock() hit /pulls/{n}/lock, which GitHub doesn't serve. Use
getIssuesApiRoute() like the other issue-only endpoints.

Fixes hub4j#2341
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.41%. Comparing base (619c857) to head (460e70c).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2342   +/-   ##
=========================================
  Coverage     85.41%   85.41%           
  Complexity     2568     2568           
=========================================
  Files           242      242           
  Lines          7577     7577           
  Branches        399      399           
=========================================
  Hits           6472     6472           
  Misses          869      869           
  Partials        236      236           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/test/java/org/kohsuke/github/GHPullRequestTest.java

@bitwiseman bitwiseman left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs a test change.
And fix site failure.

Re-fetch the pull request after lock() and unlock() and assert
isLocked(). Add the Javadoc the site build's doclint requires.
@Haarolean
Haarolean requested a review from bitwiseman October 26, 2026 15:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GHIssue.lock() / unlock() 404 on a GHPullRequest: built on the /pulls/{n} route, GitHub only serves /issues/{n}/lock

2 participants