From 8b7dbe5d338abdd976346883b646034070a88f62 Mon Sep 17 00:00:00 2001 From: Nils Plaschke Date: Sun, 25 Oct 2020 00:02:41 +0200 Subject: [PATCH] refactor(github): remove ghe compatibility checks (#7540) Co-authored-by: Rhys Arkins Co-authored-by: Jamie Magee --- lib/platform/github/index.ts | 83 +++++++++++++++++------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index bc3312505b..6a3a09918e 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -484,13 +484,7 @@ async function getClosedPrs(): Promise { } async function getOpenPrs(): Promise { - // istanbul ignore if - if (config.isGhe) { - logger.debug( - 'Skipping unsupported graphql PullRequests.mergeStateStatus query on GHE' - ); - return {}; - } + // The graphql query is supported in the current oldest GHE version 2.19 if (!config.openPrList) { config.openPrList = {}; let query; @@ -795,44 +789,43 @@ export async function getBranchStatus( 'branch status check result' ); let checkRuns: { name: string; status: string; conclusion: string }[] = []; - if (!config.isGhe) { - try { - const checkRunsUrl = `repos/${config.repository}/commits/${escapeHash( - branchName - )}/check-runs`; - const opts = { - headers: { - accept: 'application/vnd.github.antiope-preview+json', - }, - }; - const checkRunsRaw = ( - await githubApi.getJson<{ - check_runs: { name: string; status: string; conclusion: string }[]; - }>(checkRunsUrl, opts) - ).body; - if (checkRunsRaw.check_runs?.length) { - checkRuns = checkRunsRaw.check_runs.map((run) => ({ - name: run.name, - status: run.status, - conclusion: run.conclusion, - })); - logger.debug({ checkRuns }, 'check runs result'); - } else { - // istanbul ignore next - logger.debug({ result: checkRunsRaw }, 'No check runs found'); - } - } catch (err) /* istanbul ignore next */ { - if (err instanceof ExternalHostError) { - throw err; - } - if ( - err.statusCode === 403 || - err.message === PLATFORM_INTEGRATION_UNAUTHORIZED - ) { - logger.debug('No permission to view check runs'); - } else { - logger.warn({ err }, 'Error retrieving check runs'); - } + // API is supported in oldest available GHE version 2.19 + try { + const checkRunsUrl = `repos/${config.repository}/commits/${escapeHash( + branchName + )}/check-runs`; + const opts = { + headers: { + accept: 'application/vnd.github.antiope-preview+json', + }, + }; + const checkRunsRaw = ( + await githubApi.getJson<{ + check_runs: { name: string; status: string; conclusion: string }[]; + }>(checkRunsUrl, opts) + ).body; + if (checkRunsRaw.check_runs?.length) { + checkRuns = checkRunsRaw.check_runs.map((run) => ({ + name: run.name, + status: run.status, + conclusion: run.conclusion, + })); + logger.debug({ checkRuns }, 'check runs result'); + } else { + // istanbul ignore next + logger.debug({ result: checkRunsRaw }, 'No check runs found'); + } + } catch (err) /* istanbul ignore next */ { + if (err instanceof ExternalHostError) { + throw err; + } + if ( + err.statusCode === 403 || + err.message === PLATFORM_INTEGRATION_UNAUTHORIZED + ) { + logger.debug('No permission to view check runs'); + } else { + logger.warn({ err }, 'Error retrieving check runs'); } } if (checkRuns.length === 0) {