11const log4js = require ( `log4js` )
22const shell = require ( `shelljs` )
3- const { graphql } = require ( `@octokit/graphql` )
3+ const { graphql : baseGraphql } = require ( `@octokit/graphql` )
44let logger = log4js . getLogger ( `sync` )
55
66require ( `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+
3853async 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