-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-contribution-mapper.py
More file actions
77 lines (59 loc) · 1.89 KB
/
git-contribution-mapper.py
File metadata and controls
77 lines (59 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import asyncio
import os
import subprocess
import sys
from dotenv import load_dotenv
load_dotenv(override=True)
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--dry-run", action="store_true")
parser.add_argument("--force-push", action="store_true")
args = parser.parse_args()
DRY_RUN = args.dry_run
FORCE_PUSH = args.force_push
DUMMY_FILE_PATH = b"CHANGELOG.md"
REPO_PATH = "repos"
MONOREPO_PATH = os.path.join(REPO_PATH, "_monorepo")
MONOREPO_REPO = os.environ.get("MONOREPO_REPO")
REPOS = os.environ.get("REPOS", "").split(",")
REPOS = [repo.strip() for repo in REPOS if repo.strip()]
GITHUB_EMAIL = os.environ.get("GITHUB_EMAIL")
MAIN_BRANCH = os.environ.get("MAIN_BRANCH", "master")
extra_env = {"DRY_RUN": "1"} if DRY_RUN else {}
if FORCE_PUSH:
extra_env["FORCE_PUSH"] = "1"
env = {**os.environ, **extra_env}
def process_repo(repo_url: str):
repo_name = repo_url.split("/")[-1]
repo_path = os.path.join(REPO_PATH, repo_name)
try:
subprocess.run(
[
"bash",
"scripts/repo-process.sh",
repo_url,
repo_path,
repo_name,
GITHUB_EMAIL,
MAIN_BRANCH,
],
check=True,
env=env,
)
except subprocess.CalledProcessError:
print(f"❌ Processing failed for {repo_name}")
sys.exit(1)
return repo_name
async def main():
repo_names = [process_repo(repo) for repo in REPOS]
subprocess.run(["bash", "scripts/monorepo-setup.sh", MONOREPO_REPO], check=True, env=env)
repo_args = []
for repo_name in repo_names:
repo_args.extend([repo_name, os.path.join("..", repo_name)])
subprocess.run(
["bash", "scripts/monorepo-merge-all.sh", MAIN_BRANCH] + repo_args,
check=True,
env=env,
)
if __name__ == "__main__":
asyncio.run(main())