Skip to content

Commit 825585f

Browse files
committed
Replaced global git config mutation w/ env overrides
1 parent c964e8d commit 825585f

32 files changed

Lines changed: 112 additions & 336 deletions

File tree

ai-personas/utils/bump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def main():
8989
log.info(f'{msgs.log_PUSHING_CHANGES}...')
9090
git.push()
9191
log.success(f'{msgs.log_PUSHED_ALL_COMMITS}')
92-
git.restore_og_config(msgs)
9392

9493
log.success(f'{msgs.log_SUCCESS}! {project.name} {msgs.log_BUMPED_TO} v{new_ver}!')
9594

ai-personas/utils/lib/git.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88
def 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

2625
def 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-
4027
def run(*args):
4128
result = subprocess.run(['git'] + list(args), capture_output=True, text=True)
4229
if result.returncode != 0:

computer-languages/utils/bump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def main():
8989
log.info(f'{msgs.log_PUSHING_CHANGES}...')
9090
git.push()
9191
log.success(f'{msgs.log_PUSHED_ALL_COMMITS}')
92-
git.restore_og_config(msgs)
9392

9493
log.success(f'{msgs.log_SUCCESS}! {project.name} {msgs.log_BUMPED_TO} v{new_ver}!')
9594

computer-languages/utils/lib/git.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88
def 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

2625
def 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-
4027
def run(*args):
4128
result = subprocess.run(['git'] + list(args), capture_output=True, text=True)
4229
if result.returncode != 0:

data-languages/utils/bump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def main():
8989
log.info(f'{msgs.log_PUSHING_CHANGES}...')
9090
git.push()
9191
log.success(f'{msgs.log_PUSHED_ALL_COMMITS}')
92-
git.restore_og_config(msgs)
9392

9493
log.success(f'{msgs.log_SUCCESS}! {project.name} {msgs.log_BUMPED_TO} v{new_ver}!')
9594

data-languages/utils/lib/git.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88
def 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

2625
def 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-
4027
def run(*args):
4128
result = subprocess.run(['git'] + list(args), capture_output=True, text=True)
4229
if result.returncode != 0:

find-project-root/utils/bump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def main():
8989
log.info(f'{msgs.log_PUSHING_CHANGES}...')
9090
git.push()
9191
log.success(f'{msgs.log_PUSHED_ALL_COMMITS}')
92-
git.restore_og_config(msgs)
9392

9493
log.success(f'{msgs.log_SUCCESS}! {project.name} {msgs.log_BUMPED_TO} v{new_ver}!')
9594

find-project-root/utils/lib/git.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88
def 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

2625
def 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-
4027
def run(*args):
4128
result = subprocess.run(['git'] + list(args), capture_output=True, text=True)
4229
if result.returncode != 0:

get-min-py/utils/bump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def main():
100100
log.info(f'{msgs.log_PUSHING_CHANGES}...')
101101
git.push()
102102
log.success(f'{msgs.log_PUSHED_ALL_COMMITS}')
103-
git.restore_og_config(msgs)
104103

105104
log.success(f'{msgs.log_SUCCESS}! {project.name} {msgs.log_BUMPED_TO} v{new_ver}!')
106105

get-min-py/utils/lib/git.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,22 @@ def commit(files, msg, *args) : run('add', *files) ; run('commit', '-m', msg, *a
88
def 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

2625
def 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-
4027
def run(*args):
4128
result = subprocess.run(['git'] + list(args), capture_output=True, text=True)
4229
if result.returncode != 0:

0 commit comments

Comments
 (0)