|
1
|
+#!/usr/bin/env python3
|
|
2
|
+import argparse
|
|
3
|
+from pathlib import Path
|
|
4
|
+import sys
|
|
5
|
+
|
|
6
|
+import requests
|
|
7
|
+
|
|
8
|
+GITLAB = "https://gitlab.torproject.org"
|
|
9
|
+API_URL = f"{GITLAB}/api/v4"
|
|
10
|
+AUTH_HEADER = "PRIVATE-TOKEN"
|
|
11
|
+PROTECT_LEVEL = 40 # Maintainer
|
|
12
|
+
|
|
13
|
+parser = argparse.ArgumentParser()
|
|
14
|
+parser.add_argument("browser", choices=["tor-browser", "mullvad-browser"])
|
|
15
|
+parser.add_argument("firefox_version")
|
|
16
|
+parser.add_argument("our_major")
|
|
17
|
+parser.add_argument("--rebase", type=int, default=1)
|
|
18
|
+args = parser.parse_args()
|
|
19
|
+
|
|
20
|
+project_id = 1817 if args.browser == "mullvad-browser" else 472
|
|
21
|
+endpoint = f"{API_URL}/projects/{project_id}/protected_branches"
|
|
22
|
+
|
|
23
|
+token_file = Path(__file__).parent.parent / ".changelogs_token"
|
|
24
|
+if not token_file.exists():
|
|
25
|
+ print("Token not found, please create it.")
|
|
26
|
+ sys.exit(1)
|
|
27
|
+with token_file.open() as f:
|
|
28
|
+ token = f.read().strip()
|
|
29
|
+headers = {AUTH_HEADER: token}
|
|
30
|
+
|
|
31
|
+r = requests.get(endpoint, headers=headers)
|
|
32
|
+r.raise_for_status()
|
|
33
|
+rules = r.json()
|
|
34
|
+for rule in rules:
|
|
35
|
+ if f"-{args.our_major}-" in rule["name"]:
|
|
36
|
+ r = requests.delete(f"{endpoint}/{rule['name']}", headers=headers)
|
|
37
|
+ r.raise_for_status()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+def protect_branch(product):
|
|
41
|
+ data = {
|
|
42
|
+ "id": project_id,
|
|
43
|
+ "name": f"{product}-{args.firefox_version}-{args.our_major}-{args.rebase}",
|
|
44
|
+ "allow_force_push": False,
|
|
45
|
+ "merge_access_level": PROTECT_LEVEL,
|
|
46
|
+ "push_access_level": PROTECT_LEVEL,
|
|
47
|
+ }
|
|
48
|
+ r = requests.post(endpoint, json=data, headers=headers)
|
|
49
|
+ r.raise_for_status()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+protect_branch(args.browser)
|
|
53
|
+if args.browser == "tor-browser":
|
|
54
|
+ protect_branch("base-browser") |