From 7c6a891b73dc6cae8e22e082c4b8991760de1cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20ELET?= <sebastien@elet.fr> Date: Tue, 31 Jan 2017 14:54:16 +0100 Subject: [PATCH] Add option for Requested Reviewers (#79) This feature allows for the addition of requested reviewers for Pull Requests. --- docs/configuration.md | 2 ++ lib/api/github.js | 13 +++++++++++++ lib/config/definitions.js | 5 +++++ lib/worker.js | 10 ++++++++++ readme.md | 1 + 5 files changed, 31 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index e723f7347f..41d19684bf 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -69,6 +69,7 @@ $ node renovate --help --recreate-closed [boolean] Recreate PRs even if same ones were closed previously --labels <list> Labels to add to Pull Request --assignees <list> Assignees for Pull Request + --reviewers <list> Requested reviewers for Pull Requests --log-level <string> Logging level Examples: @@ -118,4 +119,5 @@ Obviously, you can't set repository or package file location with this method. | `prBody` | Pull Request body template | string | `"This Pull Request updates dependency {{depName}} from version {{currentVersion}} to {{newVersion}}\n\n{{changelog}}"` | | | | `labels` | Labels to add to Pull Request | list | `[]` | `RENOVATE_LABELS` | `--labels` | | `assignees` | Assignees for Pull Request | list | `[]` | `RENOVATE_ASSIGNEES` | `--assignees` | +| `reviewers` | Requested reviewers for Pull Requests | list | `[]` | `RENOVATE_REVIEWERS` | `--reviewers` | | `logLevel` | Logging level | string | `"info"` | `LOG_LEVEL` | `--log-level` | diff --git a/lib/api/github.js b/lib/api/github.js index 3a47d88783..9eebddef36 100644 --- a/lib/api/github.js +++ b/lib/api/github.js @@ -16,6 +16,7 @@ module.exports = { updateBranch, // issue addAssignees, + addReviewers, addLabels, // PR findPr, @@ -137,6 +138,18 @@ async function addAssignees(issueNo, assignees) { }); } +async function addReviewers(issueNo, reviewers) { + logger.debug(`Adding reviewers ${reviewers} to #${issueNo}`); + await ghGot.post(`repos/${config.repoName}/pulls/${issueNo}/requested_reviewers`, { + headers: { + accept: 'application/vnd.github.black-cat-preview+json', + }, + body: { + reviewers, + }, + }); +} + async function addLabels(issueNo, labels) { logger.debug(`Adding labels ${labels} to #${issueNo}`); await ghGot.post(`repos/${config.repoName}/issues/${issueNo}/labels`, { diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 4e319175a7..c57c98c441 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -110,6 +110,11 @@ const options = [ description: 'Assignees for Pull Request', type: 'list', }, + { + name: 'reviewers', + description: 'Requested reviewers for Pull Requests', + type: 'list', + }, // Debug options { name: 'logLevel', diff --git a/lib/worker.js b/lib/worker.js index da29ec9bde..f4ca3173fa 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -253,6 +253,7 @@ async function updateDependency(upgrade) { const prNo = await createPr(); await addLabels(prNo); await addAssignees(prNo); + await addReviewers(prNo); return; } // Check if existing PR needs updating @@ -274,6 +275,15 @@ async function updateDependency(upgrade) { await github.addAssignees(prNo, config.assignees); } + // Add reviewers to a PR + async function addReviewers(prNo) { + if (config.reviewers.length === 0) { + logger.debug(`No reviewers to add to ${prNo}`); + return; + } + await github.addReviewers(prNo, config.reviewers); + } + // Add labels to a PR async function addLabels(prNo) { if (config.labels.length === 0) { diff --git a/readme.md b/readme.md index 8a1f20d524..f0d86fcca1 100644 --- a/readme.md +++ b/readme.md @@ -47,6 +47,7 @@ $ node renovate --help --recreate-closed [boolean] Recreate PRs even if same ones were closed previously --labels <list> Labels to add to Pull Request --assignees <list> Assignees for Pull Request + --reviewers <list> Requested reviewers for Pull Requests --log-level <string> Logging level Examples: -- GitLab