Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripts/i18n) Add better error logging + dedupe logic of sync script #22984

Merged
merged 4 commits into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
@@ -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: {