From df0d79f7de9edeb66dfbd76f4843b0b4f3ae9da5 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Thu, 13 Jun 2019 06:05:58 +0200
Subject: [PATCH] fix(gitlab): skip mirrored repositories

---
 lib/platform/gitlab/index.ts          | 6 ++++++
 lib/workers/repository/error.js       | 5 +++++
 lib/workers/repository/result.js      | 1 +
 test/platform/gitlab/index.spec.ts    | 6 ++++++
 test/workers/repository/error.spec.js | 1 +
 5 files changed, 19 insertions(+)

diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts
index 6cff4f176a..34a4e331ad 100644
--- a/lib/platform/gitlab/index.ts
+++ b/lib/platform/gitlab/index.ts
@@ -95,6 +95,12 @@ export async function initRepo({
       );
       throw new Error('archived');
     }
+    if (res.body.mirror) {
+      logger.info(
+        'Repository is a mirror - throwing error to abort renovation'
+      );
+      throw new Error('mirror');
+    }
     if (res.body.default_branch === null) {
       throw new Error('empty');
     }
diff --git a/lib/workers/repository/error.js b/lib/workers/repository/error.js
index 050bee863a..7df44da667 100644
--- a/lib/workers/repository/error.js
+++ b/lib/workers/repository/error.js
@@ -27,6 +27,11 @@ async function handleError(config, err) {
     delete config.branchList; // eslint-disable-line no-param-reassign
     return err.message;
   }
+  if (err.message === 'mirror') {
+    logger.info('Repository is a mirror - skipping');
+    delete config.branchList; // eslint-disable-line no-param-reassign
+    return err.message;
+  }
   if (err.message === 'renamed') {
     logger.info('Repository has been renamed - skipping');
     delete config.branchList; // eslint-disable-line no-param-reassign
diff --git a/lib/workers/repository/result.js b/lib/workers/repository/result.js
index 69b90b3b84..76a08c1a76 100644
--- a/lib/workers/repository/result.js
+++ b/lib/workers/repository/result.js
@@ -10,6 +10,7 @@ function processResult(config, res) {
     'disabled',
     'forbidden',
     'fork',
+    'mirror',
     'no-package-files',
     'renamed',
     'uninitiated',
diff --git a/test/platform/gitlab/index.spec.ts b/test/platform/gitlab/index.spec.ts
index 928c6a6144..8a04db76fa 100644
--- a/test/platform/gitlab/index.spec.ts
+++ b/test/platform/gitlab/index.spec.ts
@@ -158,6 +158,12 @@ describe('platform/gitlab', () => {
         gitlab.initRepo({ repository: 'some/repo', localDir: '' })
       ).rejects.toThrow(Error('archived'));
     });
+    it('should throw an error if repository is a mirror', async () => {
+      api.get.mockReturnValue({ body: { mirror: true } } as any);
+      await expect(
+        gitlab.initRepo({ repository: 'some/repo', localDir: '' })
+      ).rejects.toThrow(Error('mirror'));
+    });
     it('should throw an error if repository is empty', async () => {
       api.get.mockReturnValue({ body: { default_branch: null } } as any);
       await expect(
diff --git a/test/workers/repository/error.spec.js b/test/workers/repository/error.spec.js
index b0eff479f0..9615dc505d 100644
--- a/test/workers/repository/error.spec.js
+++ b/test/workers/repository/error.spec.js
@@ -20,6 +20,7 @@ describe('workers/repository/error', () => {
       'config-validation',
       'registry-failure',
       'archived',
+      'mirror',
       'renamed',
       'blocked',
       'not-found',
-- 
GitLab