(
projectId: string,
options: {
includeUnstaged: boolean
message: string | null
push: boolean
preview?: boolean | undefined
generateMessage?: (context: CommitMessageContext) => Promise<string | null | undefined>
},
)
| 32 | } |
| 33 | |
| 34 | export async function commitProjectChanges( |
| 35 | projectId: string, |
| 36 | options: { |
| 37 | includeUnstaged: boolean |
| 38 | message: string | null |
| 39 | push: boolean |
| 40 | preview?: boolean | undefined |
| 41 | generateMessage?: (context: CommitMessageContext) => Promise<string | null | undefined> |
| 42 | }, |
| 43 | ) { |
| 44 | try { |
| 45 | const context = await prepareCommitMessageContext(projectId, options.includeUnstaged) |
| 46 | if (!context) { |
| 47 | return { committed: false, message: null, previewed: false, pushed: false } |
| 48 | } |
| 49 | |
| 50 | const generatedMessage = options.message ? null : await options.generateMessage?.(context) |
| 51 | const commitMessage = options.message ?? generatedMessage ?? buildDefaultCommitMessage(context) |
| 52 | |
| 53 | if (options.preview) { |
| 54 | return { |
| 55 | committed: false, |
| 56 | message: commitMessage, |
| 57 | previewed: true, |
| 58 | pushed: false, |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (options.includeUnstaged) { |
| 63 | await runGit(projectId, ['add', '-A']) |
| 64 | } |
| 65 | |
| 66 | await runGit(projectId, ['commit', '-m', commitMessage]) |
| 67 | |
| 68 | if (!(options.push && context.hasOrigin && context.branch)) { |
| 69 | return { |
| 70 | committed: true, |
| 71 | message: commitMessage, |
| 72 | previewed: false, |
| 73 | pushed: false, |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | try { |
| 78 | await runGitWithOptions(projectId, ['push', 'origin', context.branch], { |
| 79 | env: getNonInteractiveGitEnv(), |
| 80 | timeout: 15_000, |
| 81 | maxBuffer: 1024 * 1024 * 2, |
| 82 | }) |
| 83 | } catch (pushError) { |
| 84 | try { |
| 85 | await runGitWithOptions(projectId, ['push', '--set-upstream', 'origin', context.branch], { |
| 86 | env: getNonInteractiveGitEnv(), |
| 87 | timeout: 15_000, |
| 88 | maxBuffer: 1024 * 1024 * 2, |
| 89 | }) |
| 90 | } catch { |
| 91 | return { |
no test coverage detected