From 612ee76e0cdc4f37235a8f872b490a1543a05406 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 20 Feb 2018 21:35:04 +0100
Subject: [PATCH] fix: add try/catch to github datasource functions

---
 lib/datasource/github.js | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/lib/datasource/github.js b/lib/datasource/github.js
index a8f238f619..f42aab2a33 100644
--- a/lib/datasource/github.js
+++ b/lib/datasource/github.js
@@ -11,21 +11,31 @@ function semverSort(a, b) {
 }
 
 async function getRepoTags(repo) {
-  const url = `repos/${repo}/git/refs?per_page=100`;
-  const res = (await ghGot(url, { paginate: true })).body;
-  const tagPrefix = 'refs/tags/';
-  return res
-    .filter(o => o.ref.startsWith(tagPrefix))
-    .map(o => o.ref.replace(tagPrefix, ''))
-    .filter(o => semver.valid(o))
-    .sort(semverSort);
+  try {
+    const url = `repos/${repo}/git/refs?per_page=100`;
+    const res = (await ghGot(url, { paginate: true })).body;
+    const tagPrefix = 'refs/tags/';
+    return res
+      .filter(o => o.ref.startsWith(tagPrefix))
+      .map(o => o.ref.replace(tagPrefix, ''))
+      .filter(o => semver.valid(o))
+      .sort(semverSort);
+  } catch (err) /* istanbul ignore next */ {
+    logger.warn({ repo }, 'Could not fetch repo tags');
+    return [];
+  }
 }
 
 async function getRepoReleases(repo) {
-  const url = `repos/${repo}/releases?per_page=100`;
-  const res = (await ghGot(url, { paginate: true })).body;
-  return res
-    .map(o => o.tag_name)
-    .filter(semver.valid)
-    .sort(semverSort);
+  try {
+    const url = `repos/${repo}/releases?per_page=100`;
+    const res = (await ghGot(url, { paginate: true })).body;
+    return res
+      .map(o => o.tag_name)
+      .filter(semver.valid)
+      .sort(semverSort);
+  } catch (err) /* istanbul ignore next */ {
+    logger.warn({ repo }, 'Could not fetch repo releases');
+    return [];
+  }
 }
-- 
GitLab