|
| 1 | +name: Auto-close External Pull Requests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, reopened] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + auto_close: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Check if user is organization member |
| 13 | + id: check-membership |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + github-token: ${{ secrets.GH_AUTO_CLOSE_PR_TOKEN }} |
| 17 | + script: | |
| 18 | + const org = 'Appwrite'; |
| 19 | + let isMember = 'non-member'; |
| 20 | + try { |
| 21 | + await github.rest.orgs.checkMembershipForUser({ |
| 22 | + org: org, |
| 23 | + username: context.payload.pull_request.user.login |
| 24 | + }); |
| 25 | + console.log('PR author is a core member. Keeping PR open.'); |
| 26 | + isMember = 'member'; |
| 27 | + } catch (error) { |
| 28 | + console.log('PR author is not a core member.'); |
| 29 | + } |
| 30 | + return isMember; |
| 31 | + result-encoding: string |
| 32 | + |
| 33 | + - name: Set member output |
| 34 | + id: set-output |
| 35 | + run: echo "result=${{ steps.check-membership.outputs.result }}" >> $GITHUB_ENV |
| 36 | + |
| 37 | + - name: Comment on PR |
| 38 | + if: env.result == 'non-member' |
| 39 | + uses: actions/github-script@v7 |
| 40 | + with: |
| 41 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + script: | |
| 43 | + await github.rest.issues.createComment({ |
| 44 | + issue_number: context.issue.number, |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + body: 'This library is auto-generated by the Appwrite [SDK Generator](https://github.com/appwrite/sdk-generator), and does not accept pull requests directly. To learn more about how you can help us improve this SDK, please check the [contributing guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before submitting a pull request.' |
| 48 | + }); |
| 49 | + console.log('Comment added to PR.'); |
| 50 | +
|
| 51 | + - name: Close PR |
| 52 | + if: env.result == 'non-member' |
| 53 | + uses: actions/github-script@v7 |
| 54 | + with: |
| 55 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + script: | |
| 57 | + await github.rest.pulls.update({ |
| 58 | + pull_number: context.issue.number, |
| 59 | + owner: context.repo.owner, |
| 60 | + repo: context.repo.repo, |
| 61 | + state: 'closed' |
| 62 | + }); |
| 63 | + console.log('PR closed.'); |
0 commit comments