|
| 1 | +name: Check for External Repo Sync PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + invalid-repo-sync-check: |
| 13 | + name: Close external Repo Sync PRs |
| 14 | + if: ${{ github.repository == 'github/docs' && github.ref == 'refs/heads/repo-sync' }} |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9 |
| 18 | + with: |
| 19 | + github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }} |
| 20 | + script: | |
| 21 | +
|
| 22 | + const prCreator = context.payload.sender.login |
| 23 | +
|
| 24 | + // If the PR creator is the expected account, stop now |
| 25 | + if (prCreator === 'Octomerger') { |
| 26 | + return |
| 27 | + } |
| 28 | +
|
| 29 | + try { |
| 30 | + await github.teams.getMembershipForUserInOrg({ |
| 31 | + org: 'github', |
| 32 | + team_slug: 'employees', |
| 33 | + username: prCreator |
| 34 | + }) |
| 35 | +
|
| 36 | + // If the PR creator is a GitHub employee, stop now |
| 37 | + return |
| 38 | + } catch (err) { |
| 39 | + // An error will be thrown if the user is not a GitHub employee. |
| 40 | + // That said, we still want to proceed anyway! |
| 41 | + } |
| 42 | +
|
| 43 | + const pr = context.payload.pull_request |
| 44 | + const { owner, repo } = context.repo |
| 45 | +
|
| 46 | + // Close the PR and add the invalid label |
| 47 | + await github.issues.update({ |
| 48 | + owner: owner, |
| 49 | + repo: repo, |
| 50 | + issue_number: pr.number, |
| 51 | + labels: ['invalid'], |
| 52 | + state: 'closed' |
| 53 | + }) |
| 54 | +
|
| 55 | + // Comment on the PR |
| 56 | + await github.issues.createComment({ |
| 57 | + owner: owner, |
| 58 | + repo: repo, |
| 59 | + issue_number: pr.number, |
| 60 | + body: "Please leave this `repo-sync` branch to the robots!\n\nI'm going to close this pull request now, but feel free to open a new issue or ask any questions in [discussions](https://github.com/github/docs/discussions)!" |
| 61 | + }) |
0 commit comments