11import { GitSaga , type GitSagaInput } from "../git-saga" ;
22
3+ function buildPostHogTrailers ( taskId ?: string ) : string [ ] {
4+ const trailers = [ "Generated-By: PostHog Code" ] ;
5+ if ( taskId ) trailers . push ( `Task-Id: ${ taskId } ` ) ;
6+ return trailers ;
7+ }
8+
39export interface CommitInput extends GitSagaInput {
410 message : string ;
511 paths ?: string [ ] ;
612 allowEmpty ?: boolean ;
713 stagedOnly ?: boolean ;
14+ taskId ?: string ;
815}
916
1017export interface CommitOutput {
@@ -19,7 +26,7 @@ export class CommitSaga extends GitSaga<CommitInput, CommitOutput> {
1926 protected async executeGitOperations (
2027 input : CommitInput ,
2128 ) : Promise < CommitOutput > {
22- const { message, paths, allowEmpty, stagedOnly } = input ;
29+ const { message, paths, allowEmpty, stagedOnly, taskId } = input ;
2330
2431 const originalHead = await this . readOnlyStep ( "get-original-head" , ( ) =>
2532 this . git . revparse ( [ "HEAD" ] ) ,
@@ -62,11 +69,19 @@ export class CommitSaga extends GitSaga<CommitInput, CommitOutput> {
6269 } ) ;
6370 }
6471
72+ const trailers = buildPostHogTrailers ( taskId ) ;
73+
74+ const commitOptions : Record < string , null | string [ ] > = { } ;
75+ if ( allowEmpty ) commitOptions [ "--allow-empty" ] = null ;
76+ if ( trailers . length > 0 ) commitOptions [ "--trailer" ] = trailers ;
77+
78+ const hasOptions = Object . keys ( commitOptions ) . length > 0 ;
79+
6580 const commitResult = await this . step ( {
6681 name : "commit" ,
6782 execute : ( ) =>
68- allowEmpty
69- ? this . git . commit ( message , undefined , { "--allow-empty" : null } )
83+ hasOptions
84+ ? this . git . commit ( message , undefined , commitOptions )
7085 : this . git . commit ( message ) ,
7186 rollback : async ( ) => {
7287 await this . git . reset ( [ "--soft" , originalHead ] ) ;
0 commit comments