From c949778ab7df4b50867ec31e692b6387d58e8a4e Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 19 Feb 2018 20:01:10 +0100
Subject: [PATCH] fix: harmonize to pr.branchName

---
 lib/platform/github/index.js                          | 1 +
 lib/platform/gitlab/index.js                          | 1 +
 lib/workers/pr/index.js                               | 2 +-
 test/platform/github/__snapshots__/index.spec.js.snap | 5 +++++
 test/platform/gitlab/__snapshots__/index.spec.js.snap | 2 ++
 5 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js
index 9f2364dea1..086bd716c9 100644
--- a/lib/platform/github/index.js
+++ b/lib/platform/github/index.js
@@ -771,6 +771,7 @@ async function getPr(prNo) {
   // Harmonise PR values
   pr.displayNumber = `Pull Request #${pr.number}`;
   if (pr.state === 'open') {
+    pr.branchName = pr.head ? pr.head.ref : undefined;
     if (!pr.mergeable || pr.mergeable_state === 'dirty') {
       logger.debug(`PR is not mergeable`);
       pr.isUnmergeable = true;
diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js
index 1e22321ad6..412b54e093 100644
--- a/lib/platform/gitlab/index.js
+++ b/lib/platform/gitlab/index.js
@@ -445,6 +445,7 @@ async function getPr(iid) {
   const url = `projects/${config.repository}/merge_requests/${iid}`;
   const pr = (await get(url)).body;
   // Harmonize fields with GitHub
+  pr.branchName = pr.source_branch;
   pr.number = pr.iid;
   pr.displayNumber = `Merge Request #${pr.iid}`;
   pr.body = pr.description;
diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js
index c0b4d1153f..be18ca7cdf 100644
--- a/lib/workers/pr/index.js
+++ b/lib/workers/pr/index.js
@@ -349,7 +349,7 @@ async function checkAutoMerge(pr, config) {
     }
     // Check branch status
     const branchStatus = await platform.getBranchStatus(
-      pr.head.ref,
+      pr.branchName,
       config.requiredStatusChecks
     );
     logger.debug(`branchStatus=${branchStatus}`);
diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap
index a4ae36f632..201c509622 100644
--- a/test/platform/github/__snapshots__/index.spec.js.snap
+++ b/test/platform/github/__snapshots__/index.spec.js.snap
@@ -446,6 +446,7 @@ Object {
   "base": Object {
     "sha": "1234",
   },
+  "branchName": undefined,
   "canRebase": true,
   "commits": 1,
   "displayNumber": "Pull Request #1",
@@ -461,6 +462,7 @@ Object {
   "base": Object {
     "sha": "5678",
   },
+  "branchName": undefined,
   "canRebase": true,
   "commits": 1,
   "displayNumber": "Pull Request #1",
@@ -476,6 +478,7 @@ Object {
   "base": Object {
     "sha": "1234",
   },
+  "branchName": undefined,
   "canRebase": true,
   "commits": 2,
   "displayNumber": "Pull Request #1",
@@ -491,6 +494,7 @@ Object {
   "base": Object {
     "sha": "1234",
   },
+  "branchName": undefined,
   "canRebase": true,
   "commits": 2,
   "displayNumber": "Pull Request #1",
@@ -506,6 +510,7 @@ Object {
   "base": Object {
     "sha": "1234",
   },
+  "branchName": undefined,
   "commits": 2,
   "displayNumber": "Pull Request #1",
   "isUnmergeable": true,
diff --git a/test/platform/gitlab/__snapshots__/index.spec.js.snap b/test/platform/gitlab/__snapshots__/index.spec.js.snap
index a640f6e4ac..77e76b207f 100644
--- a/test/platform/gitlab/__snapshots__/index.spec.js.snap
+++ b/test/platform/gitlab/__snapshots__/index.spec.js.snap
@@ -166,6 +166,7 @@ Object {
     "sha": "1234",
   },
   "body": undefined,
+  "branchName": "some-branch",
   "commits": 1,
   "deletions": 1,
   "displayNumber": "Merge Request #91",
@@ -202,6 +203,7 @@ Array [
 exports[`platform/gitlab getPr(prNo) returns the PR 1`] = `
 Object {
   "body": "a merge request",
+  "branchName": "some-branch",
   "canRebase": true,
   "description": "a merge request",
   "displayNumber": "Merge Request #12345",
-- 
GitLab