@@ -33,7 +33,7 @@ module.exports = async (
3333 quarterlyMilestoneName = 'quarterly milestone' ,
3434 basePath = '.'
3535) => {
36- coreGlob = core
36+ coreGlob = core ;
3737 if ( typeof projectNumber !== 'number' )
3838 bail ( "missing params" ) ;
3939 const fs = require ( 'fs' ) ;
@@ -44,17 +44,17 @@ module.exports = async (
4444 owner : organization ? organization : context . repo . owner ,
4545 number : projectNumber
4646 } ;
47- let projectData
47+ let projectData ;
4848 try {
4949 projectData = await github . graphql ( projectDataQuery , projectDataParams ) ;
5050 } catch ( error ) {
5151 bail ( error . message ) ;
5252 } ;
5353 if ( ! projectData . organization . projectV2 . fields . nodes )
54- bail ( "couldn't retrieve project fields" )
54+ bail ( "couldn't retrieve project fields" ) ;
5555 const projectFieldOptions = projectData . organization . projectV2 . fields . nodes ;
5656 if ( ! projectData . organization . projectV2 . id )
57- bail ( "couldn't retrieve project graphql id" )
57+ bail ( "couldn't retrieve project graphql id" ) ;
5858 const projectId = projectData . organization . projectV2 . id ;
5959
6060 // get todo status
@@ -98,12 +98,12 @@ module.exports = async (
9898 isPr = true ;
9999
100100 // get PR / Issue id
101- const prIssueId = await getPrIssueId ( github , context )
101+ const prIssueId = await getPrIssueId ( github , context ) ;
102102 if ( ! prIssueId )
103103 bail ( "couldn't get ID of PR/Issue" ) ;
104104
105105 // move Issue to project
106- let projectItemId
106+ let projectItemId ;
107107 if ( ! isPr ) {
108108 const assignItemQuery = fs . readFileSync ( `${ basePath } /graphql/projectAssignPrIssue.gql` , 'utf8' ) ;
109109 const assignItemParams = {
@@ -117,9 +117,10 @@ module.exports = async (
117117 } ;
118118 } ;
119119
120- let effortFieldId
121- let effortValueId
122- let isDraftPr
120+ let effortFieldId ;
121+ let effortValueId ;
122+ let effortHumanReadable ;
123+ let isDraftPr ;
123124 if ( isPr ) {
124125 // assign author if a PR
125126 const assigneeData = await github . rest . users . getByUsername ( {
@@ -146,19 +147,19 @@ module.exports = async (
146147 name : context . repo . repo ,
147148 number : context . payload . pull_request . number
148149 } ;
149- let prCommitData
150+ let prCommitData ;
150151 try {
151- let prAllData = await github . graphql ( prCommitDataQuery , prCommitDataParams )
152- prCommitData = prAllData . repository . pullRequest . commits . nodes
153- isDraftPr = prAllData . repository . pullRequest . isDraft
152+ let prAllData = await github . graphql ( prCommitDataQuery , prCommitDataParams ) ;
153+ prCommitData = prAllData . repository . pullRequest . commits . nodes ;
154+ isDraftPr = prAllData . repository . pullRequest . isDraft ;
154155 } catch ( error ) {
155156 bail ( error . message ) ;
156157 } ;
157158
158159 // leave drafts alone
159160 if ( isDraftPr ) {
160161 coreGlob . info ( "detected PR draft, skipping project assignment" ) ;
161- return
162+ return ;
162163 }
163164
164165 // move PR to project
@@ -176,11 +177,11 @@ module.exports = async (
176177 // estimate effort if a PR
177178 if ( includeEffort ) {
178179 // get weekdays since PR's first commit
179- let prCreatedAt = new Date ( )
180+ let prCreatedAt = new Date ( ) ;
180181 prCommitData . forEach ( commit => {
181- const commitDate = new Date ( commit . commit . authoredDate )
182+ const commitDate = new Date ( commit . commit . authoredDate ) ;
182183 if ( commitDate < prCreatedAt ) {
183- prCreatedAt = commitDate
184+ prCreatedAt = commitDate ;
184185 }
185186 } ) ;
186187 const workingDaysSinceCreated = countWorkingDaysSince ( new Date ( prCreatedAt ) ) ;
@@ -199,8 +200,10 @@ module.exports = async (
199200 if ( field . name === effortName ) {
200201 effortFieldId = field . id ;
201202 field . options . forEach ( effort => {
202- if ( effort . name . toLowerCase ( ) . includes ( milestonePattern . toLowerCase ( ) ) )
203+ if ( effort . name . toLowerCase ( ) . includes ( milestonePattern . toLowerCase ( ) ) ) {
203204 effortValueId = effort . id ;
205+ effortHumanReadable = effort . name ;
206+ } ;
204207 } ) ;
205208 } ;
206209 } ) ;
@@ -227,6 +230,13 @@ module.exports = async (
227230 } catch ( error ) {
228231 bail ( error . message ) ;
229232 } ;
233+ await github . rest . issues . createComment ( {
234+ owner : context . repo . owner ,
235+ repo : context . repo . repo ,
236+ issue_number : context . payload . pull_request . number ,
237+ body : `Effort has been estimated to ${ effortHumanReadable } .
238+ This is based on date of first commit and mapping: ${ effortMapping } `
239+ } ) ;
230240 coreGlob . info ( "set project fields including effort" ) ;
231241 } else {
232242 const assignProjectFieldsQuery = fs . readFileSync ( `${ basePath } /graphql/projectNoEffortItemAssignFields.gql` , 'utf8' ) ;
@@ -269,7 +279,7 @@ module.exports = async (
269279 */
270280function bail ( msg ) {
271281 coreGlob . setFailed ( msg ) ;
272- throw new Error ( msg )
282+ throw new Error ( msg ) ;
273283}
274284
275285/**
@@ -294,7 +304,7 @@ function countWorkingDaysSince(startDate) {
294304 * @returns {string } node_id of iteration entry matching current date
295305 */
296306function getCurrentIteration ( iterations ) {
297- let monthlyMilestoneValueId
307+ let monthlyMilestoneValueId ;
298308 iterations . forEach ( iteration => {
299309 const now = new Date ( ) ;
300310 const startDate = new Date ( iteration . startDate ) ;
@@ -303,7 +313,7 @@ function getCurrentIteration(iterations) {
303313 if ( startDate < now && now < endDate )
304314 monthlyMilestoneValueId = iteration . id ;
305315 } ) ;
306- return monthlyMilestoneValueId
316+ return monthlyMilestoneValueId ;
307317}
308318
309319/**
0 commit comments