@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88def init_kudo_sync_bot (msgs ):
99 import os
1010 print (f'\n { msgs .log_SWITCHING_TO_KUDO_SYNC_BOT } ...\n ' )
11- with open (BACKUP_PATH , 'w' ) as file : # back up git config
12- file .write (run ('config' , '--global' , '--list' ))
11+ KEY_ID = None
1312 gpg_keys_path = os .environ .get ('GPG_KEYS_PATH' )
1413 if gpg_keys_path :
1514 key_path = Path (gpg_keys_path ) / 'kudo-sync-bot-private-key.asc'
1615 if key_path .exists () : subprocess .run (['gpg' , '--batch' , '--import' , str (key_path )], check = True )
1716 key_id_path = Path (gpg_keys_path ) / 'kudo-sync-bot-key-id.txt'
18- if key_id_path .exists ():
19- key_id = key_id_path . read_text (). strip ()
20- run ( 'config' , '--global' , 'user.signingkey' , key_id )
21- run ( 'config' , '--global' , 'commit.gpgsign' , 'true' )
22- run ( 'config' , '--global' , 'user.name' , ' kudo-sync-bot')
23- run ( 'config' , '--global' , 'user.email' , ' auto-sync@kudoai.com')
17+ if key_id_path .exists () : KEY_ID = key_id_path . read_text (). strip ()
18+ if KEY_ID : os . environ [ 'GIT_COMMITTER_SIGNINGKEY' ] = KEY_ID
19+ os . environ [ 'GIT_AUTHOR_NAME' ] = 'kudo-sync-bot'
20+ os . environ [ 'GIT_AUTHOR_EMAIL' ] = 'auto-sync@kudoai.com'
21+ os . environ [ 'GIT_COMMITTER_NAME' ] = ' kudo-sync-bot'
22+ os . environ [ 'GIT_COMMITTER_EMAIL' ] = ' auto-sync@kudoai.com'
2423 return True
2524
2625def push () : run ('push' )
2726
28- def restore_og_config (msgs ):
29- print (f'{ msgs .log_RESTORING_OG_GIT_CONFIG } ...' )
30- if BACKUP_PATH .exists ():
31- with open (BACKUP_PATH ) as file :
32- for line in file :
33- if '=' in line :
34- key , val = line .strip ().split ('=' , 1 )
35- run ('config' , '--global' , key , val )
36- BACKUP_PATH .unlink ()
37- else :
38- print (msgs .warn_GIT_CONFIG_BACKUP_NOT_FOUND )
39-
4027def run (* args ):
4128 result = subprocess .run (['git' ] + list (args ), capture_output = True , text = True )
4229 if result .returncode != 0 :
0 commit comments