Skip to content

Commit

Permalink
✨ Request PR review from users and teams (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Feb 8, 2022
1 parent a547f3c commit 65a0234
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
40 changes: 39 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -18193,7 +18219,9 @@ const {
SKIP_PR,
ORIGINAL_MESSAGE,
COMMIT_AS_PR_TITLE,
FORK
FORK,
REVIEWERS,
TEAM_REVIEWERS
} = __nccwpck_require__(4570)

const run = async () => {
Expand Down Expand Up @@ -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(' ')
Expand Down
8 changes: 8 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }`
Expand Down
18 changes: 18 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const {
SKIP_PR,
ORIGINAL_MESSAGE,
COMMIT_AS_PR_TITLE,
FORK
FORK,
REVIEWERS,
TEAM_REVIEWERS
} = require('./config')

const run = async () => {
Expand Down Expand Up @@ -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(' ')
Expand Down

0 comments on commit 65a0234

Please sign in to comment.