[llvm] Pr from here (PR #72277)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 08:03:00 PST 2023
https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/72277
None
>From 0116b6bcb7b9a3635b56492fa9ef74164c25b894 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 13 Nov 2023 13:18:16 +0000
Subject: [PATCH 1/4] [GitHub] Add Greeting comment to new PRs with useful
information
This adds a new workflow that responds to PRs that are opened
with a comment thanking the author for their contribution, and
provides answers to common problems (problem for now, could expand later).
According to my testing, and the docs here:
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
`opened` will only trigger on the first opening, not a re-open.
I considered including this comment in the one the labeller adds,
but that means that it would be emailed to all subscribers not just
the author.
Though it's still possible that this workflow would end up commenting
after another one, in which case subscribers would get a notification.
---
.github/workflows/pr-greeter.yml | 27 ++++++++++++++++++++++
llvm/utils/git/github-automation.py | 35 +++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 .github/workflows/pr-greeter.yml
diff --git a/.github/workflows/pr-greeter.yml b/.github/workflows/pr-greeter.yml
new file mode 100644
index 000000000000000..3c90917eb643b0b
--- /dev/null
+++ b/.github/workflows/pr-greeter.yml
@@ -0,0 +1,27 @@
+name: PR Greeter
+
+on:
+ pull_request_target:
+ types: [ opened ]
+
+permissions:
+ pull-requests: write
+
+jobs:
+ greet:
+ runs-on: ubuntu-latest
+ if: github.repository == 'DavidSpickett/llvm-project'
+ steps:
+ - name: Setup Automation Script
+ run: |
+ curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/github-automation.py
+ curl -O -L --fail https://raw.githubusercontent.com/"$GITHUB_REPOSITORY"/main/llvm/utils/git/requirements.txt
+ chmod a+x github-automation.py
+ pip install -r requirements.txt
+
+ - name: Greet Author
+ run: |
+ ./github-automation.py \
+ --token '${{ secrets.GITHUB_TOKEN }}' \
+ pr-greeter \
+ --issue-number "${{ github.event.pull_request.number }}"
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index ad1878d41193920..be4962b8093ce9e 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -211,6 +211,35 @@ def _get_curent_team(self) -> Optional[github.Team.Team]:
return None
+class PRGreeter:
+ def __init__(self, token: str, repo: str, pr_number: int):
+ repo = github.Github(token).get_repo(repo)
+ self.pr = repo.get_issue(pr_number).as_pull_request()
+
+ def run(self) -> bool:
+ # We assume that this is only called for a PR that has just been opened.
+
+ # This text is using Markdown formatting.
+ comment = f"""\
+Thank you for submitting a Pull Request (PR) to the LLVM Project!
+
+You can add reviewers by using the "Reviewers" section on this page.
+
+If this is not working for you, it's probably because you don't have write
+permissions for the repository. In which case you can instead tag reviewers by
+name in a comment by using `@` followed by their GitHub username.
+
+If you have received no comments on your PR for a week, you can request a review
+by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
+is once a week. Please remember that you are asking for valuable time from other developers.
+
+If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html).
+
+You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/)."""
+ self.pr.as_issue().create_comment(comment)
+ return True
+
+
def setup_llvmbot_git(git_dir="."):
"""
Configure the git repo in `git_dir` with the llvmbot account so
@@ -655,6 +684,9 @@ def execute_command(self) -> bool:
pr_subscriber_parser.add_argument("--label-name", type=str, required=True)
pr_subscriber_parser.add_argument("--issue-number", type=int, required=True)
+pr_greeter_parser = subparsers.add_parser("pr-greeter")
+pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
+
release_workflow_parser = subparsers.add_parser("release-workflow")
release_workflow_parser.add_argument(
"--llvm-project-dir",
@@ -705,6 +737,9 @@ def execute_command(self) -> bool:
args.token, args.repo, args.issue_number, args.label_name
)
pr_subscriber.run()
+elif args.command == "pr-greeter":
+ pr_greeter = PRGreeter(args.token, args.repo, args.issue_number)
+ pr_greeter.run()
elif args.command == "release-workflow":
release_workflow = ReleaseWorkflow(
args.token,
>From e2d50f95bfee52126e7e36389a1428f94dc83f77 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Tue, 14 Nov 2023 15:48:12 +0000
Subject: [PATCH 2/4] debug
---
llvm/utils/git/github-automation.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index be4962b8093ce9e..41adbb369cde649 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -217,6 +217,7 @@ def __init__(self, token: str, repo: str, pr_number: int):
self.pr = repo.get_issue(pr_number).as_pull_request()
def run(self) -> bool:
+ print(dir(self.pr))
# We assume that this is only called for a PR that has just been opened.
# This text is using Markdown formatting.
>From 00e4ab1d9ab0ff91f61a5189ebba99d25f90a4b8 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Tue, 14 Nov 2023 16:01:17 +0000
Subject: [PATCH 3/4] try role check
---
.github/workflows/pr-greeter.yml | 6 ++++--
llvm/utils/git/github-automation.py | 1 -
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/pr-greeter.yml b/.github/workflows/pr-greeter.yml
index 3c90917eb643b0b..7c0d5b7ced822f0 100644
--- a/.github/workflows/pr-greeter.yml
+++ b/.github/workflows/pr-greeter.yml
@@ -5,12 +5,14 @@ on:
types: [ opened ]
permissions:
- pull-requests: write
+ contents: read
jobs:
greet:
runs-on: ubuntu-latest
- if: github.repository == 'DavidSpickett/llvm-project'
+ permissions:
+ pull-requests: write
+ if: github.repository == 'DavidSpickett/llvm-project' && (github.event.pull_request.author.assocation == OWNER)
steps:
- name: Setup Automation Script
run: |
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 41adbb369cde649..be4962b8093ce9e 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -217,7 +217,6 @@ def __init__(self, token: str, repo: str, pr_number: int):
self.pr = repo.get_issue(pr_number).as_pull_request()
def run(self) -> bool:
- print(dir(self.pr))
# We assume that this is only called for a PR that has just been opened.
# This text is using Markdown formatting.
>From 244a23667970c5d41fc2cb44ad6968a7755d1744 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 13 Nov 2023 13:21:11 +0000
Subject: [PATCH 4/4] Test PR
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index 4ae7eaf9b083a57..64ca27cf734c16c 100644
--- a/README.md
+++ b/README.md
@@ -40,3 +40,5 @@ chat](https://discord.gg/xS7Z362),
The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
participants to all modes of communication within the project.
+
+...t
More information about the llvm-commits
mailing list