-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.92 KB
/
initialize-course.yml
File metadata and controls
84 lines (72 loc) · 2.92 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
name: Initialize Interactive Course
on:
workflow_dispatch:
permissions:
contents: read
issues: write
jobs:
initialize:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Create Labels And First 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 issueDir = path.join(process.env.GITHUB_WORKSPACE, '.github', 'course-issues');
const labels = [
{ name: 'course', color: '1d76db', description: 'Interactive course issue' },
{ name: 'course:step-1', color: '0e8a16', description: 'Interactive course step 1: authentication' },
{ name: 'course:step-2', color: '1d9b73', description: 'Interactive course step 2: signing' },
{ name: 'course:step-3', color: '5319e7', description: 'Interactive course step 3: practice PR' },
{ name: 'course:step-4', color: 'fbca04', description: 'Interactive course step 4: final evaluation' },
{ name: 'course:complete', color: '1d9b73', description: 'Interactive course completed' }
];
for (const label of labels) {
try {
await github.rest.issues.getLabel({
owner,
repo,
name: label.name
});
} catch (error) {
if (error.status === 404) {
await github.rest.issues.createLabel({
owner,
repo,
...label
});
} else {
throw error;
}
}
}
const firstTitle = 'BitByBit Academy Step 1: Verify SSH authentication';
const existingIssues = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: 'all',
per_page: 100
});
const existingFirst = existingIssues.find((issue) => issue.title === firstTitle);
if (existingFirst) {
core.notice(`Course already initialized. Existing issue: ${existingFirst.html_url}`);
return;
}
const firstBody = fs
.readFileSync(path.join(issueDir, 'step-1-local-setup.md'), 'utf8')
.replaceAll('{{repo_url}}', repoUrl);
const created = await github.rest.issues.create({
owner,
repo,
title: firstTitle,
body: firstBody,
labels: ['course', 'course:step-1']
});
core.notice(`Created first course issue: ${created.data.html_url}`);