From 90afde3836042d1fe42dc62a4c2a25facb651c78 Mon Sep 17 00:00:00 2001 From: Nat Alison <1278991+tesseralis@users.noreply.github.com> Date: Thu, 9 Apr 2020 14:51:25 -0700 Subject: [PATCH] fix(scripts/i18n) Add better error logging + dedupe logic of sync script (#22984) * Make the sync script work better for integration * process.exit when promises error * process.exit when promises error --- scripts/i18n/sync.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/i18n/sync.js b/scripts/i18n/sync.js index 399f140d15c29..9d5e673dc28a2 100644 --- a/scripts/i18n/sync.js +++ b/scripts/i18n/sync.js @@ -1,6 +1,6 @@ const log4js = require(`log4js`) const shell = require(`shelljs`) -const { graphql } = require(`@octokit/graphql`) +const { graphql: baseGraphql } = require(`@octokit/graphql`) let logger = log4js.getLogger(`sync`) require(`dotenv`).config() @@ -35,6 +35,21 @@ function cloneOrUpdateRepo(repoName, repoUrl) { } } +// Run the query and exit if there are errors +async function graphql(query, params) { + const graphqlWithAuth = baseGraphql.defaults({ + headers: { + authorization: `token ${token}`, + }, + }) + try { + return await graphqlWithAuth(query, params) + } catch (error) { + logger.error(error.message) + return process.exit(1) + } +} + async function getRepository(owner, name) { const { repository } = await graphql( ` @@ -53,9 +68,6 @@ async function getRepository(owner, name) { } `, { - headers: { - authorization: `token ${token}`, - }, owner, name, syncLabel: syncLabelName, @@ -77,7 +89,6 @@ async function createLabel(input) { `, { headers: { - authorization: `token ${token}`, accept: `application/vnd.github.bane-preview+json`, }, input, @@ -100,7 +111,6 @@ async function createPullRequest(input) { `, { headers: { - authorization: `token ${token}`, accept: `application/vnd.github.shadow-cat-preview+json`, }, input, @@ -120,7 +130,6 @@ async function addLabelToPullRequest(pullRequest, label) { `, { headers: { - authorization: `token ${token}`, accept: `application/vnd.github.bane-preview+json`, }, input: {