Testing#3
Conversation
chore: update README and CHANGELOG with new PR workflow commands
|
| 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
%%{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
Comments Outside Diff (1)
-
scripts/cli.ts, line 718-722 (link)ghauth check fires too late in the PR flowisGhAvailable()only verifies that theghbinary is on PATH — it does not check authentication. Whenghis installed but not logged in,findOpenPrForHeadwill callgh pr list, catch the auth-error exit and silently returnnull, and then the code spends several seconds on AI title/body generation beforegh pr createultimately fails with the same auth error. The existingfetchLatestFromNpmin this file usesAbortSignal.timeoutand propagates errors early as a pattern — the PR flow should follow suit by verifying auth up front, e.g. withgh 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
| 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 }, | ||
| ], | ||
| }), | ||
| }); | ||
| } |
There was a problem hiding this 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.
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.
No description provided.