- Add a Git action confirmation modal with live commit/push/PR progress states - Accept optional `commitMessage` input and skip AI message generation when provided - Expand server and contracts tests for custom commit message handling
Showing the changes to apps/server/src (2 of 5 files). Show all
Unified · Split
| @@ -248,6 +248,40 @@ describe("GitManager", () => { · 247 unmodified lines | ||
| 248 | 248 | ); |
| 249 | 249 | }); |
| 250 | 250 | |
| 251 | + it("uses custom commit message when provided", async () => { | |
| 252 | + const repoDir = makeTempDir("t3code-git-manager-"); | |
| 253 | + await initRepo(repoDir); | |
| 254 | + fs.writeFileSync(path.join(repoDir, "README.md"), "hello\ncustom\n"); | |
| 255 | + let generatedCount = 0; | |
| 256 | + | |
| 257 | + const manager = new GitManager({ | |
| 258 | + textGenerator: createTextGenerator({ | |
| 259 | + generateCommitMessage: async () => { | |
| 260 | + generatedCount += 1; | |
| 261 | + return { | |
| 262 | + subject: "this should not be used", | |
| 263 | + body: "", | |
| 264 | + }; | |
| 265 | + }, | |
| 266 | + }), | |
| 267 | + }); | |
| 268 | + const result = await manager.runStackedAction({ | |
| 269 | + cwd: repoDir, | |
| 270 | + action: "commit", | |
| 271 | + commitMessage: "feat: custom summary line\n\n- details from user", | |
| 272 | + }); | |
| 273 | + | |
| 274 | + expect(result.commit.status).toBe("created"); | |
| 275 | + expect(result.commit.subject).toBe("feat: custom summary line"); | |
| 276 | + expect(generatedCount).toBe(0); | |
| 277 | + expect(await runGitStdout(repoDir, ["log", "-1", "--pretty=%s"])).toBe( | |
| 278 | + "feat: custom summary line", | |
| 279 | + ); | |
| 280 | + expect(await runGitStdout(repoDir, ["log", "-1", "--pretty=%b"])).toContain( | |
| 281 | + "- details from user", | |
| 282 | + ); | |
| 283 | + }); | |
| 284 | + | |
| 251 | 285 | it("skips commit when there are no uncommitted changes", async () => { |
| 252 | 286 | const repoDir = makeTempDir("t3code-git-manager-"); |
| 253 | 287 | await initRepo(repoDir); |
| @@ -106,6 +106,24 @@ function sanitizeCommitMessage( · 105 unmodified lines | ||
| 106 | 106 | }; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | +function parseCustomCommitMessage(raw: string): CommitMessageGenerationResult | null { | |
| 110 | + const normalized = raw.replace(/\r\n/g, "\n").trim(); | |
| 111 | + if (normalized.length === 0) { | |
| 112 | + return null; | |
| 113 | + } | |
| 114 | + | |
| 115 | + const [firstLine, ...rest] = normalized.split("\n"); | |
| 116 | + const subject = firstLine?.trim() ?? ""; | |
| 117 | + if (subject.length === 0) { | |
| 118 | + return null; | |
| 119 | + } | |
| 120 | + | |
| 121 | + return { | |
| 122 | + subject, | |
| 123 | + body: rest.join("\n").trim(), | |
| 124 | + }; | |
| 125 | +} | |
| 126 | + | |
| 109 | 127 | function extractBranchFromRef(ref: string): string { |
| 110 | 128 | const normalized = ref.trim(); |
| 111 | 129 | |
| @@ -222,7 +240,11 @@ export class GitManager { · 110 unmodified lines | ||
| 222 | 240 | throw new Error("Cannot create a pull request from detached HEAD."); |
| 223 | 241 | } |
| 224 | 242 | |
| 225 | − const commit = await this.runCommitStep(input.cwd, initialStatus.branch); | |
| 243 | + const commit = await this.runCommitStep( | |
| 244 | + input.cwd, | |
| 245 | + initialStatus.branch, | |
| 246 | + input.commitMessage, | |
| 247 | + ); | |
| 226 | 248 | |
| 227 | 249 | const push = wantsPush |
| 228 | 250 | ? await this.gitCore.pushCurrentBranch(input.cwd, initialStatus.branch) |
| @@ -243,6 +265,7 @@ export class GitManager { · 14 unmodified lines | ||
| 243 | 265 | private async runCommitStep( |
| 244 | 266 | cwd: string, |
| 245 | 267 | branch: string | null, |
| 268 | + commitMessage?: string, | |
| 246 | 269 | ): Promise<{ |
| 247 | 270 | status: "created" | "skipped_no_changes"; |
| 248 | 271 | commitSha?: string | undefined; |
| @@ -253,18 +276,23 @@ export class GitManager { · 4 unmodified lines | ||
| 253 | 276 | return { status: "skipped_no_changes" }; |
| 254 | 277 | } |
| 255 | 278 | |
| 256 | − let generated: CommitMessageGenerationResult; | |
| 257 | − try { | |
| 258 | − generated = sanitizeCommitMessage( | |
| 259 | − await this.textGenerator.generateCommitMessage({ | |
| 260 | − cwd, | |
| 261 | − branch, | |
| 262 | − stagedSummary: limitContext(context.stagedSummary, 8_000), | |
| 263 | − stagedPatch: limitContext(context.stagedPatch, 50_000), | |
| 264 | − }), | |
| 265 | − ); | |
| 266 | − } catch (error) { | |
| 267 | − throw asCommandNotFound("codex", error) ?? error; | |
| 279 | + let generated: CommitMessageGenerationResult | null = parseCustomCommitMessage( | |
| 280 | + commitMessage ?? "", | |
| 281 | + ); | |
| 282 | + | |
| 283 | + if (!generated) { | |
| 284 | + try { | |
| 285 | + generated = sanitizeCommitMessage( | |
| 286 | + await this.textGenerator.generateCommitMessage({ | |
| 287 | + cwd, | |
| 288 | + branch, | |
| 289 | + stagedSummary: limitContext(context.stagedSummary, 8_000), | |
| 290 | + stagedPatch: limitContext(context.stagedPatch, 50_000), | |
| 291 | + }), | |
| 292 | + ); | |
| 293 | + } catch (error) { | |
| 294 | + throw asCommandNotFound("codex", error) ?? error; | |
| 295 | + } | |
| 268 | 296 | } |
| 269 | 297 | |
| 270 | 298 | const { commitSha } = await this.gitCore.commit(cwd, generated.subject, generated.body); |