Skip to content

Commit 36b291a

Browse files
committed
init.sh: set username and email for git
1 parent 02a1c18 commit 36b291a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

ansible/roles/dev-desktop/files/scripts/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ git fetch upstream
1111
git checkout upstream/master
1212
popd
1313

14+
init_git.py
1415
setup_rustup.sh
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/python3
2+
import requests
3+
import re
4+
import subprocess
5+
import getpass
6+
7+
for cfg in ["email", "name"]:
8+
if subprocess.run(["git", "config", "--global", f"user.{cfg}"], stdout=subprocess.DEVNULL).returncode == 0:
9+
print("git username and email already configured")
10+
exit(0)
11+
12+
people = requests.get("https://team-api.infra.rust-lang.org/v1/people.json")
13+
people.raise_for_status()
14+
people_map = people.json()["people"]
15+
16+
username = getpass.getuser()
17+
username = username.lstrip("gh-")
18+
19+
print(f"found github name: {username}")
20+
21+
if username not in people_map:
22+
print("could not find a matching user in the people map!")
23+
print("E: Could not configure your git name and email. Please do so manually.")
24+
exit(1)
25+
26+
person = people_map[github_name]
27+
28+
for config in ["email", "name"]:
29+
if config not in person:
30+
print(f"`{config}` variable does not exist")
31+
continue
32+
value = person[config]
33+
r = ["git", "config", "--global", f"user.{config}", value]
34+
print(str(r))
35+
subprocess.run(r).check_returncode()
36+
37+
print("successfully configured your user name and email for git")
38+
exit()

0 commit comments

Comments
 (0)