返回 DeepSeek-Reasonix
issue-version-label.yml
根目录 / .github / workflows / issue-version-label.yml
1 name: Label issue version
2
3 # Issue forms can't let a reporter set a label directly (that needs triage rights),
4 # so the bug/feature forms carry a "Version line" dropdown and this workflow reads
5 # the submitted value and applies the matching v2/v3 label on their behalf.
6 on:
7 issues:
8 types: [opened, edited]
9
10 permissions:
11 issues: write
12
13 concurrency:
14 group: issue-version-${{ github.event.issue.number }}
15 cancel-in-progress: true
16
17 jobs:
18 label:
19 runs-on: ubuntu-latest
20 steps:
21 - uses: actions/github-script@v9
22 with:
23 script: |
24 const body = context.payload.issue.body || '';
25 const sectionOf = (name) =>
26 body.split(/^###\s+/m).find((s) => new RegExp(`^${name}`, 'i').test(s)) || '';
27
28 const lines = ['v1', 'v2', 'v3'];
29 const m = sectionOf('Version line').match(/\bv([23])\b/i);
30 if (!m) {
31 core.info('No version line found; nothing to label.');
32 return;
33 }
34 let choice = 'v' + m[1];
35
36 // The dropdown is a choice, and v2 sits first, so it gets picked by
37 // reporters who are actually on the other line. `Exact version` is
38 // pasted from `reasonix --version`, so when it parses it is the
39 // better evidence: 1.x Go rewrite (v2), 2.x Studio (v3, studio
40 // branch). 0.x is no longer a filing line. Anything that does not
41 // parse (a commit sha, "main-v2", "studio") leaves the dropdown
42 // to decide.
43 const exact = sectionOf('Exact version').match(/\b(\d+)\.(\d+)\.(\d+)/);
44 if (exact) {
45 const major = Number(exact[1]);
46 const fromVersion = major === 1 ? 'v2' : major === 2 ? 'v3' : null;
47 if (fromVersion && fromVersion !== choice) {
48 core.info(`Version line says ${choice} but ${exact[0]} says ${fromVersion}; trusting the version.`);
49 choice = fromVersion;
50 }
51 }
52 await github.rest.issues.addLabels({
53 ...context.repo,
54 issue_number: context.issue.number,
55 labels: [choice],
56 });
57 // Keep version-line labels mutually exclusive if an edit flipped the choice.
58 for (const other of lines.filter((l) => l !== choice)) {
59 try {
60 await github.rest.issues.removeLabel({
61 ...context.repo,
62 issue_number: context.issue.number,
63 name: other,
64 });
65 } catch (e) {
66 core.info(`No ${other} label to remove.`);
67 }
68 }
69
69 lines YAML