@@ -31,36 +31,50 @@ def _resolve_path(p: str) -> str:
3131
3232
3333def setup_git (script_dir : Path ) -> None :
34- """Generate a .gitconfig with identity and optional GPG signing .
34+ """Generate per-platform .gitconfig files with includeIf .
3535
36- Reads from env: GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GPG_SIGNING_KEY.
37- Sets GIT_CONFIG_GLOBAL so all repos use this config.
36+ Reads GH_USER_NAME/GH_USER_EMAIL and GL_USER_NAME/GL_USER_EMAIL
37+ from env. Each platform gets its own identity and signing key.
38+ Falls back to GIT_AUTHOR_NAME/GIT_AUTHOR_EMAIL for single-identity
39+ local dev. Sets GIT_CONFIG_GLOBAL so all repos use this config.
3840 """
39- name = os .environ .get ("GIT_AUTHOR_NAME" )
40- email = os .environ .get ("GIT_AUTHOR_EMAIL" )
41+ gh_name = os .environ .get ("GH_USER_NAME" ) or os .environ .get ("GIT_AUTHOR_NAME" )
42+ gh_email = os .environ .get ("GH_USER_EMAIL" ) or os .environ .get ("GIT_AUTHOR_EMAIL" )
43+ gl_name = os .environ .get ("GL_USER_NAME" ) or os .environ .get ("GIT_AUTHOR_NAME" )
44+ gl_email = os .environ .get ("GL_USER_EMAIL" ) or os .environ .get ("GIT_AUTHOR_EMAIL" )
4145
42- if not name and not email :
46+ if not gh_name and not gl_name :
4347 return
4448
4549 config_path = script_dir / ".gitconfig"
50+ gh_config = script_dir / ".gitconfig-gh"
51+ gl_config = script_dir / ".gitconfig-gl"
52+
53+ for path , name , email , key_env in [
54+ (gh_config , gh_name , gh_email , "GH_GPG_SIGNING_KEY" ),
55+ (gl_config , gl_name , gl_email , "GL_GPG_SIGNING_KEY" ),
56+ ]:
57+ lines = ["# Auto-generated by bot/run.py" , "[user]" ]
58+ if name :
59+ lines .append (f"\t name = { name } " )
60+ if email :
61+ lines .append (f"\t email = { email } " )
62+ signing_key = os .environ .get (key_env ) or os .environ .get ("GPG_SIGNING_KEY" )
63+ if signing_key :
64+ lines .append (f"\t signingkey = { signing_key } " )
65+ path .write_text ("\n " .join (lines ) + "\n " )
66+
4667 lines = [
4768 "# Auto-generated by bot/run.py — do not edit manually" ,
48- "[user]" ,
69+ '[includeIf "hasconfig:remote.*.url:https://github.com/**"]' ,
70+ f"\t path = { gh_config } " ,
71+ '[includeIf "hasconfig:remote.*.url:https://gitlab.cee.redhat.com/**"]' ,
72+ f"\t path = { gl_config } " ,
73+ "[commit]" ,
74+ "\t gpgsign = true" ,
75+ "[gpg]" ,
76+ "\t format = openpgp" ,
4977 ]
50- if name :
51- lines .append (f"\t name = { name } " )
52- if email :
53- lines .append (f"\t email = { email } " )
54-
55- signing_key = os .environ .get ("GPG_SIGNING_KEY" )
56- if signing_key :
57- lines += [
58- f"\t signingkey = { signing_key } " ,
59- "[commit]" ,
60- "\t gpgsign = true" ,
61- "[gpg]" ,
62- "\t format = openpgp" ,
63- ]
6478
6579 config_path .write_text ("\n " .join (lines ) + "\n " )
6680 os .environ ["GIT_CONFIG_GLOBAL" ] = str (config_path )
0 commit comments