-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (100 loc) · 4.05 KB
/
course-progress.yml
File metadata and controls
113 lines (100 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Advance Interactive Course
on:
issues:
types: [closed]
permissions:
contents: read
issues: write
jobs:
advance:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Open Next Course Issue
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const owner = context.repo.owner;
const repo = context.repo.repo;
const repoUrl = `https://github.com/${owner}/${repo}`;
const labels = context.payload.issue.labels.map((label) => label.name);
const issueDir = path.join(process.env.GITHUB_WORKSPACE, '.github', 'course-issues');
const steps = {
'course:step-1': {
title: 'BitByBit Academy Step 2: Verify commit signing',
file: 'step-2-signing-check.md',
labels: ['course', 'course:step-2']
},
'course:step-2': {
title: 'BitByBit Academy Step 3: Open your practice pull request',
file: 'step-2-practice-pr.md',
labels: ['course', 'course:step-3']
},
'course:step-3': {
title: 'BitByBit Academy Step 4: Complete your final evaluation',
file: 'step-3-final-evaluation.md',
labels: ['course', 'course:step-4']
},
'course:step-4': {
title: 'BitByBit Academy: Course complete',
file: 'step-4-complete.md',
labels: ['course', 'course:complete']
}
};
const currentStep = Object.keys(steps).find((name) => labels.includes(name));
if (!currentStep) {
core.notice('Closed issue is not part of the interactive course.');
return;
}
const sender = context.payload.sender.login;
if ((currentStep === 'course:step-3' || currentStep === 'course:step-4') && !sender.includes('github-actions')) {
await github.rest.issues.update({
owner,
repo,
issue_number: context.payload.issue.number,
state: 'open'
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.payload.issue.number,
body: "BitByBit Academy mentor note: Nice try! 😉 You cannot close this step manually. You must pass the required Pull Request checks. The autograder bot will close this issue automatically when you succeed."
});
return;
}
const nextStep = steps[currentStep];
const existingIssues = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: 'all',
per_page: 100
});
const existingNext = existingIssues.find((issue) => issue.title === nextStep.title);
if (existingNext) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.payload.issue.number,
body: `BitByBit Academy mentor note: your next step already exists here: ${existingNext.html_url}`
});
return;
}
const body = fs
.readFileSync(path.join(issueDir, nextStep.file), 'utf8')
.replaceAll('{{repo_url}}', repoUrl);
const created = await github.rest.issues.create({
owner,
repo,
title: nextStep.title,
body,
labels: nextStep.labels
});
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.payload.issue.number,
body: `BitByBit Academy mentor note: nice work. Your next step is ready: ${created.data.html_url}`
});