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

Commit ba1ff67

Browse files
authored
Merge pull request #24 from github/template
Improve template for course authors
2 parents 22a6702 + f7ecc3b commit ba1ff67

File tree

3 files changed

+95
-15
lines changed

3 files changed

+95
-15
lines changed

templates/learninglab/course/config.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ description: >-
99
template:
1010
repo: <MY-COURSE-REPO>-template
1111
name: <MY-COURSE-REPO>
12+
1213
before:
1314
- type: createIssue
1415
title: 'Step 1 - Your first query'
15-
body: 01_function_definitions.md
16+
body: step-1.md
17+
action_id: step_1
18+
- type: assignRegistrant
19+
issue: '%actions.step_1.data.number%'
20+
1621
steps:
1722

1823
- title: "Your first query"
19-
description: "Get set up using CodeQL, and run your first query"
24+
description: "Write your first query"
2025
event: commit_comment.created
2126
link: '{{ repoUrl }}/issues/1'
2227
actions:
@@ -25,21 +30,37 @@ steps:
2530
left: '%payload.sender.login%'
2631
operator: ===
2732
right: github-actions[bot]
33+
# Ensure comment is relevant for this issue
34+
- type: gate
35+
left: '%payload.comment.body%'
36+
operator: search
37+
# regex-escape then yaml-escape the expected markdown string
38+
right: "/Results for `step-1\\.ql`\\:/"
2839
# Ensure comment has expected completed string
2940
- type: gate
3041
left: '%payload.comment.body%'
3142
operator: search
3243
# regex-escape then yaml-escape the expected markdown string
3344
right: "/Results for `step-1\\.ql`\\: \\*\\*correct\\*\\* \\(3 results\\)/"
45+
else:
46+
- type: respond
47+
issue: "Step 1 - Your first query"
48+
with: fail.md
49+
data:
50+
commit: '%payload.comment.commit_id%'
51+
commentUrl: '%payload.comment.html_url%'
3452

3553
# Answer is correct!!
3654

3755
# Create Issue for next task
3856
- type: createIssue
39-
title: "Step 2 - alloca definition"
40-
body: 02_alloca_definition.md
57+
title: "Step 2 - Your second query"
58+
body: step-2.md
4159
action_id: next_issue
4260

61+
- type: assignRegistrant
62+
issue: '%actions.next_issue.data.number%'
63+
4364
# Make comment on current issue with link to commit that introduces correct query
4465
- type: respond
4566
issue: "Step 1 - Your first query"
@@ -63,8 +84,8 @@ steps:
6384
- type: closeIssue
6485
issue: "Step 1 - Your first query"
6586

66-
- title: "alloca definition"
67-
description: "write a query that looks for definitions of a macro"
87+
- title: "Your second query"
88+
description: "Write your second query"
6889
event: commit_comment.created
6990
link: '{{ repoUrl }}/issues'
7091
actions:
@@ -73,23 +94,36 @@ steps:
7394
left: '%payload.sender.login%'
7495
operator: ===
7596
right: github-actions[bot]
97+
# Ensure comment is relevant for this issue
98+
- type: gate
99+
left: '%payload.comment.body%'
100+
operator: search
101+
# regex-escape then yaml-escape the expected markdown string
102+
right: "/Results for `step-2\\.ql`\\:/"
76103
# Ensure comment has expected completed string
77104
- type: gate
78105
left: '%payload.comment.body%'
79106
operator: search
80107
# regex-escape then yaml-escape the expected markdown string
81108
right: "/Results for `step-2\\.ql`\\: \\*\\*correct\\*\\* \\(5 results\\)/"
109+
else:
110+
- type: respond
111+
issue: "Step 2 - Your second query"
112+
with: fail.md
113+
data:
114+
commit: '%payload.comment.commit_id%'
115+
commentUrl: '%payload.comment.html_url%'
82116

83117
# Answer is correct!!
84118

85119

86120
# Make comment on current issue with final message
87121
- type: respond
88-
issue: "Step 2 - alloca definition"
122+
issue: "Step 2 - Your second query"
89123
with: end.md
90124
data:
91125
commit: '%payload.comment.commit_id%'
92126

93127
# Close current issue
94128
- type: closeIssue
95-
issue: "Step 2 - alloca definition"
129+
issue: "Step 2 - Your second query"

templates/learninglab/course/generate-config.js

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ template:
2929
* * `{{commit}}` - Sha that was the head of the most recent PUSH
3030
*/
3131
const 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
*/
6372
const 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(`
108119
before:
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

115135
STEPS.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
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Ooops! The query you submitted in {{commit}} didn't find the right results. Have a look at the [comment]({{commentUrl}}).
2+
3+
To submit a new iteration of your query, you just have to push a new commit to the same branch (`master` or the PR branch).

0 commit comments

Comments
 (0)