Skip to content

Commit 2879a03

Browse files
authored
[workflows] Fix release note request workflow (llvm#94784)
We need to use the issue-write workflow to write the comments, because pull_request targets don't have permissions to write comments.
1 parent 7a03666 commit 2879a03

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

.github/workflows/issue-write.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
workflows:
66
- "Check code formatting"
77
- "Check for private emails used in PRs"
8+
- "PR Request Release Note"
89
types:
910
- completed
1011

@@ -92,7 +93,11 @@ jobs:
9293
9394
var pr_number = 0;
9495
gql_result.repository.ref.associatedPullRequests.nodes.forEach((pr) => {
95-
if (pr.baseRepository.owner.login = context.repo.owner && pr.state == 'OPEN') {
96+
97+
// The largest PR number is the one we care about. The only way
98+
// to have more than one associated pull requests is if all the
99+
// old pull requests are in the closed state.
100+
if (pr.baseRepository.owner.login = context.repo.owner && pr.number > pr_number) {
96101
pr_number = pr.number;
97102
}
98103
});

.github/workflows/pr-request-release-note.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: PR Request Release Note
22

33
permissions:
44
contents: read
5-
pull-requests: write
65

76
on:
87
pull_request:
@@ -41,3 +40,10 @@ jobs:
4140
--token "$GITHUB_TOKEN" \
4241
request-release-note \
4342
--pr-number ${{ github.event.pull_request.number}}
43+
44+
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
45+
if: always()
46+
with:
47+
name: workflow-args
48+
path: |
49+
comments

llvm/utils/git/github-automation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import argparse
1212
from git import Repo # type: ignore
1313
import html
14+
import json
1415
import github
1516
import os
1617
import re
@@ -653,7 +654,13 @@ def request_release_note(token: str, repo_name: str, pr_number: int):
653654
mention = f"@{submitter}"
654655

655656
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. "
656-
pr.as_issue().create_comment(comment)
657+
try:
658+
pr.as_issue().create_comment(comment)
659+
except:
660+
# Failed to create comment so emit file instead
661+
with open("comments", "w") as file:
662+
data = [{"body": comment}]
663+
json.dump(data, file)
657664

658665

659666
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)