Skip to content

refactor(lib): use runGitCommand helper instead of Bun.spawn#272

Merged
amondnet merged 4 commits into
mainfrom
267-refactor-bunspawn-to-rungitcommand-helper-in-git-workflowts-and-repo-managerts
Jul 5, 2026
Merged

refactor(lib): use runGitCommand helper instead of Bun.spawn#272
amondnet merged 4 commits into
mainfrom
267-refactor-bunspawn-to-rungitcommand-helper-in-git-workflowts-and-repo-managerts

Conversation

@amondnet

@amondnet amondnet commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace direct Bun.spawn calls with the centralized runGitCommand helper in git-workflow.ts and repo-manager.ts for consistency, testability, and maintainability.

Changes

src/lib/git-workflow.ts:

  • getAllLinkedBranches() - Convert to use runGitCommand for git and gh api calls
  • startDevelopWorkflow() - Convert to use runGitCommand for gh issue develop
  • fetchBranch() - Convert to use runGitCommand for git fetch and branch operations

src/lib/repo-manager.ts:

  • isInGitRepo() - Convert to use runGitCommand for git rev-parse
  • getGitDir() - Convert to use runGitCommand for git rev-parse
  • cloneBareRepo() - Convert to use runGitCommand for gh repo clone
  • getCurrentRepoInfo() - Convert to use runGitCommand for gh repo view

Benefits:

  • Consistency: All git commands use the same execution pattern
  • Testability: Easier to mock in tests (single point of mocking)
  • Maintainability: Centralized error handling and logging
  • Debugging: Unified command execution for easier debugging

Test Plan

  • All tests pass (798/798)
  • Type checking passes
  • Linting passes
  • Pure refactoring - no behavior changes

Related Issues

Closes #267


Summary by cubic

Refactored all git/gh CLI calls in git-workflow.ts, git-workflow-worktree.ts, and repo-manager.ts to use the shared runCliCommand helper (renamed from runGitCommand) for consistency and easier testing. Removed dead code in getAllLinkedBranches, hardened isInGitRepo/getGitDir and cloneBareRepo/getCurrentRepoInfo error handling, and restored the .please/**/*.md ESLint ignore; addresses #267 with no behavior changes.

Written for commit acbec2e. Summary will update on new commits.

Replace direct Bun.spawn calls with the centralized runGitCommand helper
in git-workflow.ts and repo-manager.ts for consistency with the codebase.

- getAllLinkedBranches(): use runGitCommand for git and gh api calls
- startDevelopWorkflow(): use runGitCommand for gh issue develop
- fetchBranch(): use runGitCommand for git fetch and branch operations
- isInGitRepo(): use runGitCommand for git rev-parse
- getGitDir(): use runGitCommand for git rev-parse
- cloneBareRepo(): use runGitCommand for gh repo clone
- getCurrentRepoInfo(): use runGitCommand for gh repo view

Issue: #267
@amondnet amondnet linked an issue Feb 5, 2026 that may be closed by this pull request
10 tasks
@vercel

vercel Bot commented Feb 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gh-please Ready Ready Preview, Comment Jul 5, 2026 10:48am

Request Review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @amondnet, 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 refactors how external Git and GitHub CLI commands are executed within the application. By introducing and utilizing a dedicated runGitCommand helper, the changes aim to standardize command invocation, streamline error handling, and simplify output parsing, leading to a more robust and easier-to-maintain codebase.

Highlights

  • Centralized Git Command Execution: Replaced direct Bun.spawn calls with a new runGitCommand helper function across git-workflow.ts and repo-manager.ts.
  • Improved Code Quality: This refactoring enhances consistency, testability, maintainability, and debugging by centralizing the logic for executing Git and GitHub CLI commands.
Changelog
  • src/lib/git-workflow.ts
    • Imported runGitCommand from ./git-exec.
    • Updated getAllLinkedBranches() to use runGitCommand for git rev-parse and gh api calls, simplifying process execution and output handling.
    • Updated startDevelopWorkflow() to use runGitCommand for gh issue develop commands, centralizing error handling and output parsing.
    • Updated fetchBranch() to use runGitCommand for git fetch and git branch operations, consolidating command execution logic.
  • src/lib/repo-manager.ts
    • Imported runGitCommand from ./git-exec.
    • Updated isInGitRepo() to use runGitCommand for git rev-parse --git-dir.
    • Updated getGitDir() to use runGitCommand for git rev-parse --absolute-git-dir, simplifying output retrieval and error checking.
    • Updated cloneBareRepo() to use runGitCommand for gh repo clone commands, centralizing error handling.
    • Updated getCurrentRepoInfo() to use runGitCommand for gh repo view commands, improving consistency in command execution and JSON output parsing.
Activity
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 is an excellent refactoring to centralize git command execution with the runGitCommand helper. Replacing direct Bun.spawn calls greatly improves consistency, testability, and maintainability. The changes in git-workflow.ts and repo-manager.ts are clean and effective. I've identified one minor opportunity for cleanup in git-workflow.ts where the refactoring has highlighted some redundant code. Overall, this is a valuable improvement to the codebase.

Comment thread src/lib/git-workflow.ts Outdated
Remove redundant git command and check that was ineffective since
the code unconditionally returns empty array regardless of outcome.

Co-authored-by: gemini-code-assist[bot] <162626009+gemini-code-assist[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

@sonarqubecloud

sonarqubecloud Bot commented Feb 5, 2026

Copy link
Copy Markdown

Restore the .please/**/*.md eslint ignore that exists on main but was
missing on this branch, fixing the lint check.

Wrap runGitCommand calls in isInGitRepo/getGitDir with try/catch so a
subprocess spawn failure returns false/null instead of throwing,
matching their documented boolean/nullable contract and fixing the
Unit Tests check failure surfaced in CI at repo-manager.ts:55.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@amondnet, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e9d0e1da-11b4-4ddd-89a3-b73a4a59e5a6

📥 Commits

Reviewing files that changed from the base of the PR and between 8bece18 and acbec2e.

📒 Files selected for processing (7)
  • eslint.config.js
  • src/lib/git-exec.ts
  • src/lib/git-workflow-worktree.ts
  • src/lib/git-workflow.ts
  • src/lib/repo-manager.ts
  • test/lib/git-workflow-worktree.preload.ts
  • test/lib/git-workflow-worktree.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 267-refactor-bunspawn-to-rungitcommand-helper-in-git-workflowts-and-repo-managerts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 26.47059% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/lib/repo-manager.ts 17.14% 29 Missing ⚠️
src/lib/git-workflow.ts 4.76% 20 Missing ⚠️
src/lib/git-exec.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codacy-production

codacy-production Bot commented Jul 5, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · -8 duplication

Metric Results
Complexity 4
Duplication -8

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown

Greptile Summary

This PR migrates all Bun.spawn call sites in git-workflow.ts and repo-manager.ts to the centralized runCliCommand helper (renamed from runGitCommand to reflect its use with both git and gh CLI), and restores a missing ESLint ignore for .please/**/*.md.

  • src/lib/git-exec.ts: Renamed runGitCommandrunCliCommand with an updated doc comment; implementation is unchanged.
  • src/lib/git-workflow.ts / src/lib/repo-manager.ts: Replaced ad-hoc Bun.spawn blocks with runCliCommand; removed genuinely dead code in getAllLinkedBranches; added try/catch guards in isInGitRepo and getGitDir (and wraps for cloneBareRepo/getCurrentRepoInfo) to handle spawn-level failures cleanly.
  • src/lib/git-workflow-worktree.ts and tests updated to match the rename.

Confidence Score: 5/5

Safe to merge — pure refactoring with no behavior changes and all 798 tests passing.

Every changed call site is a mechanical replacement of an inline Bun.spawn block with the equivalent runCliCommand helper, which uses the same Bun.spawn internally. The renamed export (runGitCommand → runCliCommand) is verified complete — no stale callers remain in the codebase. Dead code removal in getAllLinkedBranches is accurate (the old block always returned [] regardless of the git-check result). Error handling is now more consistent across the file, and the ESLint ignore restoration is a straightforward CI fix.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/git-exec.ts Renamed runGitCommand → runCliCommand with updated JSDoc; implementation unchanged. Export is now consistent with all callers.
src/lib/git-workflow.ts Replaced three Bun.spawn blocks with runCliCommand; removed dead git-repo-check code in getAllLinkedBranches (the block returned [] either way); behavior preserved.
src/lib/repo-manager.ts All Bun.spawn calls replaced with runCliCommand; isInGitRepo and getGitDir gain try/catch for spawn-level errors; cloneBareRepo and getCurrentRepoInfo wrap the spawn call in try/catch and rethrow, consistent with the rest of the file.
src/lib/git-workflow-worktree.ts Mechanical rename of runGitCommand → runCliCommand across all call sites; logic unchanged.
eslint.config.js Restores the .please/**/*.md ESLint ignore to prevent CI failures from linting illustrative code blocks in planning documents.
test/lib/git-workflow-worktree.preload.ts Mock module export updated from runGitCommand to runCliCommand to match the renamed helper; test coverage unaffected.
test/lib/git-workflow-worktree.test.ts Doc comment updated to reference runCliCommand; no logic changes.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant git_workflow as git-workflow.ts
    participant repo_manager as repo-manager.ts
    participant git_exec as git-exec.ts (runCliCommand)
    participant CLI as git / gh CLI

    Caller->>git_workflow: getAllLinkedBranches(issueNumber, repo)
    git_workflow->>git_exec: runCliCommand([gh, api, graphql, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>git_workflow: GitResult
    git_workflow-->>Caller: string[]

    Caller->>git_workflow: startDevelopWorkflow(issueNumber, options)
    git_workflow->>git_exec: runCliCommand([gh, issue, develop, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>git_workflow: GitResult
    git_workflow-->>Caller: branchName

    Caller->>repo_manager: isInGitRepo()
    repo_manager->>git_exec: runCliCommand([git, rev-parse, --git-dir])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{exitCode}"
    git_exec-->>repo_manager: GitResult
    repo_manager-->>Caller: boolean

    Caller->>repo_manager: cloneBareRepo(owner, repo)
    repo_manager->>git_exec: runCliCommand([gh, repo, clone, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>repo_manager: GitResult
    repo_manager-->>Caller: bareRepoPath
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant git_workflow as git-workflow.ts
    participant repo_manager as repo-manager.ts
    participant git_exec as git-exec.ts (runCliCommand)
    participant CLI as git / gh CLI

    Caller->>git_workflow: getAllLinkedBranches(issueNumber, repo)
    git_workflow->>git_exec: runCliCommand([gh, api, graphql, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>git_workflow: GitResult
    git_workflow-->>Caller: string[]

    Caller->>git_workflow: startDevelopWorkflow(issueNumber, options)
    git_workflow->>git_exec: runCliCommand([gh, issue, develop, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>git_workflow: GitResult
    git_workflow-->>Caller: branchName

    Caller->>repo_manager: isInGitRepo()
    repo_manager->>git_exec: runCliCommand([git, rev-parse, --git-dir])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{exitCode}"
    git_exec-->>repo_manager: GitResult
    repo_manager-->>Caller: boolean

    Caller->>repo_manager: cloneBareRepo(owner, repo)
    repo_manager->>git_exec: runCliCommand([gh, repo, clone, ...])
    git_exec->>CLI: Bun.spawn(args)
    CLI-->>git_exec: "{stdout, stderr, exitCode}"
    git_exec-->>repo_manager: GitResult
    repo_manager-->>Caller: bareRepoPath
Loading

Reviews (2): Last reviewed commit: "refactor(lib): rename runGitCommand to r..." | Re-trigger Greptile

Comment thread src/lib/git-workflow.ts Outdated
Comment thread src/lib/repo-manager.ts Outdated
… handling

runGitCommand is used to spawn both git and gh CLI commands, so the name
was misleading. Renamed to runCliCommand across git-exec, git-workflow,
git-workflow-worktree, and repo-manager.

Also wrap cloneBareRepo/getCurrentRepoInfo's runCliCommand calls in
try/catch, matching the pattern already used in isInGitRepo/getGitDir,
so a spawn failure (e.g. gh missing from PATH) surfaces a clear error
instead of an unhandled rejection.
@sonarqubecloud

sonarqubecloud Bot commented Jul 5, 2026

Copy link
Copy Markdown

@amondnet
amondnet merged commit cd8b72a into main Jul 5, 2026
14 of 15 checks passed
@amondnet
amondnet deleted the 267-refactor-bunspawn-to-rungitcommand-helper-in-git-workflowts-and-repo-managerts branch July 5, 2026 10:50
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.

Refactor Bun.spawn to runGitCommand helper in git-workflow.ts and repo-manager.ts

1 participant