-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (54 loc) · 2.46 KB
/
Copy pathsync-blocked-label.yml
File metadata and controls
65 lines (54 loc) · 2.46 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
name: Sync status:blocked label from dependencies
on:
issues:
types: [opened, edited, reopened]
permissions:
issues: write
jobs:
sync-blocked:
runs-on: ubuntu-latest
steps:
- name: Apply/remove status labels based on blocked-by
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const issue = context.payload.issue;
const issue_number = issue.number;
const body = (issue.body || "").toLowerCase();
// Only manage labels when the issue explicitly opts into dependency annotations.
const hasDependenciesSection = body.includes("## dependencies");
// Consider an issue blocked only when blocked-by contains at least one
// explicit issue reference (e.g., blocked-by: #123 or blocked-by: #123, #456).
// Values like "blocked-by: none" must not apply status:blocked.
const blockedByLines = body
.split("\n")
.map(l => l.trim())
.filter(l => l.startsWith("blocked-by:"));
const hasBlockedByIssueRef = blockedByLines.some(line => /#\d+/.test(line));
const labels = issue.labels.map(l => l.name);
const hasBlockedLabel = labels.includes("status:blocked");
const hasReadyLabel = labels.includes("status:ready");
async function addLabel(name) {
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [name] });
}
async function removeLabel(name) {
try {
await github.rest.issues.removeLabel({ owner, repo, issue_number, name });
} catch (e) {
// ignore if label doesn't exist or already removed
}
}
if (!hasDependenciesSection) {
// Do not auto-apply status labels if the issue doesn't use the dependency convention.
return;
}
if (hasBlockedByIssueRef) {
if (!hasBlockedLabel) await addLabel("status:blocked");
if (hasReadyLabel) await removeLabel("status:ready");
} else {
if (hasBlockedLabel) await removeLabel("status:blocked");
// Optional: mark ready when dependencies section exists but no blocked-by lines exist
if (!hasReadyLabel) await addLabel("status:ready");
}