@@ -29,6 +29,14 @@ template:
2929 * * `{{commit}}` - Sha that was the head of the most recent PUSH
3030 */
3131const NEXT_MESSAGE = 'next.md' ;
32+ /**
33+ * File in `responses/` that is used as the content for comments that are posted
34+ * when a user fails a step.
35+ *
36+ * Makes use of the placeholders:
37+ * * `{{commit}}` - Sha that was the head of the most recent PUSH
38+ */
39+ const FAIL_MESSAGE = 'fail.md' ;
3240/**
3341 * File in `responses/` that is used as the content for the comment that is
3442 * posted when a user finishes the last step.
@@ -58,6 +66,7 @@ const END_MESSAGE = 'end.md';
5866 * instructionsFile: string;
5967 * title: string;
6068 * description: string;
69+ * activitiesFiles: string[];
6170 * }>
6271 */
6372const STEPS = [
@@ -66,14 +75,16 @@ const STEPS = [
6675 expectedResults : 3 ,
6776 instructionsFile : 'step-1.md' ,
6877 title : 'Your first query' ,
69- description : 'Write your first query'
78+ description : 'Write your first query' ,
79+ activitiesFiles : [ ]
7080 } ,
7181 {
7282 queryFile : 'step-2.ql' ,
7383 expectedResults : 5 ,
7484 instructionsFile : 'step-2.md' ,
7585 title : 'Your second query' ,
76- description : 'Write your second query'
86+ description : 'Write your second query' ,
87+ activitiesFiles : [ ]
7788 }
7889] ;
7990
@@ -108,13 +119,23 @@ console.log(`
108119before:
109120 - type: createIssue
110121 title: '${ issueTitle ( STEPS [ 0 ] , 0 ) } '
111- body: ${ STEPS [ 0 ] . instructionsFile }
112- steps:
113- ` . trim ( ) ) ;
122+ body: ${ STEPS [ 0 ] . instructionsFile } ` ) ;
123+ if ( STEPS [ 0 ] . activitiesFiles . length > 0 ) {
124+ console . log ( ` comments:` ) ;
125+ STEPS [ 0 ] . activitiesFiles . map ( activityFile => {
126+ console . log ( ` - ${ activityFile } ` ) ;
127+ } )
128+ }
129+ console . log ( ` action_id: step_1
130+ - type: assignRegistrant
131+ issue: '%actions.step_1.data.number%'
132+
133+ steps:` ) ;
114134
115135STEPS . map ( ( step , i ) => {
116136 // The markdown string to look for in the comment from github-actions[bot]
117137 const expectedString = `Results for \`${ step . queryFile } \`: **correct** (${ step . expectedResults } result${ step . expectedResults === 1 ? '' : 's' } )` ;
138+ const expectedIssue = `Results for \`${ step . queryFile } \`:` ;
118139 console . log ( `
119140 - title: "${ escapeDoubleQuoteYamlString ( step . title ) } "
120141 description: "${ escapeDoubleQuoteYamlString ( step . description ) } "
@@ -126,12 +147,25 @@ STEPS.map((step, i) => {
126147 left: '%payload.sender.login%'
127148 operator: ===
128149 right: github-actions[bot]
150+ # Ensure comment is relevant for this issue
151+ - type: gate
152+ left: '%payload.comment.body%'
153+ operator: search
154+ # regex-escape then yaml-escape the expected markdown string
155+ right: "/${ escapeDoubleQuoteYamlString ( escapeRegExp ( expectedIssue ) ) } /"
129156 # Ensure comment has expected completed string
130157 - type: gate
131158 left: '%payload.comment.body%'
132159 operator: search
133160 # regex-escape then yaml-escape the expected markdown string
134161 right: "/${ escapeDoubleQuoteYamlString ( escapeRegExp ( expectedString ) ) } /"
162+ else:
163+ - type: respond
164+ issue: "${ escapeDoubleQuoteYamlString ( issueTitle ( step , i ) ) } "
165+ with: ${ FAIL_MESSAGE }
166+ data:
167+ commit: '%payload.comment.commit_id%'
168+ commentUrl: '%payload.comment.html_url%'
135169
136170 # Answer is correct!!` ) ;
137171
@@ -182,8 +216,17 @@ STEPS.map((step, i) => {
182216 # Create Issue for next task
183217 - type: createIssue
184218 title: "${ escapeDoubleQuoteYamlString ( issueTitle ( next , i + 1 ) ) } "
185- body: ${ next . instructionsFile }
186- action_id: next_issue
219+ body: ${ next . instructionsFile } ` ) ;
220+ if ( next . activitiesFiles . length > 0 ) {
221+ console . log ( ` comments:` ) ;
222+ }
223+ next . activitiesFiles . map ( file => {
224+ console . log ( ` - ${ file } ` )
225+ } )
226+ console . log ( ` action_id: next_issue
227+
228+ - type: assignRegistrant
229+ issue: '%actions.next_issue.data.number%'
187230
188231 # Make comment on current issue with link to commit that introduces correct query
189232 - type: respond
0 commit comments