-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (65 loc) · 2.58 KB
/
create-issues.yml
File metadata and controls
79 lines (65 loc) · 2.58 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
name: Create Good First Issues
on:
workflow_dispatch: # run manually from the Actions tab
jobs:
create-issues:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/checkout@v4
- name: Post issues from .github/issues/
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const dir = '.github/issues';
const files = fs.readdirSync(dir)
.filter(f => f.endsWith('.md'))
.sort();
// Fetch all existing issue titles (open + closed) for idempotency
const existing = await github.paginate(
github.rest.issues.listForRepo,
{ owner: context.repo.owner, repo: context.repo.repo, state: 'all', per_page: 100 }
);
const existingTitles = new Set(existing.map(i => i.title));
for (const file of files) {
const raw = fs.readFileSync(path.join(dir, file), 'utf8');
// Parse YAML frontmatter between the first two --- delimiters
const fmMatch = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
if (!fmMatch) {
core.warning(`No frontmatter found in ${file}, skipping.`);
continue;
}
const [, frontmatter, body] = fmMatch;
// Parse title (supports quoted and unquoted values)
const titleMatch = frontmatter.match(/^title:\s*"?(.+?)"?\s*$/m);
if (!titleMatch) {
core.warning(`No title in ${file}, skipping.`);
continue;
}
const title = titleMatch[1];
// Parse labels array: ["label one", "label two"]
const labelsMatch = frontmatter.match(/^labels:\s*(\[.*\])\s*$/m);
let labels = [];
if (labelsMatch) {
try {
labels = JSON.parse(labelsMatch[1]);
} catch {
core.warning(`Could not parse labels in ${file}`);
}
}
if (existingTitles.has(title)) {
core.info(`⏭ Already exists — skipping: "${title}"`);
continue;
}
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
labels,
body: body.trim(),
});
core.info(`✅ Created: "${title}"`);
}