@@ -9,6 +9,8 @@ const logger = mainLogger.child({ event });
99const SQUASH_UPDATE_MESSAGE = process . env . SQUASH_UPDATE_MESSAGE || 'Update dependencies' ;
1010const SQUASH_DEPS_DAYS_AGO = Number . parseInt ( process . env . SQUASH_DAYS_AGO || '5' ) ;
1111const SQUASH_MAX_UPDATE_COMMITS = Number . parseInt ( process . env . SQUASH_MAX_UPDATE_COMMITS || '5' ) ;
12+ const GIT_SQUASH_USER =
13+ "GIT_AUTHOR_NAME='Containers Up!' GIT_AUTHOR_EMAIL='260200075+containers-up@users.noreply.github.com'" ;
1214
1315const buildMessage = ( subject : string , body ?: string ) => {
1416 const parts = [ subject , body ] . filter ( Boolean ) ;
@@ -19,13 +21,15 @@ const gitCommitWithMessage = async (
1921 sshRun : ( cmd : string ) => Promise < { stdout : string } > ,
2022 message : string ,
2123 amend = false ,
22- authorDate ? : string
24+ authorDate : string
2325) => {
2426 const amendFlag = amend ? ' --amend' : '' ;
25- const dateFlag = authorDate ? ` --date='${ authorDate } '` : '' ;
27+ const dateFlag = ` --date='${ authorDate } '` ;
2628 // Use base64 encoding to avoid all shell escaping issues
2729 const base64Message = Buffer . from ( message ) . toString ( 'base64' ) ;
28- await sshRun ( `echo '${ base64Message } ' | base64 -d | git commit${ amendFlag } ${ dateFlag } -F -` ) ;
30+ await sshRun (
31+ `echo '${ base64Message } ' | base64 -d | env ${ GIT_SQUASH_USER } git commit${ amendFlag } ${ dateFlag } -F -`
32+ ) ;
2933} ;
3034
3135const hasUncommittedChanges = async (
@@ -59,9 +63,10 @@ const getCommitMetadata = async (
5963const updateCurrentCommit = async (
6064 sshRun : ( cmd : string ) => Promise < { stdout : string } > ,
6165 subject : string ,
62- body : string
66+ body : string ,
67+ authorDate ?: string
6368) => {
64- await gitCommitWithMessage ( sshRun , buildMessage ( subject , body ) , true ) ;
69+ await gitCommitWithMessage ( sshRun , buildMessage ( subject , body ) , true , authorDate ) ;
6570} ;
6671
6772const squashLastTwoCommits = async (
@@ -113,7 +118,7 @@ const squashOldestTwoCommits = async (
113118 const base64Msg = Buffer . from ( squashedMessage ) . toString ( 'base64' ) ;
114119 const newHash = (
115120 await sshRun (
116- `echo '${ base64Msg } ' | base64 -d | env GIT_AUTHOR_DATE='${ commits [ 0 ] . authorDate } ' git commit-tree ${ commits [ 1 ] . tree } -p HEAD`
121+ `echo '${ base64Msg } ' | base64 -d | env ${ GIT_SQUASH_USER } GIT_AUTHOR_DATE='${ commits [ 0 ] . authorDate } ' git commit-tree ${ commits [ 1 ] . tree } -p HEAD`
117122 )
118123 ) . stdout . trim ( ) ;
119124 await sshRun ( `git reset --hard ${ newHash } ` ) ;
@@ -126,7 +131,7 @@ const squashOldestTwoCommits = async (
126131 const b64 = Buffer . from ( msg ) . toString ( 'base64' ) ;
127132 const hash = (
128133 await sshRun (
129- `echo '${ b64 } ' | base64 -d | env GIT_AUTHOR_DATE='${ commits [ i ] . authorDate } ' git commit-tree ${ commits [ i ] . tree } -p HEAD`
134+ `echo '${ b64 } ' | base64 -d | env ${ GIT_SQUASH_USER } GIT_AUTHOR_DATE='${ commits [ i ] . authorDate } ' git commit-tree ${ commits [ i ] . tree } -p HEAD`
130135 )
131136 ) . stdout . trim ( ) ;
132137 await sshRun ( `git reset --hard ${ hash } ` ) ;
@@ -173,12 +178,14 @@ export const squashUpdates = async (
173178 // Get previous commit info
174179 const prevCommit = await getCommitMetadata ( sshRun , 1 ) ;
175180
176- const isAutomatedAuthor = / d e p e n d a b o t | r e n o v a t e / i. test ( prevCommit . authorName ) ;
181+ const isAutomatedAuthor = ( authorName : string ) =>
182+ / d e p e n d a b o t | r e n o v a t e | c o n t a i n e r s - u p / i. test ( authorName ) ;
177183 const X_DAYS_AGO = Date . now ( ) - SQUASH_DEPS_DAYS_AGO * 24 * 60 * 60 * 1000 ;
178184
179185 if (
180- isAutomatedAuthor ||
181- ( prevCommit . timestamp > X_DAYS_AGO && prevCommit . subject . includes ( SQUASH_UPDATE_MESSAGE ) )
186+ isAutomatedAuthor ( lastCommit . authorName ) &&
187+ isAutomatedAuthor ( prevCommit . authorName ) &&
188+ prevCommit . timestamp > X_DAYS_AGO
182189 ) {
183190 // Previous commit is from automated author, squash them together
184191 logger . info ( `Squashing last 2 commits together (previous author: ${ prevCommit . authorName } )` ) ;
@@ -192,9 +199,12 @@ export const squashUpdates = async (
192199 continue ;
193200 }
194201
195- if ( ! lastCommit . subject . includes ( SQUASH_UPDATE_MESSAGE ) ) {
202+ if (
203+ isAutomatedAuthor ( lastCommit . authorName ) &&
204+ ! lastCommit . subject . includes ( SQUASH_UPDATE_MESSAGE )
205+ ) {
196206 logger . info ( 'Updating current commit message only (previous is old or not an update commit)' ) ;
197- await updateCurrentCommit ( sshRun , lastCommit . subject , lastCommit . body ) ;
207+ await updateCurrentCommit ( sshRun , lastCommit . subject , lastCommit . body , lastCommit . authorDate ) ;
198208 }
199209
200210 break ;
0 commit comments