Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 37067db

Browse files
committed
Adapt course template to add intro issues
1 parent 6556bbf commit 37067db

File tree

1 file changed

+76
-21
lines changed

1 file changed

+76
-21
lines changed

templates/learninglab/course/generate-config.js

+76-21
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ template:
2020
name: <MY-COURSE-REPO>
2121
`;
2222

23+
/**
24+
* File in `responses/` that is used as the content for comments that are posted
25+
* when a user finishes the setup phase.
26+
*
27+
*/
28+
const INTRO_OK_MESSAGE = 'setup-ok.md';
2329
/**
2430
* File in `responses/` that is used as the content for comments that are posted
2531
* when a user finishes a step.
@@ -46,6 +52,24 @@ const FAIL_MESSAGE = 'fail.md';
4652
*/
4753
const END_MESSAGE = 'end.md';
4854

55+
/**
56+
* Setup steps of this course.
57+
* Each of this step consists in a `.md` file that introduce the
58+
* course, describe the setup ... before the actual query writing begins
59+
*/
60+
const INTRO_ISSUES = [
61+
{
62+
title: 'Welcome!',
63+
instructionsFile: 'step1-welcome.md',
64+
activitiesFiles: []
65+
},
66+
{
67+
title: 'Set up your IDE',
68+
instructionsFile: 'step2-setup.md',
69+
activitiesFiles: ['2-1.md']
70+
}
71+
]
72+
4973
/**
5074
* Each of the steps of this course, each step must have:
5175
*
@@ -100,7 +124,7 @@ console.log(META.trim());
100124
* @param step {{title: string;}}
101125
* @param i {number}
102126
*/
103-
const issueTitle = (step, i) => `Step ${i + 1} - ${step.title}`;
127+
const issueTitle = (step, i) => `Step ${i + 1 + INTRO_ISSUES.length} - ${step.title}`;
104128

105129
/**
106130
* @param str {string}
@@ -117,20 +141,53 @@ const escapeDoubleQuoteYamlString = (str) =>
117141

118142
console.log(`
119143
before:
144+
# Create Issues for introduction`);
145+
146+
INTRO_ISSUES.map((issue, i) => {
147+
console.log(`
120148
- type: createIssue
121-
title: '${issueTitle(STEPS[0], 0)}'
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
149+
title: ${issue.title}
150+
body: ${issue.instructionsFile}
151+
action_id: intro_${i}`);
152+
if (issue.activitiesFiles.length > 0) {
153+
console.log(` comments:`);
154+
issue.activitiesFiles.map(activityFile => {
155+
console.log(` - ${activityFile}`);
156+
})
157+
}
158+
console.log(`
159+
- type: assignRegistrant
160+
issue: '%actions.intro_${i}.data.number%'`)
161+
})
162+
console.log(`
163+
- type: createIssue
164+
title: "${escapeDoubleQuoteYamlString(issueTitle(STEPS[0], 0))}"
165+
body: ${STEPS[0].instructionsFile}
166+
action_id: step_0`);
167+
if (STEPS[0].activitiesFiles.length > 0) {
168+
console.log(` comments:`);
169+
STEPS[0].activitiesFiles.map(activityFile => {
170+
console.log(` - ${activityFile}`);
171+
})
172+
}
173+
console.log(`
130174
- type: assignRegistrant
131-
issue: '%actions.step_1.data.number%'
175+
issue: '%actions.step_0.data.number%'`)
132176

133-
steps:`);
177+
console.log(`
178+
steps:
179+
- title: "Welcome to the course"
180+
description: "Know where to find documentation and help, install CodeQL, setup your IDE."
181+
event: issues.closed
182+
link: '{{ repoUrl }}/issues/1'
183+
actions:
184+
- type: gate
185+
left: '%payload.issue.title%'
186+
operator: search
187+
right: "${escapeDoubleQuoteYamlString(INTRO_ISSUES[INTRO_ISSUES.length - 1].title)}"
188+
- type: respond
189+
issue: "${escapeDoubleQuoteYamlString(INTRO_ISSUES[INTRO_ISSUES.length - 1].title)}"
190+
with: ${INTRO_OK_MESSAGE}`);
134191

135192
STEPS.map((step, i) => {
136193
// The markdown string to look for in the comment from github-actions[bot]
@@ -140,7 +197,7 @@ STEPS.map((step, i) => {
140197
- title: "${escapeDoubleQuoteYamlString(step.title)}"
141198
description: "${escapeDoubleQuoteYamlString(step.description)}"
142199
event: commit_comment.created
143-
link: '{{ repoUrl }}/issues${i === 0 ? '/1' : ''}'
200+
link: '{{ repoUrl }}/issues/'
144201
actions:
145202
# Ensure comment is posted by github-actions
146203
- type: gate
@@ -166,7 +223,7 @@ STEPS.map((step, i) => {
166223
data:
167224
commit: '%payload.comment.commit_id%'
168225
commentUrl: '%payload.comment.html_url%'
169-
226+
170227
# Answer is correct!!`);
171228

172229
/* The following is disabled for now as Learning Lab is using ^15.18.3 of
@@ -216,11 +273,9 @@ STEPS.map((step, i) => {
216273
# Create Issue for next task
217274
- type: createIssue
218275
title: "${escapeDoubleQuoteYamlString(issueTitle(next, i + 1))}"
219-
body: ${next.instructionsFile}`);
220-
if(next.activitiesFiles.length > 0) {
221-
console.log(` comments:`);
222-
}
223-
next.activitiesFiles.map(file => {
276+
body: ${next.instructionsFile}
277+
comments:`);
278+
next.activitiesFiles.map(file => {
224279
console.log(` - ${file}`)
225280
})
226281
console.log(` action_id: next_issue
@@ -243,9 +298,9 @@ STEPS.map((step, i) => {
243298
repo: '%payload.repository.name%'
244299
sha: '%payload.comment.commit_id%'
245300
body: |
246-
Congratulations, looks like the query you introduced for step ${i + 1} finds the correct results!
301+
Congratulations, looks like the query you introduced for step ${INTRO_ISSUES.length + i + 1} finds the correct results!
247302
248-
Take a look at the [instructions for the next step](%actions.next_issue.data.html_url%) to continue.
303+
Merge this Pull Request (unless you're on master), and take a look at the [instructions for the next step](%actions.next_issue.data.html_url%) to continue.
249304
250305
# Close current issue
251306
- type: closeIssue

0 commit comments

Comments
 (0)