From 14fc4ebefa6b90fcd078355750f59834043fc9c5 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Wed, 18 Jan 2017 21:17:07 +0100
Subject: [PATCH] Add assignees to logic

---
 lib/api/github.js | 14 ++++++++++++++
 lib/worker.js     | 20 ++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/lib/api/github.js b/lib/api/github.js
index 01f52e506a..5b05466e35 100644
--- a/lib/api/github.js
+++ b/lib/api/github.js
@@ -12,6 +12,7 @@ module.exports = {
   deleteBranch,
   getBranchPr,
   // issue
+  addAssignees,
   addLabels,
   // PR
   checkForClosedPr,
@@ -100,6 +101,19 @@ function getBranchPr(branchName) {
 
 // Issue
 
+function addAssignees(issueNo, assignees) {
+  logger.debug(`Adding assignees ${assignees} to #${issueNo}`);
+  return ghGot.post(`repos/${config.repoName}/issues/${issueNo}/assignees`, {
+    body: {
+      assignees,
+    },
+  })
+  .catch((error) => {
+    logger.error(JSON.stringify(error));
+    throw error;
+  });
+}
+
 function addLabels(issueNo, labels) {
   logger.debug(`Adding labels ${labels} to #${issueNo}`);
   return ghGot.post(`repos/${config.repoName}/issues/${issueNo}/labels`, {
diff --git a/lib/worker.js b/lib/worker.js
index ecaba9a8af..a6f58bee8e 100644
--- a/lib/worker.js
+++ b/lib/worker.js
@@ -273,7 +273,9 @@ function updateDependency(upgrade) {
       if (!existingPr) {
         logger.debug(`Didn't find existing PR for branch ${branchName}`);
         // We need to create a new PR
-        return createPr().then(prNo => addLabels(prNo));
+        return createPr()
+        .then(prNo => addLabels(prNo))
+        .then(addAssignees);
       }
       // Check if existing PR needs updating
       logger.debug(`processExistingPr: ${existingPr.number}`);
@@ -285,13 +287,23 @@ function updateDependency(upgrade) {
       return updatePr(existingPr);
     }
 
+    // Add assignees to a PR
+    function addAssignees(prNo) {
+      if (config.assignees.length === 0) {
+        logger.debug(`No assignees to add to ${prNo}`);
+        return Promise.resolve();
+      }
+      return github.addAssignees(prNo, config.assignees);
+    }
+
     // Add labels to a PR
     function addLabels(prNo) {
       if (config.labels.length === 0) {
-        logger.silly(`No labels to add to ${prNo}`);
-        return Promise.resolve();
+        logger.debug(`No labels to add to ${prNo}`);
+        return Promise.resolve(prNo);
       }
-      return github.addLabels(prNo, config.labels);
+      return github.addLabels(prNo, config.labels)
+      .then(() => prNo);
     }
   }
 }
-- 
GitLab