From eed8fd5455a6e48e357a0e9d6a00f850ad612383 Mon Sep 17 00:00:00 2001 From: Stephan van Stekelenburg Date: Wed, 28 Oct 2026 18:01:46 +0100 Subject: [PATCH] feat(pr): open GitHub pull requests in dedicated worktrees --- README.md | 11 ++ docs/clireference.md | 27 +++++ src/Commands/PrCommand.cs | 47 ++++++++ src/Commands/SwitchCommand.cs | 24 +--- src/Configuration/WorktreeConfig.cs | 7 ++ src/Module.cs | 2 + src/Services/GitHubService.cs | 6 +- src/Services/PullRequestWorktreeService.cs | 112 ++++++++++++++++++ .../PullRequestWorktreeServiceTests.cs | 102 ++++++++++++++++ 9 files changed, 312 insertions(+), 26 deletions(-) create mode 100644 src/Commands/PrCommand.cs create mode 100644 src/Services/PullRequestWorktreeService.cs create mode 100644 tests/Services/PullRequestWorktreeServiceTests.cs diff --git a/README.md b/README.md index afaf99e..5aa3648 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,17 @@ Create a new worktree for a feature branch and open it instantly in a new tab: hypr my-feature ``` +### Review a pull request + +Open a GitHub PR in a dedicated worktree, including PRs from forks: + +```bash +hypr pr 123 +hypr pr https://github.com/owner/repository/pull/123 +``` + +Requires an authenticated GitHub CLI (`gh`). Reopening a PR preserves your local work. + ### Cleanup Clean up old worktrees. `hypr` checks if branches are merged or if their PRs are closed. diff --git a/docs/clireference.md b/docs/clireference.md index 12f1cfa..4d059ed 100644 --- a/docs/clireference.md +++ b/docs/clireference.md @@ -47,6 +47,33 @@ Branch names are sanitized for the filesystem - slashes become hyphens. For exam You can customize this with the `directory_pattern` setting (see [Configuration](configuration.md)), which supports template variables like `{repo_name}`, `{branch}`, `{repo_parent_dir}`, and environment variables. For example, to organize all worktrees in a central location: `~/.worktrees/{repo_name}/{branch}`. +## `hypr pr ` + +Open a GitHub pull request in its own worktree. Requires the GitHub CLI (`gh`), +authenticated with access to the repository, and Git access to the configured remote. + +```bash +hypr pr 123 +hypr pr https://github.com/owner/repository/pull/123 +hypr pr 123 --terminal vscode --after-init "npm test" -y +``` + +The PR's base repository must match a configured remote. Forked PRs are fetched +through the base repository's PR ref, so no fork remote is needed. A dedicated +local branch named `pr-123` keeps review work separate from the contributor's branch. +An unrelated existing branch with that name is rejected. + +Running the command again opens the existing worktree and preserves local commits +and uncommitted changes. It does not update the branch to the latest PR revision. +The existing create hooks and session initialization settings apply. + +| Option | Description | +| --- | --- | +| `--dir ` | Override the directory pattern when creating a worktree. | +| `--terminal ` | Override the terminal mode. | +| `--after-init