Skip to content

Commit

Permalink
fix(scripts/i18n) Add better error logging + dedupe logic of sync scr…
Browse files Browse the repository at this point in the history
…ipt (#22984)

* Make the sync script work better for integration

* process.exit when promises error

* process.exit when promises error
  • Loading branch information
tesseralis committed Apr 9, 2020
1 parent 405964e commit 90afde3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions scripts/i18n/sync.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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(
`
Expand All @@ -53,9 +68,6 @@ async function getRepository(owner, name) {
}
`,
{
headers: {
authorization: `token ${token}`,
},
owner,
name,
syncLabel: syncLabelName,
Expand All @@ -77,7 +89,6 @@ async function createLabel(input) {
`,
{
headers: {
authorization: `token ${token}`,
accept: `application/vnd.github.bane-preview+json`,
},
input,
Expand All @@ -100,7 +111,6 @@ async function createPullRequest(input) {
`,
{
headers: {
authorization: `token ${token}`,
accept: `application/vnd.github.shadow-cat-preview+json`,
},
input,
Expand All @@ -120,7 +130,6 @@ async function addLabelToPullRequest(pullRequest, label) {
`,
{
headers: {
authorization: `token ${token}`,
accept: `application/vnd.github.bane-preview+json`,
},
input: {
Expand Down

0 comments on commit 90afde3

Please sign in to comment.