Skip to content

Add GitHub pull request update functionality with branch management#6

Merged
csvenke merged 1 commit intomainfrom
feature/gh-pr-update
Mar 15, 2026
Merged

Add GitHub pull request update functionality with branch management#6
csvenke merged 1 commit intomainfrom
feature/gh-pr-update

Conversation

@csvenke
Copy link
Copy Markdown
Owner

@csvenke csvenke commented Mar 15, 2026

Summary

Adds support for updating existing pull requests and automatic branch upstream management to the GitHub PR command.

Key Changes

New Features

  • PR Update Detection: When creating a PR, the command now checks if a PR already exists and updates it instead of creating a duplicate
  • Automatic Branch Push: Automatically pushes branches with upstream tracking (-u origin branch) when no upstream exists
  • Enhanced PR Command Flow: Retrieves current branch and passes it through to PR creation logic

Implementation Details

  • Added HasUpstream() and PushWithUpstream() methods to gh.Client interface
  • Implemented git commands for upstream detection and branch pushing in RealClient
  • Created CreatePullRequestWithBranch() function that handles branch management and PR creation/update logic
  • Updated gh pr command to pass branch context to PR creation
  • Modified test stub clients to support new interface methods

Behavior

  • If a PR already exists: Updates title and body, returns "Pull request updated successfully"
  • If no PR exists: Creates new PR using standard GitHub CLI
  • Branch handling: Checks for upstream before pushing, skips push if upstream already exists
  • Maintains backward compatibility with CreatePullRequest() wrapper function

Test Coverage

  • Added comprehensive tests for CreatePullRequestWithBranch() covering:
    • Creating new PRs when none exist
    • Updating existing PRs
    • Branch push scenarios (with/without upstream)
    • Error handling for push and upstream check failures
    • Edge cases (empty branch, nil git client)

- Check if PR already exists before creating a new one
- Update existing PR with new title and body if one is found
- Create new PR only when none exists
- Update tests to verify both creation and update paths
@csvenke csvenke changed the title Add support for updating existing pull requests Add GitHub PR update functionality with upstream branch management Mar 15, 2026
@csvenke csvenke changed the title Add GitHub PR update functionality with upstream branch management Add GitHub pull request update functionality with branch management Mar 15, 2026
@csvenke csvenke merged commit 97a30fb into main Mar 15, 2026
4 checks passed
@csvenke csvenke deleted the feature/gh-pr-update branch March 15, 2026 18:06
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.

1 participant