@@ -12,10 +12,10 @@ async function sleep (ms) {
1212// Often, there is a delay between the webhook firing and GaphQL updating
1313async function retryQuery ( context , query , args ) {
1414 try {
15- return await context . github . query ( query , args )
15+ return await context . github . graphql ( query , args )
1616 } catch ( err ) {
1717 await sleep ( 1000 )
18- return context . github . query ( query , args )
18+ return context . github . graphql ( query , args )
1919 }
2020}
2121
@@ -49,14 +49,14 @@ const PROJECT_FRAGMENT = `
4949`
5050
5151module . exports = ( robot ) => {
52- const logger = robot . log . child ( { name : 'project-bot' } )
52+ const logger = robot . log . child ( { name : 'project-bot' } )
5353 // Increase the maxListenerCount by the number of automationCommands
5454 // because we register a bunch of listeners
5555 robot . events . setMaxListeners ( robot . events . getMaxListeners ( ) + automationCommands . length )
5656 logger . info ( `Starting up` )
5757
5858 // Register all of the automation commands
59- automationCommands . forEach ( ( { createsACard, webhookName, ruleName, ruleMatcher} ) => {
59+ automationCommands . forEach ( ( { createsACard, webhookName, ruleName, ruleMatcher } ) => {
6060 logger . trace ( `Attaching listener for ${ webhookName } ` )
6161 robot . on ( webhookName , async function ( context ) {
6262 const issueUrl = context . payload . issue ? context . payload . issue . html_url : context . payload . pull_request . html_url . replace ( '/pull/' , '/issues/' )
@@ -92,8 +92,8 @@ module.exports = (robot) => {
9292 }
9393 }
9494 }
95- ` , { issueUrl : issueUrl } )
96- const { resource} = graphResult
95+ ` , { issueUrl : issueUrl } )
96+ const { resource } = graphResult
9797
9898 let allProjects = [ ]
9999 if ( resource . repository . owner . projects ) {
@@ -105,25 +105,25 @@ module.exports = (robot) => {
105105 }
106106
107107 // Loop through all of the Automation Cards and see if any match
108- const automationRules = extractAutomationRules ( allProjects ) . filter ( ( { ruleName : rn } ) => rn === ruleName )
108+ const automationRules = extractAutomationRules ( allProjects ) . filter ( ( { ruleName : rn } ) => rn === ruleName )
109109
110- for ( const { column, ruleArgs} of automationRules ) {
110+ for ( const { column, ruleArgs } of automationRules ) {
111111 if ( await ruleMatcher ( logger , context , ruleArgs ) ) {
112112 logger . info ( `Creating Card for "${ issueUrl } " to column ${ column . id } because of "${ ruleName } " and value: "${ ruleArgs } "` )
113- await context . github . query ( `
113+ await context . github . graphql ( `
114114 mutation createCard($contentId: ID!, $columnId: ID!) {
115115 addProjectCard(input: {contentId: $contentId, projectColumnId: $columnId}) {
116116 clientMutationId
117117 }
118118 }
119- ` , { contentId : resource . id , columnId : column . id } )
119+ ` , { contentId : resource . id , columnId : column . id } )
120120 }
121121 }
122122 } else {
123123 // Check if we need to move the Issue (or Pull request)
124124 const graphResult = await retryQuery ( context , `
125- query getCardAndColumnAutomationCards($url : URI!) {
126- resource(url: $url ) {
125+ query getCardAndColumnAutomationCards($issueUrl : URI!) {
126+ resource(url: $issueUrl ) {
127127 ... on Issue {
128128 projectCards(first: 10) {
129129 nodes {
@@ -141,28 +141,28 @@ module.exports = (robot) => {
141141 }
142142 }
143143 }
144- ` , { url : issueUrl } )
144+ ` , { issueUrl : issueUrl } )
145145 logger . debug ( graphResult , 'Retrieved results' )
146- const { resource} = graphResult
146+ const { resource } = graphResult
147147 // sometimes there are no projectCards
148148 if ( ! resource . projectCards ) {
149149 logger . error ( issueUrl , resource , 'Not even an array for project cards. Odd' )
150150 }
151151 const cardsForIssue = resource . projectCards ? resource . projectCards . nodes : [ ]
152152
153153 for ( const issueCard of cardsForIssue ) {
154- const automationRules = extractAutomationRules ( [ issueCard . project ] ) . filter ( ( { ruleName : rn } ) => rn === ruleName )
154+ const automationRules = extractAutomationRules ( [ issueCard . project ] ) . filter ( ( { ruleName : rn } ) => rn === ruleName )
155155
156- for ( const { column, ruleArgs} of automationRules ) {
156+ for ( const { column, ruleArgs } of automationRules ) {
157157 if ( await ruleMatcher ( logger , context , ruleArgs ) ) {
158158 logger . info ( `Moving Card ${ issueCard . id } for "${ issueUrl } " to column ${ column . id } because of "${ ruleName } " and value: "${ ruleArgs } "` )
159- await context . github . query ( `
159+ await context . github . graphql ( `
160160 mutation moveCard($cardId: ID!, $columnId: ID!) {
161161 moveProjectCard(input: {cardId: $cardId, columnId: $columnId}) {
162162 clientMutationId
163163 }
164164 }
165- ` , { cardId : issueCard . id , columnId : column . id } )
165+ ` , { cardId : issueCard . id , columnId : column . id } )
166166 }
167167 }
168168 }
0 commit comments