Skip to content
This repository was archived by the owner on Jul 12, 2026. It is now read-only.

Add existing PR detection and update flow - #42

Merged
alissonperez merged 3 commits into
mainfrom
fix/pr-description
Dec 4, 2025
Merged

Add existing PR detection and update flow#42
alissonperez merged 3 commits into
mainfrom
fix/pr-description

Conversation

@alissonperez

Copy link
Copy Markdown
Owner

Ref. [Link]

What was done?

  • Implemented detection of an existing open GitHub pull request for the current branch.
  • Added an update flow that prompts the user to either update the existing PR or cancel instead of always creating a new PR.
  • Introduced helper functions to find and update existing PRs and added error handling for update failures.
  • Removed missing dashes from the PR template area to fix formatting inconsistencies.
  • Updated and extended unit tests to cover the new behaviors (existing PR update and cancel flows) and to ensure previous tests still behave correctly.

How was it done?

  • Added _get_existing_pr(repo, branch_name) to return an open pull request whose head ref matches the branch name, or None if none exists.
  • Added _update_pr(pr, pr_data) to edit the title and body of an existing PR and to surface failures with a printed message and SystemExit(1).
  • Modified create_pr to call _get_existing_pr and, when a PR exists, prompt the user (via inquirer.confirm) to update it. If the user confirms, _update_pr is called; otherwise the operation is canceled.
  • Fixed PR template formatting by removing missing dashes in prdata.py to align with the expected template format.
  • Tests were updated to mock _get_existing_pr where appropriate and new tests were added to validate both the update and cancel flows for existing PRs.

How was it tested?

  • Unit tests updated/added in gpt_pr/test_gh.py:
    • test_create_pr_success and test_create_pr_cancel now patch _get_existing_pr to return None to ensure the original creation paths are exercised.
    • test_create_pr_existing_pr_update: patches _get_existing_pr to return a mock PR object and patches _update_pr; patches inquirer.confirm to simulate user acceptance (execute() -> True); asserts that _update_pr is called once with the existing PR and pr_data.
    • test_create_pr_existing_pr_cancel: patches _get_existing_pr to return a mock PR object and patches _update_pr; patches inquirer.confirm to simulate user decline (execute() -> False); asserts that _update_pr is not called, no new pull is created, and the cancellation message is printed.
  • Tests use mocker, SimpleNamespace, and capsys to simulate GH repo/PR objects, intercept prompts, and capture printed output.
  • Runtime behavior: when updating, create_pr calls _update_pr which edits the PR title and body and prints success or failure; failures raise SystemExit(1) after printing the error message.

Significant changes (summary):

  • New: _get_existing_pr(repo, branch_name)
  • New: _update_pr(pr, pr_data)
  • Modified: create_pr to detect existing PRs and prompt for update
  • Modified: PR template formatting in prdata.py (removed missing dashes)
  • Tests: updated existing tests and added tests for update/cancel flows (gpt_pr/test_gh.py)

Generated by GPT-PR

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @alissonperez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the PR creation workflow by implementing a mechanism to detect existing open pull requests for a given branch. Instead of always creating a new PR, users are now presented with an option to update the existing one or cancel the operation. This change streamlines the PR management process, prevents duplication, and improves the overall user experience by providing more intelligent interaction with GitHub's PR system.

Highlights

  • Existing PR Detection: The system now detects if an open GitHub pull request already exists for the current branch, preventing duplicate PR creation.
  • PR Update Flow: Users are now prompted to either update an existing pull request or cancel the operation, providing more control over PR management.
  • Helper Functions & Error Handling: New helper functions (_get_existing_pr, _update_pr) were introduced to facilitate finding and updating existing PRs, including robust error handling for update failures.
  • PR Template Formatting: Formatting inconsistencies in the PR template were resolved by removing unnecessary dashes in prdata.py.
  • Unit Test Coverage: Unit tests were significantly updated and extended in gpt_pr/test_gh.py to cover the new existing PR update and cancel flows, ensuring the reliability of the new features and existing functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a useful feature to detect and update existing pull requests, preventing the creation of duplicates. The implementation is straightforward and includes corresponding unit tests for the new flows. I've identified a few areas for improvement:

  • The method for finding an existing PR can be made more efficient.
  • The exception handling could be more specific.
  • There's a minor inconsistency in user-facing messages.
    Overall, these are solid changes that improve the tool's usability.

Comment thread gpt_pr/gh.py
Comment thread gpt_pr/gh.py
Comment thread gpt_pr/gh.py
@alissonperez
alissonperez merged commit 10b2d4a into main Dec 4, 2025
1 check passed
@alissonperez
alissonperez deleted the fix/pr-description branch December 4, 2025 12:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant