[tbb-commits] [Git][tpo/applications/tor-browser-build][main] Bug 40717: Create a script to prepare changelogs

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Tue Dec 20 10:39:10 UTC 2022



Pier Angelo Vendrame pushed to branch main at The Tor Project / Applications / tor-browser-build


Commits:
2318e242 by Pier Angelo Vendrame at 2022-12-20T11:37:49+01:00
Bug 40717: Create a script to prepare changelogs

- - - - -


3 changed files:

- .gitlab/issue_templates/Release Prep - Alpha.md
- tools/.gitignore
- + tools/fetch-changelogs.py


Changes:

=====================================
.gitlab/issue_templates/Release Prep - Alpha.md
=====================================
@@ -179,6 +179,13 @@ Tor Browser Alpha (and Nightly) are on the `main` branch, while Stable lives in
       - [ ] Update the URL if you have uploaded to a different people.tpo home
 - [ ] Update `ChangeLog.txt`
   - [ ] Ensure ChangeLog.txt is sync'd between alpha and stable branches
+  - [ ] Check the linked issues: ask people to check if any are missing, remove the not fixed ones
+  - [ ] Run `tools/fetch-changelogs.py $(TOR_BROWSER_VERSION)` or `tools/fetch-changelogs.py '#$(ISSUE_NUMBER)'`
+    - Make sure you have `requests` installed (e.g., `apt install python3-requests`)
+    - The first time you run this script you will need to generate an access token; the script will guide you
+  - [ ] Copy the output of the script to the beginning of `ChangeLog.txt` and adjust its output
+    - At the moment, the script does not create a _Build System_ section
+    - If you used the issue number, you will need to write the Tor Browser version manually
 - [ ] Open MR with above changes
 - [ ] Begin build on `$(BUILD_SERVER)` (fix any issues which come up and update MR)
 - [ ] Sign/Tag commit: `make signtag-alpha`


=====================================
tools/.gitignore
=====================================
@@ -1 +1,2 @@
 _repackaged
+.changelogs_token


=====================================
tools/fetch-changelogs.py
=====================================
@@ -0,0 +1,140 @@
+#!/usr/bin/env python3
+from datetime import datetime
+import enum
+from pathlib import Path
+import sys
+
+import requests
+
+
+GITLAB = "https://gitlab.torproject.org"
+API_URL = f"{GITLAB}/api/v4"
+PROJECT_ID = 473
+
+
+class Platform(enum.IntFlag):
+    WINDOWS = 8
+    MACOS = 4
+    LINUX = 2
+    ANDROID = 1
+    DESKTOP = 8 | 4 | 2
+    ALL_PLATFORMS = 8 | 4 | 2 | 1
+
+
+class Issue:
+    def __init__(self, j):
+        self.title = j["title"]
+        self.project, self.number = (
+            j["references"]["full"].rsplit("/", 2)[-1].split("#")
+        )
+        self.platform = 0
+        self.num_platforms = 0
+        if "Desktop" in j["labels"]:
+            self.platform = Platform.DESKTOP
+            self.num_platforms += 3
+        else:
+            if "Windows" in j["labels"]:
+                self.platform |= Platform.WINDOWS
+                self.num_platforms += 1
+            if "MacOS" in j["labels"]:
+                self.platform |= Platform.MACOS
+                self.num_platforms += 1
+            if "Linux" in j["labels"]:
+                self.platform |= Platform.LINUX
+                self.num_platforms += 1
+        if "Android" in j["labels"]:
+            self.platform |= Platform.ANDROID
+            self.num_platforms += 1
+        if not self.platform:
+            self.platform = Platform.ALL_PLATFORMS
+            self.num_platforms = 4
+
+    def get_platforms(self):
+        if self.platform == Platform.ALL_PLATFORMS:
+            return "All Platforms"
+        platforms = []
+        if self.platform & Platform.WINDOWS:
+            platforms.append("Windows")
+        if self.platform & Platform.MACOS:
+            platforms.append("macOS")
+        if self.platform & Platform.LINUX:
+            platforms.append("Linux")
+        if self.platform & Platform.ANDROID:
+            platforms.append("Android")
+        return " + ".join(platforms)
+
+    def __str__(self):
+        return f"Bug {self.number}: {self.title} [{self.project}]"
+
+    def __lt__(self, other):
+        return self.number < other.number
+
+
+if len(sys.argv) < 2:
+    print(f"Usage: {sys.argv[0]} version-to-release or #issue-id")
+    sys.exit(1)
+
+token_file = Path(__file__).parent / ".changelogs_token"
+if not token_file.exists():
+    print(
+        f"Please add your personal GitLab token (with 'read_api' scope) to {token_file}"
+    )
+    print(
+        f"Please go to {GITLAB}/-/profile/personal_access_tokens and generate it."
+    )
+    token = input("Please enter the new token: ").strip()
+    if not token:
+        print("Invalid token!")
+        sys.exit(2)
+    with token_file.open("w") as f:
+        f.write(token)
+with token_file.open() as f:
+    token = f.read().strip()
+headers = {"PRIVATE-TOKEN": token}
+
+if sys.argv[1][0] != "#":
+    version = sys.argv[1]
+    r = requests.get(
+        f"{API_URL}/projects/{PROJECT_ID}/issues?labels=Release Prep",
+        headers=headers,
+    )
+    issue = None
+    for i in r.json():
+        if i["title"].find(sys.argv[1]) != -1:
+            if issue is None:
+                issue = i
+            else:
+                print("More than one matching issue found!")
+                print("Please use the issue id.")
+                sys.exit(3)
+    if not issue:
+        print(
+            "Release preparation issue not found. Please make sure it has ~Release Prep."
+        )
+        sys.exit(4)
+    iid = issue["iid"]
+else:
+    version = "????"
+    iid = sys.argv[1][1:]
+
+r = requests.get(
+    f"{API_URL}/projects/{PROJECT_ID}/issues/{iid}/links", headers=headers
+)
+linked = {}
+for i in r.json():
+    i = Issue(i)
+    if i.platform not in linked:
+        linked[i.platform] = []
+    linked[i.platform].append(i)
+linked = sorted(
+    linked.values(),
+    key=lambda issues: (issues[0].num_platforms << 8) | issues[0].platform,
+    reverse=True,
+)
+
+date = datetime.now().strftime("%B %d %Y")
+print(f"Tor Browser {version} - {date}")
+for issues in linked:
+    print(f" * {issues[0].get_platforms()}")
+    for i in sorted(issues):
+        print(f"   * {i}")



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/2318e2425ef612d63df99bc681cbd8cce3531a95

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser-build/-/commit/2318e2425ef612d63df99bc681cbd8cce3531a95
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20221220/20283003/attachment-0001.htm>


More information about the tbb-commits mailing list