Skip to content

Testing#3

Merged
MusicMaster4 merged 5 commits into
mainfrom
testing
Jul 10, 2026
Merged

Testing#3
MusicMaster4 merged 5 commits into
mainfrom
testing

Conversation

@MusicMaster4

Copy link
Copy Markdown
Owner

No description provided.

@MusicMaster4 MusicMaster4 merged commit a45d4f5 into main Jul 10, 2026
1 check passed
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds AI-powered GitHub pull-request creation to the gitgen CLI via two new commands — gg pr [base] and gg cnp pr — backed by a new lib/pr-message.ts module that makes parallel plain-text model calls for the PR title and body, then shells out to the GitHub CLI (gh) to create the PR.

  • lib/pr-message.ts: New module with generatePrContent (two parallel AI calls), fallbackPrContent (git-log-based fallback), cleanTitle/cleanBody sanitizers, base-branch detection helpers, and a runCapture wrapper for gh with a 120 s timeout.
  • scripts/cli.ts: Adds case \"pr\" and extends case \"commit\" to parse optional trailing pr [base] args; createPullRequest handles push, existing-PR detection, AI generation, and gh pr create.
  • test/pr-message.test.ts: Unit tests for cleanTitle and cleanBody covering think-tag stripping, fence unwrapping, prefix removal, and length capping.

Confidence Score: 4/5

Safe to merge; the new PR flow works end-to-end and falls back gracefully when AI is unavailable.

The two issues are quality/UX concerns rather than correctness bugs. When gh is installed but not authenticated, the command spends several seconds on AI generation before failing at gh pr create. The fetch calls to the AI APIs also have no abort signal, so a hung network connection would cause the command to spin indefinitely. Both are straightforward to fix and do not affect the core git or PR creation logic.

lib/pr-message.ts — the fetch functions lack timeout signals; scripts/cli.ts — the gh auth check ordering.

Important Files Changed

Filename Overview
lib/pr-message.ts New module for AI-driven PR title/body generation. Logic is well-structured with parallel model calls, multi-format response extraction, and graceful fallback. Missing AbortSignal on fetch calls could cause hangs.
scripts/cli.ts Adds pr command and extends commit case with optional PR creation. Flow logic and arg parsing are sound; auth check is not early enough — gh availability is checked but auth status is not, wasting time on AI generation before a predictable failure.
test/pr-message.test.ts Covers cleanTitle and cleanBody with representative test cases including think-tag stripping, fence unwrapping, and length capping.
CHANGELOG.md Moves the 1.0.7 release entry to an Unreleased section and documents the new PR workflow features.
README.md Adds documentation for gg pr and gg cnp pr commands, gh prerequisite, and a new How AI pull requests work section.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant U as User
    participant CLI as cli.ts
    participant Git as git
    participant AI as OpenRouter/OpenAI
    participant GH as gh CLI

    U->>CLI: gg pr [base] / gg cnp pr
    CLI->>GH: gh --version (isGhAvailable)
    CLI->>Git: git branch --show-current
    CLI->>Git: git add . + commit (if dirty)
    CLI->>Git: git push / push -u origin HEAD
    CLI->>GH: gh pr list --head branch --state open
    alt PR already open
        CLI-->>U: print existing PR URL
    else No open PR
        CLI->>AI: title call (plain text)
        CLI->>AI: body call (plain text, parallel)
        CLI-->>U: preview title + body
        CLI->>GH: gh pr create --base ... --title ... --body ...
        CLI-->>U: print new PR URL
    end
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 U as User
    participant CLI as cli.ts
    participant Git as git
    participant AI as OpenRouter/OpenAI
    participant GH as gh CLI

    U->>CLI: gg pr [base] / gg cnp pr
    CLI->>GH: gh --version (isGhAvailable)
    CLI->>Git: git branch --show-current
    CLI->>Git: git add . + commit (if dirty)
    CLI->>Git: git push / push -u origin HEAD
    CLI->>GH: gh pr list --head branch --state open
    alt PR already open
        CLI-->>U: print existing PR URL
    else No open PR
        CLI->>AI: title call (plain text)
        CLI->>AI: body call (plain text, parallel)
        CLI-->>U: preview title + body
        CLI->>GH: gh pr create --base ... --title ... --body ...
        CLI-->>U: print new PR URL
    end
Loading

Comments Outside Diff (1)

  1. scripts/cli.ts, line 718-722 (link)

    P2 gh auth check fires too late in the PR flow

    isGhAvailable() only verifies that the gh binary is on PATH — it does not check authentication. When gh is installed but not logged in, findOpenPrForHead will call gh pr list, catch the auth-error exit and silently return null, and then the code spends several seconds on AI title/body generation before gh pr create ultimately fails with the same auth error. The existing fetchLatestFromNpm in this file uses AbortSignal.timeout and propagates errors early as a pattern — the PR flow should follow suit by verifying auth up front, e.g. with gh auth status --active (exit 0 if logged in) right after the availability check.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: scripts/cli.ts
    Line: 718-722
    
    Comment:
    **`gh` auth check fires too late in the PR flow**
    
    `isGhAvailable()` only verifies that the `gh` binary is on PATH — it does not check authentication. When `gh` is installed but not logged in, `findOpenPrForHead` will call `gh pr list`, catch the auth-error exit and silently return `null`, and then the code spends several seconds on AI title/body generation before `gh pr create` ultimately fails with the same auth error. The existing `fetchLatestFromNpm` in this file uses `AbortSignal.timeout` and propagates errors early as a pattern — the PR flow should follow suit by verifying auth up front, e.g. with `gh auth status --active` (exit 0 if logged in) right after the availability check.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
scripts/cli.ts:718-722
**`gh` auth check fires too late in the PR flow**

`isGhAvailable()` only verifies that the `gh` binary is on PATH — it does not check authentication. When `gh` is installed but not logged in, `findOpenPrForHead` will call `gh pr list`, catch the auth-error exit and silently return `null`, and then the code spends several seconds on AI title/body generation before `gh pr create` ultimately fails with the same auth error. The existing `fetchLatestFromNpm` in this file uses `AbortSignal.timeout` and propagates errors early as a pattern — the PR flow should follow suit by verifying auth up front, e.g. with `gh auth status --active` (exit 0 if logged in) right after the availability check.

### Issue 2 of 2
lib/pr-message.ts:104-121
**No abort signal / timeout on fetch calls**

`openRouterRequest` and `openAiRequest` issue plain `fetch` calls with no `AbortSignal`. If the AI API hangs (e.g., rate-limit queue, network drop), the command will spin forever with no way to recover except Ctrl-C. The existing `fetchLatestFromNpm` in `cli.ts` already uses `signal: AbortSignal.timeout(15_000)` — the same guard should be applied here, matching the `runCapture` 120 s timeout used for `gh` commands.

Reviews (1): Last reviewed commit: "Merge branch 'main' into testing" | Re-trigger Greptile

Comment thread lib/pr-message.ts
Comment on lines +104 to +121
return fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
"X-Title": "Git Command Generator",
},
body: JSON.stringify({
model,
temperature: 0.2,
max_tokens: maxTokens,
messages: [
{ role: "system", content: system },
{ role: "user", content: context },
],
}),
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 No abort signal / timeout on fetch calls

openRouterRequest and openAiRequest issue plain fetch calls with no AbortSignal. If the AI API hangs (e.g., rate-limit queue, network drop), the command will spin forever with no way to recover except Ctrl-C. The existing fetchLatestFromNpm in cli.ts already uses signal: AbortSignal.timeout(15_000) — the same guard should be applied here, matching the runCapture 120 s timeout used for gh commands.

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/pr-message.ts
Line: 104-121

Comment:
**No abort signal / timeout on fetch calls**

`openRouterRequest` and `openAiRequest` issue plain `fetch` calls with no `AbortSignal`. If the AI API hangs (e.g., rate-limit queue, network drop), the command will spin forever with no way to recover except Ctrl-C. The existing `fetchLatestFromNpm` in `cli.ts` already uses `signal: AbortSignal.timeout(15_000)` — the same guard should be applied here, matching the `runCapture` 120 s timeout used for `gh` commands.

How can I resolve this? If you propose a fix, please make it concise.

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