Skip to content

Commit 90afde3

Browse files
authored
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
1 parent 405964e commit 90afde3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

scripts/i18n/sync.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const log4js = require(`log4js`)
22
const shell = require(`shelljs`)
3-
const { graphql } = require(`@octokit/graphql`)
3+
const { graphql: baseGraphql } = require(`@octokit/graphql`)
44
let logger = log4js.getLogger(`sync`)
55

66
require(`dotenv`).config()
@@ -35,6 +35,21 @@ function cloneOrUpdateRepo(repoName, repoUrl) {
3535
}
3636
}
3737

38+
// Run the query and exit if there are errors
39+
async function graphql(query, params) {
40+
const graphqlWithAuth = baseGraphql.defaults({
41+
headers: {
42+
authorization: `token ${token}`,
43+
},
44+
})
45+
try {
46+
return await graphqlWithAuth(query, params)
47+
} catch (error) {
48+
logger.error(error.message)
49+
return process.exit(1)
50+
}
51+
}
52+
3853
async function getRepository(owner, name) {
3954
const { repository } = await graphql(
4055
`
@@ -53,9 +68,6 @@ async function getRepository(owner, name) {
5368
}
5469
`,
5570
{
56-
headers: {
57-
authorization: `token ${token}`,
58-
},
5971
owner,
6072
name,
6173
syncLabel: syncLabelName,
@@ -77,7 +89,6 @@ async function createLabel(input) {
7789
`,
7890
{
7991
headers: {
80-
authorization: `token ${token}`,
8192
accept: `application/vnd.github.bane-preview+json`,
8293
},
8394
input,
@@ -100,7 +111,6 @@ async function createPullRequest(input) {
100111
`,
101112
{
102113
headers: {
103-
authorization: `token ${token}`,
104114
accept: `application/vnd.github.shadow-cat-preview+json`,
105115
},
106116
input,
@@ -120,7 +130,6 @@ async function addLabelToPullRequest(pullRequest, label) {
120130
`,
121131
{
122132
headers: {
123-
authorization: `token ${token}`,
124133
accept: `application/vnd.github.bane-preview+json`,
125134
},
126135
input: {

0 commit comments

Comments
 (0)