From 2da4d8413bc577e05ddc4053838a8e0eab6284f9 Mon Sep 17 00:00:00 2001
From: Jamie Magee <JamieMagee@users.noreply.github.com>
Date: Tue, 24 Mar 2020 07:24:55 +0100
Subject: [PATCH] feat(github): github enterprise vulnerability alerts (#5762)

Add support for vulnerability alerts for GHE. Requires GHE 2.17.0 or higher. I think this is a fair requirement to assume, as GHE 2.16.x went EOL on January 22, 2020.

This also allows us to remove the check for GHE version when gettings issues.

Closes #4905
---
 lib/platform/github/index.ts | 46 ++----------------------------------
 1 file changed, 2 insertions(+), 44 deletions(-)

diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts
index 5de710041a..c408d5c1e1 100644
--- a/lib/platform/github/index.ts
+++ b/lib/platform/github/index.ts
@@ -1,6 +1,5 @@
 import is from '@sindresorhus/is';
 import delay from 'delay';
-import semver from 'semver';
 import URL from 'url';
 
 import { logger } from '../../logger';
@@ -1264,7 +1263,7 @@ export async function setBranchStatus({
 // Issue
 
 /* istanbul ignore next */
-async function getGraphqlIssues(): Promise<Issue[]> {
+async function getIssues(): Promise<Issue[]> {
   // prettier-ignore
   const query = `
     query {
@@ -1294,44 +1293,10 @@ async function getGraphqlIssues(): Promise<Issue[]> {
   }));
 }
 
-// istanbul ignore next
-async function getRestIssues(): Promise<Issue[]> {
-  logger.debug('Retrieving issueList');
-  const res = await api.get<
-    {
-      pull_request: boolean;
-      number: number;
-      state: string;
-      title: string;
-    }[]
-  >(
-    `repos/${config.repository}/issues?creator=${config.renovateUsername}&state=all&per_page=100&sort=created&direction=asc`,
-    { paginate: 'all', useCache: false }
-  );
-  // istanbul ignore if
-  if (!is.array(res.body)) {
-    logger.warn({ responseBody: res.body }, 'Could not retrieve issue list');
-    return [];
-  }
-  return res.body
-    .filter(issue => !issue.pull_request)
-    .map(i => ({
-      number: i.number,
-      state: i.state,
-      title: i.title,
-    }));
-}
-
 export async function getIssueList(): Promise<Issue[]> {
   if (!config.issueList) {
     logger.debug('Retrieving issueList');
-    const filterBySupportMinimumGheVersion = '2.17.0';
-    // istanbul ignore next
-    config.issueList =
-      config.enterpriseVersion &&
-      semver.lt(config.enterpriseVersion, filterBySupportMinimumGheVersion)
-        ? await getRestIssues()
-        : await getGraphqlIssues();
+    config.issueList = await getIssues();
   }
   return config.issueList;
 }
@@ -1879,13 +1844,6 @@ export function getPrBody(input: string): string {
 }
 
 export async function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
-  // istanbul ignore if
-  if (config.isGhe) {
-    logger.debug(
-      'Skipping unsupported graphql vulnerabilityAlerts query on GHE'
-    );
-    return [];
-  }
   const headers = {
     accept: 'application/vnd.github.vixen-preview+json',
   };
-- 
GitLab