Skip to content

fix: refactor existing PR message format when calling create_pull_req…#2947

Open
Nishthajain7 wants to merge 1 commit into
github:mainfrom
Nishthajain7:issue-2931
Open

fix: refactor existing PR message format when calling create_pull_req…#2947
Nishthajain7 wants to merge 1 commit into
github:mainfrom
Nishthajain7:issue-2931

Conversation

@Nishthajain7

Copy link
Copy Markdown

Summary

Catch the "pull request already exists" 422 from create_pull_request and return a clean message with the existing PR's URL instead of forwarding GitHub's raw, unformatted validation error.

Why

When create_pull_request fails because a PR already exists for the given head/base, the tool currently forwards GitHub's raw API error verbatim (e.g. failed to create pull request: POST .../pulls: 422 Validation Failed [{Resource:PullRequest Field: Code:custom Message:A pull request already exists for owner:branch.}]). This is unreadable and gives the caller no way to find the existing PR without a separate lookup.

Fixes #2931

What changed

  • Added findExistingPullRequest, which detects the specific code:"custom" / "A pull request already exists" 422 shape and calls PullRequests.List (filtered by head/base) to resolve the existing PR
  • Updated CreatePullRequest's error handling: on this specific error, return a structured {id, url, message} result pointing at the existing PR instead of the raw error; all other Create errors are unaffected and still return the original error path

MCP impact

  • No tool or API changes
  • Tool schema or behavior changed
  • New tool added

Prompts tested (tool changes only)

"Create a pull request from test/dup-pr into main" (when a PR already exists for that branch pair) returns the existing PR's number and link instead of an error

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Note: if you're renaming tools, you must add the tool aliases. For more information on how to do so, please refer to the official docs.

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test

Docs

  • Not needed
  • Updated (README / docs / examples)

@Nishthajain7
Nishthajain7 requested a review from a team as a code owner July 26, 2026 15:46
Copilot AI review requested due to automatic review settings July 26, 2026 15:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

failed to create pull request: repeat PR, better error msging

2 participants