|
| 1 | +# Welcome new contributors (per project doc: "Pull requests are welcome. Found a bug? Open an issue.") |
| 2 | +name: Welcome new contributors |
| 3 | + |
| 4 | +on: |
| 5 | + issues: |
| 6 | + types: [opened] |
| 7 | + pull_request: |
| 8 | + types: [opened] |
| 9 | + |
| 10 | +permissions: |
| 11 | + issues: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + welcome: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Welcome on first issue |
| 19 | + if: github.event_name == 'issues' |
| 20 | + uses: actions/github-script@v7 |
| 21 | + with: |
| 22 | + script: | |
| 23 | + const author = context.payload.issue.user.login; |
| 24 | + const repo = context.repo; |
| 25 | + const { data: issueData } = await github.rest.search.issuesAndPullRequests({ |
| 26 | + q: `repo:${repo.owner}/${repo.repo} is:issue author:${author}` |
| 27 | + }); |
| 28 | + const isFirstIssue = issueData.total_count <= 1; |
| 29 | + const welcome = isFirstIssue |
| 30 | + ? 'Welcome to the project! ' |
| 31 | + : ''; |
| 32 | + const body = welcome + 'Thanks for opening this issue. Pull requests are welcome—see [CONTRIBUTING](https://github.com/' + repo.owner + '/' + repo.repo + '/blob/main/CONTRIBUTING.md) for guidelines. Found a bug? Describe steps to reproduce and we\'ll label it.'; |
| 33 | + await github.rest.issues.createComment({ |
| 34 | + owner: repo.owner, |
| 35 | + repo: repo.repo, |
| 36 | + issue_number: context.payload.issue.number, |
| 37 | + body |
| 38 | + }); |
| 39 | +
|
| 40 | + - name: Welcome on first PR |
| 41 | + if: github.event_name == 'pull_request' |
| 42 | + uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + script: | |
| 45 | + const author = context.payload.pull_request.user.login; |
| 46 | + const repo = context.repo; |
| 47 | + const { data: prData } = await github.rest.search.issuesAndPullRequests({ |
| 48 | + q: `repo:${repo.owner}/${repo.repo} is:pr author:${author}` |
| 49 | + }); |
| 50 | + const isFirstPR = prData.total_count <= 1; |
| 51 | + const welcome = isFirstPR |
| 52 | + ? 'Welcome to the project! ' |
| 53 | + : ''; |
| 54 | + const body = welcome + 'Thanks for your pull request. See [CONTRIBUTING](https://github.com/' + repo.owner + '/' + repo.repo + '/blob/main/CONTRIBUTING.md) for guidelines. We\'ll review as soon as we can.'; |
| 55 | + await github.rest.issues.createComment({ |
| 56 | + owner: repo.owner, |
| 57 | + repo: repo.repo, |
| 58 | + issue_number: context.payload.pull_request.number, |
| 59 | + body |
| 60 | + }); |
0 commit comments