[llvm] [workflows] Add a job for requesting a release note on release branch PRs (PR #91826)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 16:48:00 PDT 2024


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/91826

>From bf1703f3d4d3b111fa1c999a87060cfc991a4eb9 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 10 May 2024 22:45:48 +0000
Subject: [PATCH 1/3] [workflows] Add a job for requesting a release note on
 merged PRs

---
 .github/workflows/pr-request-release-note.yml | 43 +++++++++++++++++++
 llvm/utils/git/github-automation.py           | 33 ++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 .github/workflows/pr-request-release-note.yml

diff --git a/.github/workflows/pr-request-release-note.yml b/.github/workflows/pr-request-release-note.yml
new file mode 100644
index 0000000000000..0fcb95f1fe294
--- /dev/null
+++ b/.github/workflows/pr-request-release-note.yml
@@ -0,0 +1,43 @@
+name: PR Request Release Note
+
+permissions:
+  contents: read
+  pull-requests: write
+
+on:
+  pull_request:
+    types:
+      - closed
+
+jobs:
+  request-release-note:
+    if: >-
+      github.repository_owner == 'llvm' &&
+      startsWith(github.ref, 'refs/heads/release')
+
+    runs-on: ubuntu-latest
+    steps:
+      # We need to pull the script from the main branch, so that we ensure
+      # we get the latest version of this script.
+      - name: Checkout Scripts
+        uses: actions/checkout at b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+        with:
+          sparse-checkout: |
+            llvm/utils/git/requirements.txt
+            llvm/utils/git/github-automation.py
+          sparse-checkout-cone-mode: false
+
+      - name: Install Dependencies
+        run: |
+          pip install -r llvm/utils/git/requirements.txt
+
+      - name: Request Release Note
+        env:
+          # We need to use an llvmbot token here, because we are mentioning a user.
+          GITHUB_TOKEN: ${{ github.token }}
+        run: |
+          python3 llvm/utils/git/github-automation.py \
+            --repo "$GITHUB_REPOSITORY" \
+            --token "$GITHUB_TOKEN" \
+            request-release-note \
+            --pr-number ${{ github.event.pull_request.number}}
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 1b5141e42594b..ab9b5e07230d4 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -637,6 +637,25 @@ def execute_command(self) -> bool:
         return False
 
 
+def request_release_note(token:str, repo_name:str, pr_number:int):
+    repo = github.Github(token).get_repo(repo_name)
+    pr = repo.get_issue(pr_number).as_pull_request()
+    submitter = pr.user.login
+    if submitter == 'llvmbot':
+        m = re.search("Requested by: @(.+)$", pr.body)
+        if not m:
+            submitter = None
+            print("Warning could not determine user who requested backport.")
+        submitter = m.group(1)
+
+    mention = ''
+    if submitter:
+        mention = f'@{submitter}'
+
+    comment = f"{mention} (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix.  When you are done, please add the release:note label to this PR. "
+    pr.as_issue().create_comment(comment)
+
+
 parser = argparse.ArgumentParser()
 parser.add_argument(
     "--token", type=str, required=True, help="GitHub authentication token"
@@ -703,6 +722,18 @@ def execute_command(self) -> bool:
     help="The user that requested this backport",
 )
 
+request_release_note_parser = subparsers.add_parser(
+    "request-release-note",
+    help="Request a release note for a pull request",
+)
+request_release_note_parser.add_argument(
+    "--pr-number",
+    type=int,
+    required=True,
+    help="The pull request to request the release note",
+)
+
+
 args = parser.parse_args()
 
 if args.command == "issue-subscriber":
@@ -743,3 +774,5 @@ def execute_command(self) -> bool:
             sys.exit(1)
 elif args.command == "setup-llvmbot-git":
     setup_llvmbot_git()
+elif args.command == "request-release-note":
+    request_release_note(args.token, args.repo, args.pr_number)

>From 2ffd6cf6c0c96ffae3ecd6534cb3a98d68f16e2c Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 10 May 2024 23:39:01 +0000
Subject: [PATCH 2/3] Fix format errors

---
 llvm/utils/git/github-automation.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index ab9b5e07230d4..aa70525190d40 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -641,16 +641,16 @@ def request_release_note(token:str, repo_name:str, pr_number:int):
     repo = github.Github(token).get_repo(repo_name)
     pr = repo.get_issue(pr_number).as_pull_request()
     submitter = pr.user.login
-    if submitter == 'llvmbot':
+    if submitter == "llvmbot":
         m = re.search("Requested by: @(.+)$", pr.body)
         if not m:
             submitter = None
             print("Warning could not determine user who requested backport.")
         submitter = m.group(1)
 
-    mention = ''
+    mention = ""
     if submitter:
-        mention = f'@{submitter}'
+        mention = f"@{submitter}"
 
     comment = f"{mention} (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix.  When you are done, please add the release:note label to this PR. "
     pr.as_issue().create_comment(comment)

>From 0d1ccbb361adb620ba315d3e499eb94c7401ab32 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 10 May 2024 23:46:30 +0000
Subject: [PATCH 3/3] Fix formatting

---
 llvm/utils/git/github-automation.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index aa70525190d40..1766ccb38ba25 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -637,7 +637,7 @@ def execute_command(self) -> bool:
         return False
 
 
-def request_release_note(token:str, repo_name:str, pr_number:int):
+def request_release_note(token: str, repo_name: str, pr_number: int):
     repo = github.Github(token).get_repo(repo_name)
     pr = repo.get_issue(pr_number).as_pull_request()
     submitter = pr.user.login



More information about the llvm-commits mailing list