Skip to content

Commit

Permalink
feat: team_reviewers input (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
adzienis authored Dec 23, 2021
1 parent 3a2f600 commit 466b1b8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ jobs:
branch: test-add-reviewers-${{ github.run_number }}
commit-message: "Just testing [skip ci]"
reviewers: gr2m
team_reviewers: test-reviewers
- uses: octokit/[email protected]
id: get-pull-request
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ with:
labels: label1, label2
assignees: user1, user2
reviewers: user1, user2
team_reviewers: team1, team2
auto-merge: squash
update-pull-request-title-and-body: false
```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ inputs:
reviewers:
description: Comma separated list of reviewers to apply to the pull request
required: false
team_reviewers:
description: Comma separated list of team reviewers to apply to the pull request
required: false
auto-merge:
description: "Enable auto merge for pull request. Requires auto merging to be enabled in repository settings"
required: false
Expand Down
50 changes: 40 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function main() {
labels: core.getInput("labels"),
assignees: core.getInput("assignees"),
reviewers: core.getInput("reviewers"),
team_reviewers: core.getInput("team_reviewers"),
autoMerge: core.getInput("auto-merge"),
updatePRTitleAndBody: core.getInput("update-pull-request-title-and-body"),
};
Expand Down Expand Up @@ -223,19 +224,48 @@ async function main() {
core.debug(inspect(data));
}

if (inputs.reviewers) {
core.debug(`Adding reviewers: ${inputs.reviewers}`);
const reviewers = inputs.reviewers.trim().split(/\s*,\s*/);
if (inputs.reviewers || inputs.team_reviewers) {
let params = {
owner,
repo,
pull_number: number
}
let reviewers = null;
let team_reviewers = null;

if(inputs.reviewers) {
core.debug(`Adding reviewers: ${inputs.reviewers}`)
reviewers = (inputs.reviewers || "").trim().split(/\s*,\s*/);

params = {
...params,
reviewers
}
};

if(inputs.team_reviewers) {
core.debug(`Adding team reviewers: ${inputs.team_reviewers}`)
team_reviewers = (inputs.team_reviewers || "").trim().split(/\s*,\s*/);

params = {
...params,
team_reviewers
}
} ;

const { data } = await octokit.request(
`POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers`,
{
owner,
repo,
pull_number: number,
reviewers,
}
params
);
core.info(`Reviewers added: ${reviewers.join(", ")}`);

if(reviewers) {
core.info(`Reviewers added: ${reviewers.join(", ")}`);
}

if(team_reviewers) {
core.info(`Team reviewers added: ${team_reviewers.join(", ")}`);
}

core.debug(inspect(data));
}

Expand Down

0 comments on commit 466b1b8

Please sign in to comment.