diff --git a/README.md b/README.md index 1a304be0..3e7599e3 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,9 @@ Here are all the inputs [repo-file-sync-action](https://github.com/BetaHuhn/repo | `GH_INSTALLATION_TOKEN` | Token from a GitHub App installation | **`GH_PAT` or `GH_INSTALLATION_TOKEN` required** | N/A | | `CONFIG_PATH` | Path to the sync configuration file | **No** | .github/sync.yml | | `PR_LABELS` | Labels which will be added to the pull request. Set to false to turn off | **No** | sync | -| `ASSIGNEES` | People to assign to the pull request | **No** | N/A | +| `ASSIGNEES` | Users to assign to the pull request | **No** | N/A | +| `REVIEWERS` | Users to request a review of the pull request from | **No** | N/A | +| `TEAM_REVIEWERS` | Teams to request a review of the pull request from | **No** | N/A | | `COMMIT_PREFIX` | Prefix for commit message and pull request title | **No** | 🔄 | | `COMMIT_BODY` | Commit message body. Will be appended to commit message, separated by two line returns. | **No** | '' | | `ORIGINAL_MESSAGE` | Use original commit message instead. Only works if the file(s) were changed and the action was triggered by pushing a single commit. | **No** | false | @@ -328,6 +330,23 @@ You can tell [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync- ASSIGNEES: BetaHuhn ``` +### Request a PR review + +You can tell [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-action) to request a review of the PR from users with `REVIEWERS` and from teams with `TEAM_REVIEWERS`: + +**.github/workflows/sync.yml** + +```yml +- name: Run GitHub File Sync + uses: BetaHuhn/repo-file-sync-action@v1 + with: + GH_PAT: ${{ secrets.GH_PAT }} + REVIEWERS: | + BetaHuhn + BetaHuhnBot + TEAM_REVIEWERS: engineering +``` + ### Custom GitHub Enterprise Host If your target repository is hosted on a GitHub Enterprise Server you can specify a custom host name like this: diff --git a/action.yml b/action.yml index 83110fe7..d7935825 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,15 @@ inputs: required: false ASSIGNEES: description: | - People to assign to the pull request. Defaults to none + Users to assign to the pull request. Defaults to none + required: false + REVIEWERS: + description: | + Users to request a review of the pull request from. Defaults to none + required: false + TEAM_REVIEWERS: + description: | + Teams to request a review of the pull request from. Defaults to none required: false COMMIT_PREFIX: description: | diff --git a/dist/index.js b/dist/index.js index 908cc34b..a8d5e01d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -17220,6 +17220,14 @@ try { key: 'ASSIGNEES', type: 'array' }), + REVIEWERS: getInput({ + key: 'REVIEWERS', + type: 'array' + }), + TEAM_REVIEWERS: getInput({ + key: 'TEAM_REVIEWERS', + type: 'array' + }), TMP_DIR: getInput({ key: 'TMP_DIR', default: `tmp-${ Date.now().toString() }` @@ -17846,6 +17854,24 @@ class Git { }) } + async addPrReviewers(reviewers) { + await this.github.pulls.requestReviewers({ + owner: this.repo.user, + repo: this.repo.name, + pull_number: this.existingPr.number, + reviewers: reviewers + }) + } + + async addPrTeamReviewers(reviewers) { + await this.github.pulls.requestReviewers({ + owner: this.repo.user, + repo: this.repo.name, + pull_number: this.existingPr.number, + team_reviewers: reviewers + }) + } + async createGithubTreeAndCommit(tree, commitMessage) { core.debug(`Creating a GitHub tree`) let treeSha @@ -18193,7 +18219,9 @@ const { SKIP_PR, ORIGINAL_MESSAGE, COMMIT_AS_PR_TITLE, - FORK + FORK, + REVIEWERS, + TEAM_REVIEWERS } = __nccwpck_require__(4570) const run = async () => { @@ -18358,6 +18386,16 @@ const run = async () => { core.info(`Adding assignee(s) "${ ASSIGNEES.join(', ') }" to PR`) await git.addPrAssignees(ASSIGNEES) } + + if (REVIEWERS !== undefined && REVIEWERS.length > 0 && !FORK) { + core.info(`Adding reviewer(s) "${ REVIEWERS.join(', ') }" to PR`) + await git.addPrReviewers(REVIEWERS) + } + + if (TEAM_REVIEWERS !== undefined && TEAM_REVIEWERS.length > 0 && !FORK) { + core.info(`Adding team reviewer(s) "${ TEAM_REVIEWERS.join(', ') }" to PR`) + await git.addPrTeamReviewers(TEAM_REVIEWERS) + } } core.info(' ') diff --git a/src/config.js b/src/config.js index 631c9a23..2821dcfb 100644 --- a/src/config.js +++ b/src/config.js @@ -67,6 +67,14 @@ try { key: 'ASSIGNEES', type: 'array' }), + REVIEWERS: getInput({ + key: 'REVIEWERS', + type: 'array' + }), + TEAM_REVIEWERS: getInput({ + key: 'TEAM_REVIEWERS', + type: 'array' + }), TMP_DIR: getInput({ key: 'TMP_DIR', default: `tmp-${ Date.now().toString() }` diff --git a/src/git.js b/src/git.js index 301e2e6a..50091c2c 100644 --- a/src/git.js +++ b/src/git.js @@ -441,6 +441,24 @@ class Git { }) } + async addPrReviewers(reviewers) { + await this.github.pulls.requestReviewers({ + owner: this.repo.user, + repo: this.repo.name, + pull_number: this.existingPr.number, + reviewers: reviewers + }) + } + + async addPrTeamReviewers(reviewers) { + await this.github.pulls.requestReviewers({ + owner: this.repo.user, + repo: this.repo.name, + pull_number: this.existingPr.number, + team_reviewers: reviewers + }) + } + async createGithubTreeAndCommit(tree, commitMessage) { core.debug(`Creating a GitHub tree`) let treeSha diff --git a/src/index.js b/src/index.js index 0f0c9cb8..53c62907 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,9 @@ const { SKIP_PR, ORIGINAL_MESSAGE, COMMIT_AS_PR_TITLE, - FORK + FORK, + REVIEWERS, + TEAM_REVIEWERS } = require('./config') const run = async () => { @@ -182,6 +184,16 @@ const run = async () => { core.info(`Adding assignee(s) "${ ASSIGNEES.join(', ') }" to PR`) await git.addPrAssignees(ASSIGNEES) } + + if (REVIEWERS !== undefined && REVIEWERS.length > 0 && !FORK) { + core.info(`Adding reviewer(s) "${ REVIEWERS.join(', ') }" to PR`) + await git.addPrReviewers(REVIEWERS) + } + + if (TEAM_REVIEWERS !== undefined && TEAM_REVIEWERS.length > 0 && !FORK) { + core.info(`Adding team reviewer(s) "${ TEAM_REVIEWERS.join(', ') }" to PR`) + await git.addPrTeamReviewers(TEAM_REVIEWERS) + } } core.info(' ')