Skip to content

[GitHub] Add greeting comment to opened PRs from new contributors #72384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2023

Conversation

DavidSpickett
Copy link
Collaborator

This includes some commonly needed information like how to add reviewers.

This is implemented as a job before the labeler, so that on a new PR the comment is added before there are any subscribers and only the author gets a nofitication.

The labeler job depends on the greeter having run or having been skipped. So if the PR wasn't just opened, or it's from a regular contributor, the labeling still happens.

But we can be sure that when a greeting comment is left, it's the very first thing we do.

This includes some commonly needed information like how to add
reviewers.

This is implemented as a job before the labeler, so that on a new
PR the comment is added before there are any subscribers and only
the author gets a nofitication.

The labeler job depends on the greeter having run or having been skipped.
So if the PR wasn't just opened, or it's from a regular contributor,
the labeling still happens.

But we can be sure that when a greeting comment is left, it's the
very first thing we do.
@llvmbot
Copy link
Member

llvmbot commented Nov 15, 2023

@llvm/pr-subscribers-github-workflow

Author: David Spickett (DavidSpickett)

Changes

This includes some commonly needed information like how to add reviewers.

This is implemented as a job before the labeler, so that on a new PR the comment is added before there are any subscribers and only the author gets a nofitication.

The labeler job depends on the greeter having run or having been skipped. So if the PR wasn't just opened, or it's from a regular contributor, the labeling still happens.

But we can be sure that when a greeting comment is left, it's the very first thing we do.


Full diff: https://github.com/llvm/llvm-project/pull/72384.diff

2 Files Affected:

  • (modified) .github/workflows/new-prs.yml (+29-2)
  • (modified) llvm/utils/git/github-automation.py (+36)
diff --git a/.github/workflows/new-prs.yml b/.github/workflows/new-prs.yml
index 9ba55d59ff15b4c..18caa408df57b60 100644
--- a/.github/workflows/new-prs.yml
+++ b/.github/workflows/new-prs.yml
@@ -15,16 +15,43 @@ on:
       - synchronize
 
 jobs:
-  automate-prs-labels:
+  greeter:
+    runs-on: ubuntu-latest
     permissions:
       pull-requests: write
+    # Only comment on PRs that have been opened for the first time, by someone
+    # new to LLVM or to GitHub as a whole.
+    if: >-
+      (github.repository == 'llvm/llvm-project') &&
+      (github.event.action == 'opened') &&
+      (github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' ||
+       github.event.pull_request.author_association == 'FIRST_TIMER')
+    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 }}"
+
+  automate-prs-labels:
+    # Greet first so that only the author gets that notification.
+    needs: greeter
     runs-on: ubuntu-latest
     # Ignore PRs with more than 10 commits.  Pull requests with a lot of
     # commits tend to be accidents usually when someone made a mistake while trying
     # to rebase.  We want to ignore these pull requests to avoid excessive
     # notifications.
+    # always() means that even if greeter is skipped, this job will run.
     if: >
-      github.repository == 'llvm/llvm-project' &&
+      always() && github.repository == 'llvm/llvm-project' &&
       github.event.pull_request.draft == false &&
       github.event.pull_request.commits < 10
     steps:
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index ad1878d41193920..4c1a4126a7776da 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -211,6 +211,36 @@ 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
+        # by a user new to LLVM and/or GitHub itself.
+
+        # 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 +685,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 +738,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,

@DavidSpickett
Copy link
Collaborator Author

While these configurations are pretty fragile and a pain to write, it's readable enough once it works, so I'd prefer to go with this solution. Easier to control notifications this way.

@DavidSpickett
Copy link
Collaborator Author

The message content is unchanged from the other PR.

@tru
Copy link
Collaborator

tru commented Nov 15, 2023

What's the difference between FIRST_TIME and FIRST_TIME_CONTRIBUTOR?

Also a question for @kbeyls - maybe we should note that committing to this repo is a sign that they have accepted the license and our "CLA". Not sure where that's documented right now, but I think it might be good to link to that so people have time to review it before the PR is accepted.

@kbeyls
Copy link
Collaborator

kbeyls commented Nov 15, 2023

What's the difference between FIRST_TIME and FIRST_TIME_CONTRIBUTOR?

Also a question for @kbeyls - maybe we should note that committing to this repo is a sign that they have accepted the license and our "CLA". Not sure where that's documented right now, but I think it might be good to link to that so people have time to review it before the PR is accepted.

We don't have a CLA, so I'm a bit confused about what you mean by "our CLA"?
If we want to point people to copyright and license information related to their contribution, I guess that https://llvm.org/docs/DeveloperPolicy.html#copyright-license-and-patents might be the best section to point to.

I think I've seen some other projects hosted on github use an auto-commenter like in this PR to point out (and let people tick off that they've understood and agreed with) which license they are contributing their code under.

I think it's probably best to not do this as part of this PR.
Maybe we should aim to get a useful commenter-bot for first-time contributors landed as part of this PR; and then use one or more issues/RFCs on how to further improve the content of the comment? That could list the ideas for e.g. pointing out license/CLA-related information and other stuff.

@DavidSpickett
Copy link
Collaborator Author

What's the difference between FIRST_TIME and FIRST_TIME_CONTRIBUTOR?

Documented in:
https://docs.github.com/en/graphql/reference/enums#commentauthorassociation

FIRST_TIMER is new to GitHub itself, so if you wanted to you could link to more info than someone who is just new to the repository I guess. We cater to both in the docs we have so I checked for either.

@DavidSpickett
Copy link
Collaborator Author

ping!

The message content has changed slightly since last time.

@DavidSpickett DavidSpickett merged commit 7724954 into llvm:main Dec 5, 2023
@DavidSpickett DavidSpickett deleted the greeting-first branch December 5, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants