|
1 | 1 | # The docs.github.com project has two repositories: github/docs (public) and github/docs-internal (private)
|
2 | 2 | #
|
3 |
| -# This GitHub Actions workflow keeps the main branch of those two repos in sync. |
| 3 | +# This GitHub Actions workflow keeps the `main` branch of those two repos in sync. |
4 | 4 | #
|
5 | 5 | # For more details, see https://github.com/repo-sync/repo-sync#how-it-works
|
6 | 6 |
|
7 | 7 | name: Repo Sync
|
8 | 8 |
|
9 |
| -# **What it does**: Syncs docs and docs-internal. |
10 |
| -# **Why we have it**: To keep the open-source repository up-to-date, while still having an internal repository for sensitive work. |
| 9 | +# **What it does**: |
| 10 | +# - close-invalid-repo-sync: Close repo sync pull requests not created by Octomerger or a Hubber. |
| 11 | +# - repo-sync: Syncs docs and docs-internal. |
| 12 | +# **Why we have it**: |
| 13 | +# - close-invalid-repo-sync: Another form of spam prevention for the open-source repository. |
| 14 | +# - repo-sync: To keep the open-source repository up-to-date, while still having an internal |
| 15 | +# repository for sensitive work. |
11 | 16 | # **Who does it impact**: Open-source.
|
12 | 17 |
|
13 | 18 | on:
|
|
16 | 21 | - cron: '*/15 * * * *' # every 15 minutes
|
17 | 22 |
|
18 | 23 | jobs:
|
| 24 | + close-invalid-repo-sync: |
| 25 | + name: Close invalid Repo Sync PRs |
| 26 | + if: github.repository == 'github/docs' |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Find pull request |
| 30 | + uses: juliangruber/find-pull-request-action@2fc55e82a6d5d36fe1e7f1848f7e64fd02d99de9 |
| 31 | + id: find-pull-request |
| 32 | + with: |
| 33 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + branch: repo-sync |
| 35 | + base: main |
| 36 | + |
| 37 | + - name: Close pull request if unwanted |
| 38 | + if: ${{ steps.find-pull-request.outputs.number }} |
| 39 | + uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9 |
| 40 | + with: |
| 41 | + github-token: ${{ secrets.DOCUBOT_FR_PROJECT_BOARD_WORKFLOWS_REPO_ORG_READ_SCOPES }} |
| 42 | + script: | |
| 43 | + const { owner, repo } = context.repo |
| 44 | +
|
| 45 | + const pr = await github.pulls.get({ |
| 46 | + owner, |
| 47 | + repo, |
| 48 | + pull_number: parseInt(${{ steps.find-pull-request.outputs.number }}) |
| 49 | + }) |
| 50 | +
|
| 51 | + const prCreator = pr.user.login |
| 52 | +
|
| 53 | + // If the PR creator is the expected account, stop now |
| 54 | + if (prCreator === 'Octomerger') { |
| 55 | + return |
| 56 | + } |
| 57 | +
|
| 58 | + try { |
| 59 | + await github.teams.getMembershipForUserInOrg({ |
| 60 | + org: 'github', |
| 61 | + team_slug: 'employees', |
| 62 | + username: prCreator |
| 63 | + }) |
| 64 | +
|
| 65 | + // If the PR creator is a GitHub employee, stop now |
| 66 | + return |
| 67 | + } catch (err) { |
| 68 | + // An error will be thrown if the user is not a GitHub employee. |
| 69 | + // That said, we still want to proceed anyway! |
| 70 | + } |
| 71 | +
|
| 72 | + // Close the PR and add the invalid label |
| 73 | + await github.issues.update({ |
| 74 | + owner, |
| 75 | + repo, |
| 76 | + issue_number: pr.number, |
| 77 | + labels: ['invalid'], |
| 78 | + state: 'closed' |
| 79 | + }) |
| 80 | +
|
| 81 | + // Comment on the PR |
| 82 | + await github.issues.createComment({ |
| 83 | + owner, |
| 84 | + repo, |
| 85 | + issue_number: pr.number, |
| 86 | + 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)!" |
| 87 | + }) |
| 88 | +
|
19 | 89 | repo-sync:
|
| 90 | + needs: close-invalid-repo-sync |
20 | 91 | if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
|
21 | 92 | name: Repo Sync
|
22 | 93 | runs-on: ubuntu-latest
|
|
0 commit comments