Skip to content

Commit 65a0234

Browse files
committed
✨ Request PR review from users and teams (#162)
1 parent a547f3c commit 65a0234

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed

README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ Here are all the inputs [repo-file-sync-action](https://github.com/BetaHuhn/repo
106106
| `GH_INSTALLATION_TOKEN` | Token from a GitHub App installation | **`GH_PAT` or `GH_INSTALLATION_TOKEN` required** | N/A |
107107
| `CONFIG_PATH` | Path to the sync configuration file | **No** | .github/sync.yml |
108108
| `PR_LABELS` | Labels which will be added to the pull request. Set to false to turn off | **No** | sync |
109-
| `ASSIGNEES` | People to assign to the pull request | **No** | N/A |
109+
| `ASSIGNEES` | Users to assign to the pull request | **No** | N/A |
110+
| `REVIEWERS` | Users to request a review of the pull request from | **No** | N/A |
111+
| `TEAM_REVIEWERS` | Teams to request a review of the pull request from | **No** | N/A |
110112
| `COMMIT_PREFIX` | Prefix for commit message and pull request title | **No** | 🔄 |
111113
| `COMMIT_BODY` | Commit message body. Will be appended to commit message, separated by two line returns. | **No** | '' |
112114
| `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-
328330
ASSIGNEES: BetaHuhn
329331
```
330332

333+
### Request a PR review
334+
335+
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`:
336+
337+
**.github/workflows/sync.yml**
338+
339+
```yml
340+
- name: Run GitHub File Sync
341+
uses: BetaHuhn/repo-file-sync-action@v1
342+
with:
343+
GH_PAT: ${{ secrets.GH_PAT }}
344+
REVIEWERS: |
345+
BetaHuhn
346+
BetaHuhnBot
347+
TEAM_REVIEWERS: engineering
348+
```
349+
331350
### Custom GitHub Enterprise Host
332351

333352
If your target repository is hosted on a GitHub Enterprise Server you can specify a custom host name like this:

action.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ inputs:
2525
required: false
2626
ASSIGNEES:
2727
description: |
28-
People to assign to the pull request. Defaults to none
28+
Users to assign to the pull request. Defaults to none
29+
required: false
30+
REVIEWERS:
31+
description: |
32+
Users to request a review of the pull request from. Defaults to none
33+
required: false
34+
TEAM_REVIEWERS:
35+
description: |
36+
Teams to request a review of the pull request from. Defaults to none
2937
required: false
3038
COMMIT_PREFIX:
3139
description: |

dist/index.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -17220,6 +17220,14 @@ try {
1722017220
key: 'ASSIGNEES',
1722117221
type: 'array'
1722217222
}),
17223+
REVIEWERS: getInput({
17224+
key: 'REVIEWERS',
17225+
type: 'array'
17226+
}),
17227+
TEAM_REVIEWERS: getInput({
17228+
key: 'TEAM_REVIEWERS',
17229+
type: 'array'
17230+
}),
1722317231
TMP_DIR: getInput({
1722417232
key: 'TMP_DIR',
1722517233
default: `tmp-${ Date.now().toString() }`
@@ -17846,6 +17854,24 @@ class Git {
1784617854
})
1784717855
}
1784817856

17857+
async addPrReviewers(reviewers) {
17858+
await this.github.pulls.requestReviewers({
17859+
owner: this.repo.user,
17860+
repo: this.repo.name,
17861+
pull_number: this.existingPr.number,
17862+
reviewers: reviewers
17863+
})
17864+
}
17865+
17866+
async addPrTeamReviewers(reviewers) {
17867+
await this.github.pulls.requestReviewers({
17868+
owner: this.repo.user,
17869+
repo: this.repo.name,
17870+
pull_number: this.existingPr.number,
17871+
team_reviewers: reviewers
17872+
})
17873+
}
17874+
1784917875
async createGithubTreeAndCommit(tree, commitMessage) {
1785017876
core.debug(`Creating a GitHub tree`)
1785117877
let treeSha
@@ -18193,7 +18219,9 @@ const {
1819318219
SKIP_PR,
1819418220
ORIGINAL_MESSAGE,
1819518221
COMMIT_AS_PR_TITLE,
18196-
FORK
18222+
FORK,
18223+
REVIEWERS,
18224+
TEAM_REVIEWERS
1819718225
} = __nccwpck_require__(4570)
1819818226

1819918227
const run = async () => {
@@ -18358,6 +18386,16 @@ const run = async () => {
1835818386
core.info(`Adding assignee(s) "${ ASSIGNEES.join(', ') }" to PR`)
1835918387
await git.addPrAssignees(ASSIGNEES)
1836018388
}
18389+
18390+
if (REVIEWERS !== undefined && REVIEWERS.length > 0 && !FORK) {
18391+
core.info(`Adding reviewer(s) "${ REVIEWERS.join(', ') }" to PR`)
18392+
await git.addPrReviewers(REVIEWERS)
18393+
}
18394+
18395+
if (TEAM_REVIEWERS !== undefined && TEAM_REVIEWERS.length > 0 && !FORK) {
18396+
core.info(`Adding team reviewer(s) "${ TEAM_REVIEWERS.join(', ') }" to PR`)
18397+
await git.addPrTeamReviewers(TEAM_REVIEWERS)
18398+
}
1836118399
}
1836218400

1836318401
core.info(' ')

src/config.js

+8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ try {
6767
key: 'ASSIGNEES',
6868
type: 'array'
6969
}),
70+
REVIEWERS: getInput({
71+
key: 'REVIEWERS',
72+
type: 'array'
73+
}),
74+
TEAM_REVIEWERS: getInput({
75+
key: 'TEAM_REVIEWERS',
76+
type: 'array'
77+
}),
7078
TMP_DIR: getInput({
7179
key: 'TMP_DIR',
7280
default: `tmp-${ Date.now().toString() }`

src/git.js

+18
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,24 @@ class Git {
441441
})
442442
}
443443

444+
async addPrReviewers(reviewers) {
445+
await this.github.pulls.requestReviewers({
446+
owner: this.repo.user,
447+
repo: this.repo.name,
448+
pull_number: this.existingPr.number,
449+
reviewers: reviewers
450+
})
451+
}
452+
453+
async addPrTeamReviewers(reviewers) {
454+
await this.github.pulls.requestReviewers({
455+
owner: this.repo.user,
456+
repo: this.repo.name,
457+
pull_number: this.existingPr.number,
458+
team_reviewers: reviewers
459+
})
460+
}
461+
444462
async createGithubTreeAndCommit(tree, commitMessage) {
445463
core.debug(`Creating a GitHub tree`)
446464
let treeSha

src/index.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const {
1717
SKIP_PR,
1818
ORIGINAL_MESSAGE,
1919
COMMIT_AS_PR_TITLE,
20-
FORK
20+
FORK,
21+
REVIEWERS,
22+
TEAM_REVIEWERS
2123
} = require('./config')
2224

2325
const run = async () => {
@@ -182,6 +184,16 @@ const run = async () => {
182184
core.info(`Adding assignee(s) "${ ASSIGNEES.join(', ') }" to PR`)
183185
await git.addPrAssignees(ASSIGNEES)
184186
}
187+
188+
if (REVIEWERS !== undefined && REVIEWERS.length > 0 && !FORK) {
189+
core.info(`Adding reviewer(s) "${ REVIEWERS.join(', ') }" to PR`)
190+
await git.addPrReviewers(REVIEWERS)
191+
}
192+
193+
if (TEAM_REVIEWERS !== undefined && TEAM_REVIEWERS.length > 0 && !FORK) {
194+
core.info(`Adding team reviewer(s) "${ TEAM_REVIEWERS.join(', ') }" to PR`)
195+
await git.addPrTeamReviewers(TEAM_REVIEWERS)
196+
}
185197
}
186198

187199
core.info(' ')

0 commit comments

Comments
 (0)