@@ -12,6 +12,9 @@ import {
1212 getSocketDevPackageOverviewUrlFromPurl
1313} from '../../utils/socket-url.mts'
1414
15+ const GITHUB_ACTIONS_BOT_USERNAME = 'github-actions[bot]'
16+ const GITHUB_ACTIONS_BOT_EMAIL = `${ GITHUB_ACTIONS_BOT_USERNAME } @users.noreply.github.com`
17+
1518function formatBranchName ( str : string ) : string {
1619 return str
1720 . replace ( / [ - _ . \\ / ] + / g, '-' )
@@ -113,6 +116,7 @@ export async function gitCreateAndPushBranchIfNeeded(
113116 logger . warn ( 'Nothing to commit, skipping push.' )
114117 return false
115118 }
119+ await gitEnsureIdentity ( cwd )
116120 await spawn ( 'git' , [ 'checkout' , '-b' , branch ] , { cwd } )
117121 await spawn ( 'git' , [ 'add' , ...moddedFilepaths ] , { cwd } )
118122 await spawn ( 'git' , [ 'commit' , '-m' , commitMsg ] , { cwd } )
@@ -133,6 +137,33 @@ export async function gitCreateAndPushBranchIfNeeded(
133137 return false
134138}
135139
140+ export async function gitEnsureIdentity ( cwd = process . cwd ( ) ) : Promise < void > {
141+ let hasUserName = false
142+ try {
143+ const { stdout } = await spawn ( 'git' , [ 'config' , '--get' , 'user.name' ] , {
144+ cwd
145+ } )
146+ hasUserName = ! ! stdout . trim ( )
147+ } catch { }
148+ if ( ! hasUserName ) {
149+ await spawn ( 'git' , [ 'config' , 'user.name' , GITHUB_ACTIONS_BOT_USERNAME ] , {
150+ cwd
151+ } )
152+ }
153+ let hasUserEmail = false
154+ try {
155+ const { stdout } = await spawn ( 'git' , [ 'config' , '--get' , 'user.email' ] , {
156+ cwd
157+ } )
158+ hasUserEmail = ! ! stdout . trim ( )
159+ } catch { }
160+ if ( ! hasUserEmail ) {
161+ await spawn ( 'git' , [ 'config' , 'user.email' , GITHUB_ACTIONS_BOT_EMAIL ] , {
162+ cwd
163+ } )
164+ }
165+ }
166+
136167export async function gitResetAndClean (
137168 branch = 'HEAD' ,
138169 cwd = process . cwd ( )
0 commit comments