@bbcsoftwarefactory/skills 0.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.json +2 -3
- package/dist/skills/code-quality-gate/SKILL.md +4 -5
- package/dist/skills/code-quality-gate/references/gate-bigo.md +1 -1
- package/dist/skills/delivery-coordinator/SKILL.md +7 -8
- package/dist/skills/delivery-coordinator/references/hud-output.md +1 -1
- package/dist/skills/delivery-coordinator/references/issue-claim.md +5 -5
- package/dist/skills/delivery-coordinator/references/issue-dedup.md +1 -1
- package/dist/skills/delivery-coordinator/references/worktree-isolation.md +2 -2
- package/dist/skills/greptile-review-loop/SKILL.md +3 -4
- package/dist/skills/greptile-review-loop/references/review-protocol.md +1 -1
- package/dist/skills/issue-reviewer/SKILL.md +10 -13
- package/dist/skills/issue-reviewer/references/review-format.md +1 -1
- package/dist/skills/issue-reviewer/references/triage.md +6 -6
- package/dist/skills/question-gate/SKILL.md +6 -8
- package/dist/skills/question-gate/references/client-hooks.md +10 -10
- package/dist/skills/question-gate/references/diagram-routing.md +3 -3
- package/dist/skills/skill-clean-architecture/SKILL.md +2 -3
- package/dist/skills/skill-clean-architecture/references/source-headers.md +2 -3
- package/dist/skills/tool-depot/references/readonly-access.md +1 -1
- package/dist/skills/tool-depot/references/tool-catalog.json +2 -2
- package/dist/skills/watcher-observability/SKILL.md +3 -4
- package/dist/skills/watcher-observability/references/batch-protocol.md +6 -6
- package/dist/skills/watcher-observability/references/configuration.md +1 -1
- package/dist/skills/watcher-observability/references/error-scan.md +1 -1
- package/dist/skills/watcher-observability/references/live-protocol.md +8 -8
- package/dist/skills/watcher-observability/references/server-account.md +8 -8
- package/dist/skills/watcher-observability/server/watcher-gate.sh +1 -1
- package/dist/skills/watcher-observability/tests/watcher-gate.test.sh +10 -7
- package/dist/skills/workflow-auditor/SKILL.md +3 -5
- package/dist/skills/workflow-auditor/references/audit-protocol.md +3 -3
- package/dist/skills/workflow-auditor/references/ledger.md +1 -1
- package/package.json +26 -27
- package/dist/skills/code-quality-gate/scripts/extract-diff-scope.py +0 -225
- package/dist/skills/code-quality-gate/tests/extract-diff-scope.test.sh +0 -200
- package/dist/skills/delivery-coordinator/scripts/check-issue-claim.py +0 -363
- package/dist/skills/delivery-coordinator/scripts/check-worktree-guard.py +0 -220
- package/dist/skills/delivery-coordinator/scripts/classify-change-lane.py +0 -263
- package/dist/skills/delivery-coordinator/tests/check-issue-claim.test.sh +0 -221
- package/dist/skills/delivery-coordinator/tests/check-worktree-guard.test.sh +0 -123
- package/dist/skills/delivery-coordinator/tests/classify-change-lane.test.sh +0 -124
- package/dist/skills/greptile-review-loop/scripts/review-loop.py +0 -435
- package/dist/skills/greptile-review-loop/tests/review-loop.test.sh +0 -331
- package/dist/skills/issue-reviewer/scripts/fetch-issue-attachments.py +0 -239
- package/dist/skills/issue-reviewer/scripts/plan-issue-triage.py +0 -311
- package/dist/skills/issue-reviewer/tests/fetch-issue-attachments.test.sh +0 -90
- package/dist/skills/issue-reviewer/tests/plan-issue-triage.test.sh +0 -168
- package/dist/skills/question-gate/scripts/triage-question.py +0 -713
- package/dist/skills/question-gate/tests/question-corpus.test.sh +0 -32
- package/dist/skills/question-gate/tests/triage-question.test.sh +0 -441
- package/dist/skills/skill-clean-architecture/scripts/measure-bigo.py +0 -427
- package/dist/skills/skill-clean-architecture/tests/measure-bigo.test.sh +0 -222
- package/dist/skills/watcher-observability/scripts/error-scan.py +0 -318
- package/dist/skills/watcher-observability/scripts/resolve-containers.py +0 -155
- package/dist/skills/watcher-observability/scripts/save-counts.py +0 -381
- package/dist/skills/watcher-observability/scripts/summarize-logs.py +0 -113
- package/dist/skills/watcher-observability/scripts/watch-live.py +0 -606
- package/dist/skills/watcher-observability/tests/error-scan.test.sh +0 -257
- package/dist/skills/watcher-observability/tests/live-windows.test.sh +0 -177
- package/dist/skills/watcher-observability/tests/resolve-containers.test.sh +0 -87
- package/dist/skills/watcher-observability/tests/save-counts.test.sh +0 -338
- package/dist/skills/watcher-observability/tests/sleuth.test.sh +0 -176
- package/dist/skills/watcher-observability/tests/summarize-logs.test.sh +0 -105
- package/dist/skills/watcher-observability/tests/watcher-config.test.sh +0 -70
- package/dist/skills/workflow-auditor/scripts/audit-ledger.py +0 -624
- package/dist/skills/workflow-auditor/scripts/list-zed-commands.py +0 -183
- package/dist/skills/workflow-auditor/scripts/render-workflow.py +0 -201
- package/dist/skills/workflow-auditor/scripts/validate-skills.py +0 -444
- package/dist/skills/workflow-auditor/tests/audit-ledger.test.sh +0 -660
- package/dist/skills/workflow-auditor/tests/list-zed-commands.test.sh +0 -93
- package/dist/skills/workflow-auditor/tests/render-workflow.test.sh +0 -135
- package/dist/skills/workflow-auditor/tests/validate-skills.test.sh +0 -190
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
cd -- "${BASH_SOURCE[0]%/*}/.."
|
|
4
|
-
|
|
5
|
-
SCRIPT="$PWD/scripts/extract-diff-scope.py"
|
|
6
|
-
PYTHON_BIN=$(command -v python3 || command -v python)
|
|
7
|
-
run() { "$PYTHON_BIN" -I -B "$SCRIPT" "$@"; }
|
|
8
|
-
scratch=$(mktemp -d)
|
|
9
|
-
trap 'rm -rf -- "$scratch"' EXIT
|
|
10
|
-
|
|
11
|
-
failures=0
|
|
12
|
-
checks=0
|
|
13
|
-
|
|
14
|
-
assert_contains() {
|
|
15
|
-
local label=$1 haystack=$2 needle=$3
|
|
16
|
-
checks=$((checks + 1))
|
|
17
|
-
if ! printf '%s' "$haystack" | grep -Fq -- "$needle"; then
|
|
18
|
-
printf 'FAIL [%s]: expected to contain: %s\n' "$label" "$needle" >&2
|
|
19
|
-
failures=$((failures + 1))
|
|
20
|
-
fi
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
assert_not_contains() {
|
|
24
|
-
local label=$1 haystack=$2 needle=$3
|
|
25
|
-
checks=$((checks + 1))
|
|
26
|
-
if printf '%s' "$haystack" | grep -Fq -- "$needle"; then
|
|
27
|
-
printf 'FAIL [%s]: expected NOT to contain: %s\n' "$label" "$needle" >&2
|
|
28
|
-
failures=$((failures + 1))
|
|
29
|
-
fi
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
repo="$scratch/repo"
|
|
33
|
-
mkdir -p "$repo/src" "$repo/dist"
|
|
34
|
-
git -C "$repo" init -q
|
|
35
|
-
git -C "$repo" config user.email "test@example.com"
|
|
36
|
-
git -C "$repo" config user.name "Test"
|
|
37
|
-
|
|
38
|
-
cat >"$repo/src/service.ts" <<'EOF'
|
|
39
|
-
export function greet(name: string): string {
|
|
40
|
-
return `hi ${name}`
|
|
41
|
-
}
|
|
42
|
-
EOF
|
|
43
|
-
git -C "$repo" add src/service.ts
|
|
44
|
-
git -C "$repo" commit -q -m "init"
|
|
45
|
-
|
|
46
|
-
# 1. Working mode includes tracked modifications AND untracked new .ts files, excludes dist/ and .md
|
|
47
|
-
cat >"$repo/src/service.ts" <<'EOF'
|
|
48
|
-
export function greet(name: string, items: string[]): string {
|
|
49
|
-
const raw: any = name
|
|
50
|
-
if (items.length > 0) {
|
|
51
|
-
return raw
|
|
52
|
-
} else {
|
|
53
|
-
return items.filter(x => items.includes(x)).join(',')
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
EOF
|
|
57
|
-
cat >"$repo/src/helper.ts" <<'EOF'
|
|
58
|
-
export const castVal = (v: unknown) => v as string
|
|
59
|
-
export const dupTernary = async (fn: (a: string, opt?: string) => Promise<void>, opt?: string) =>
|
|
60
|
-
opt
|
|
61
|
-
? await fn('a', opt)
|
|
62
|
-
: await fn('a')
|
|
63
|
-
EOF
|
|
64
|
-
cat >"$repo/dist/generated.js" <<'EOF'
|
|
65
|
-
const ignored: any = 1
|
|
66
|
-
EOF
|
|
67
|
-
cat >"$repo/README.md" <<'EOF'
|
|
68
|
-
# Ignored markdown
|
|
69
|
-
EOF
|
|
70
|
-
|
|
71
|
-
out_working=$(cd "$repo" && run --working)
|
|
72
|
-
assert_contains "working mode" "$out_working" 'mode: "working"'
|
|
73
|
-
assert_contains "working files_changed" "$out_working" 'files_changed: 2'
|
|
74
|
-
assert_contains "working tracked file" "$out_working" 'file: "src/service.ts"'
|
|
75
|
-
assert_contains "working untracked file" "$out_working" 'file: "src/helper.ts"'
|
|
76
|
-
assert_not_contains "working excludes dist" "$out_working" 'dist/generated.js'
|
|
77
|
-
assert_not_contains "working excludes md" "$out_working" 'README.md'
|
|
78
|
-
assert_contains "working typesafe candidate" "$out_working" 'const raw: any = name'
|
|
79
|
-
assert_contains "working earlyreturn candidate" "$out_working" '} else {'
|
|
80
|
-
assert_contains "working duplicate ternary candidate" "$out_working" "? await fn('a', opt)"
|
|
81
|
-
assert_contains "working bigo candidate" "$out_working" 'items.filter(x => items.includes(x))'
|
|
82
|
-
|
|
83
|
-
# The `records` section lists every added line, so the checks above pass even if
|
|
84
|
-
# a gate regex is broken. Assert inside each gate's own section as well.
|
|
85
|
-
section() { printf '%s\n' "$1" | sed -n "/^ $2:/,/^ [a-z_]*:/p"; }
|
|
86
|
-
ts_sec=$(section "$out_working" typesafe_candidates)
|
|
87
|
-
er_sec=$(section "$out_working" earlyreturn_candidates)
|
|
88
|
-
bo_sec=$(section "$out_working" bigo_candidates)
|
|
89
|
-
assert_contains "typesafe section: any" "$ts_sec" 'const raw: any = name'
|
|
90
|
-
assert_contains "typesafe section: as cast" "$ts_sec" 'v as string'
|
|
91
|
-
assert_not_contains "typesafe section: no plain line" "$ts_sec" 'if (items.length > 0) {'
|
|
92
|
-
assert_contains "earlyreturn section: else" "$er_sec" '} else {'
|
|
93
|
-
assert_contains "earlyreturn section: ternary" "$er_sec" "? await fn('a', opt)"
|
|
94
|
-
assert_not_contains "earlyreturn section: no any line" "$er_sec" 'const raw: any = name'
|
|
95
|
-
assert_contains "bigo section: filter+includes" "$bo_sec" 'items.filter(x => items.includes(x))'
|
|
96
|
-
assert_not_contains "bigo section: no any line" "$bo_sec" 'const raw: any = name'
|
|
97
|
-
|
|
98
|
-
# 2. Staged mode only includes staged files
|
|
99
|
-
git -C "$repo" add src/helper.ts
|
|
100
|
-
out_staged=$(cd "$repo" && run --staged)
|
|
101
|
-
assert_contains "staged mode" "$out_staged" 'mode: "staged"'
|
|
102
|
-
assert_contains "staged files_changed" "$out_staged" 'files_changed: 1'
|
|
103
|
-
assert_contains "staged has helper.ts" "$out_staged" 'file: "src/helper.ts"'
|
|
104
|
-
assert_not_contains "staged excludes unstaged service.ts" "$out_staged" 'file: "src/service.ts"'
|
|
105
|
-
|
|
106
|
-
# 3. Range mode works across commits
|
|
107
|
-
git -C "$repo" add src/service.ts
|
|
108
|
-
git -C "$repo" commit -q -m "wave 1"
|
|
109
|
-
out_range=$(cd "$repo" && run --range HEAD~1..HEAD)
|
|
110
|
-
assert_contains "range mode" "$out_range" 'mode: "range"'
|
|
111
|
-
assert_contains "range files_changed" "$out_range" 'files_changed: 2'
|
|
112
|
-
|
|
113
|
-
# 4. Head mode works and empty working tree yields 0 files
|
|
114
|
-
out_head=$(cd "$repo" && run --head 1)
|
|
115
|
-
assert_contains "head mode" "$out_head" 'mode: "head"'
|
|
116
|
-
assert_contains "head files_changed" "$out_head" 'files_changed: 2'
|
|
117
|
-
|
|
118
|
-
rm -f "$repo/dist/generated.js" "$repo/README.md"
|
|
119
|
-
out_clean=$(cd "$repo" && run --working)
|
|
120
|
-
assert_contains "clean files_changed 0" "$out_clean" 'files_changed: 0'
|
|
121
|
-
assert_contains "clean empty records" "$out_clean" 'records: []'
|
|
122
|
-
|
|
123
|
-
# 5. Unknown options and invalid --head must exit non-zero
|
|
124
|
-
checks=$((checks + 1))
|
|
125
|
-
if (cd "$repo" && run --bogus-flag >/dev/null 2>&1); then
|
|
126
|
-
printf 'FAIL [unknown option]: expected non-zero exit code\n' >&2
|
|
127
|
-
failures=$((failures + 1))
|
|
128
|
-
fi
|
|
129
|
-
|
|
130
|
-
checks=$((checks + 1))
|
|
131
|
-
if (cd "$repo" && run --head foo >/dev/null 2>&1); then
|
|
132
|
-
printf 'FAIL [invalid --head]: expected non-zero exit code\n' >&2
|
|
133
|
-
failures=$((failures + 1))
|
|
134
|
-
fi
|
|
135
|
-
|
|
136
|
-
# 6. diff.noprefix=true in git config must still parse tracked files
|
|
137
|
-
out_noprefix=$(cd "$repo" && git -c diff.noprefix=true status >/dev/null && GIT_CONFIG_PARAMETERS="'diff.noprefix=true'" run --range HEAD~1..HEAD)
|
|
138
|
-
assert_contains "diff.noprefix=true preserves files_changed" "$out_noprefix" 'files_changed: 2'
|
|
139
|
-
assert_contains "diff.noprefix=true preserves records" "$out_noprefix" 'const raw: any = name'
|
|
140
|
-
|
|
141
|
-
# 7. ADR 0001 portability: only python and git are needed (no bash, awk, wc or tr).
|
|
142
|
-
gitdir="$scratch/only-git"
|
|
143
|
-
mkdir -p "$gitdir"
|
|
144
|
-
ln -s "$(command -v git)" "$gitdir/git"
|
|
145
|
-
py_abs=$("$PYTHON_BIN" -c 'import sys; print(sys.executable)')
|
|
146
|
-
out_bare=$(cd "$repo" && env -i HOME="$HOME" PATH="$gitdir" "$py_abs" -I -B "$SCRIPT" --head 1 2>&1) || true
|
|
147
|
-
assert_contains "no awk/bash: runs" "$out_bare" 'files_changed: 2'
|
|
148
|
-
assert_contains "no awk/bash: records" "$out_bare" 'const raw: any = name'
|
|
149
|
-
|
|
150
|
-
# 8. Legacy escaping is part of the contract: the files list escapes quotes,
|
|
151
|
-
# tracked and untracked records carry the path as git prints it.
|
|
152
|
-
cat >"$repo/src/quo\"te.ts" <<'EOF'
|
|
153
|
-
const q: any = 1
|
|
154
|
-
EOF
|
|
155
|
-
out_quote=$(cd "$repo" && run --working)
|
|
156
|
-
assert_contains "quoted name escaped in files" "$out_quote" ' - "src/quo\"te.ts"'
|
|
157
|
-
assert_contains "quoted name raw in untracked record" "$out_quote" ' - file: "src/quo"te.ts"'
|
|
158
|
-
rm -f "$repo/src/quo\"te.ts"
|
|
159
|
-
|
|
160
|
-
# 9. Each BigO alternative must be reachable on its own: a line that only
|
|
161
|
-
# matches through .map( must reach bigo_candidates.
|
|
162
|
-
cat >"$repo/src/only-map.ts" <<'EOF'
|
|
163
|
-
export const ids = rows.map(r => r.id)
|
|
164
|
-
EOF
|
|
165
|
-
bo_map=$(section "$(cd "$repo" && run --working)" bigo_candidates)
|
|
166
|
-
assert_contains "bigo section: map alone" "$bo_map" 'rows.map(r => r.id)'
|
|
167
|
-
rm -f "$repo/src/only-map.ts"
|
|
168
|
-
|
|
169
|
-
# 10. #41 regression: deep nesting is 12+ leading spaces before if/for/while.
|
|
170
|
-
printf 'function f() {\n if (deep) {}\n if (shallow) {}\n}\n' >"$repo/src/nesting.ts"
|
|
171
|
-
er_nest=$(section "$(cd "$repo" && run --working)" earlyreturn_candidates)
|
|
172
|
-
assert_contains "earlyreturn: 12 spaces is deep" "$er_nest" ' if (deep) {}'
|
|
173
|
-
assert_not_contains "earlyreturn: 10 spaces is not" "$er_nest" 'if (shallow)'
|
|
174
|
-
rm -f "$repo/src/nesting.ts"
|
|
175
|
-
|
|
176
|
-
# 11. Line numbers are positions in the NEW file. Removed lines ("-") and the
|
|
177
|
-
# "" marker do not exist there, so they must not
|
|
178
|
-
# advance the counter (the awk version counted them and shifted every
|
|
179
|
-
# added line after a deletion).
|
|
180
|
-
lines_repo="$scratch/lines"
|
|
181
|
-
mkdir -p "$lines_repo"
|
|
182
|
-
git -C "$lines_repo" init -q
|
|
183
|
-
git -C "$lines_repo" config user.email "test@example.com"
|
|
184
|
-
git -C "$lines_repo" config user.name "Test"
|
|
185
|
-
printf 'a\nb\nc\nd\n' >"$lines_repo/replace.ts"
|
|
186
|
-
printf 'x\ny' >"$lines_repo/nonl.ts"
|
|
187
|
-
git -C "$lines_repo" add . && git -C "$lines_repo" commit -q -m base
|
|
188
|
-
printf 'a\nconst x: any = 1\nconst y: any = 2\nd\n' >"$lines_repo/replace.ts"
|
|
189
|
-
printf 'x\ny\nconst z: any = 3\n' >"$lines_repo/nonl.ts"
|
|
190
|
-
out_lines=$(cd "$lines_repo" && run --working)
|
|
191
|
-
lines_of() { printf '%s\n' "$out_lines" | grep -B3 -F "content: \"$1\"" | grep -m1 -o 'line: [0-9]*'; }
|
|
192
|
-
checks=$((checks + 1))
|
|
193
|
-
got="$(lines_of 'const x: any = 1') $(lines_of 'const y: any = 2') $(lines_of 'const z: any = 3')"
|
|
194
|
-
if [[ $got != 'line: 2 line: 3 line: 3' ]]; then
|
|
195
|
-
printf 'FAIL [new-file line numbers]: got %s, want line: 2 line: 3 line: 3\n' "$got" >&2
|
|
196
|
-
failures=$((failures + 1))
|
|
197
|
-
fi
|
|
198
|
-
|
|
199
|
-
printf 'extract-diff-scope.test.sh: %d checks, %d failures\n' "$checks" "$failures"
|
|
200
|
-
[[ "$failures" -eq 0 ]]
|
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""check-issue-claim.py: decide whether one person may work on a canonical GitHub issue.
|
|
3
|
-
|
|
4
|
-
Read-only and offline: it evaluates GitHub REST (or `gh --json`) output and `git ls-remote`
|
|
5
|
-
output that the caller fetched through Tool Depot, and never calls GitHub itself.
|
|
6
|
-
Rules CL1-CL12 are defined in references/issue-claim.md.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from datetime import datetime, timedelta, timezone
|
|
10
|
-
import json
|
|
11
|
-
import re
|
|
12
|
-
import sys
|
|
13
|
-
|
|
14
|
-
PHASES = ('check', 'verify', 'release', 'status')
|
|
15
|
-
DEFAULT_LABEL = 'status:in-progress'
|
|
16
|
-
DEFAULT_STALE_DAYS = 7
|
|
17
|
-
BRANCH = re.compile(r'feat/(\d+)-[a-z0-9][a-z0-9._-]*')
|
|
18
|
-
REFERENCE = re.compile(r'(?:\b([A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+))?#(\d+)\b')
|
|
19
|
-
ISSUE_URL = re.compile(r'github\.com/([A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+)/issues/(\d+)\b')
|
|
20
|
-
HEAD_REF = re.compile(r'refs/heads/(\S+)')
|
|
21
|
-
|
|
22
|
-
# Most severe first: the first verdict found here is the reported one.
|
|
23
|
-
STOP_VERDICTS = ('closed', 'claimed-by-other', 'contended-lost', 'orphan-claim', 'invalid-branch',
|
|
24
|
-
'unrecorded-claim', 'still-held', 'duplicate-work', 'stale-claim')
|
|
25
|
-
|
|
26
|
-
HELP = (
|
|
27
|
-
'Usage: python3 -I -B scripts/check-issue-claim.py --phase check|verify|release|status\n'
|
|
28
|
-
' --issue-json <file> gh api repos/<o>/<r>/issues/<n> (or gh issue view <n> --json ...)\n'
|
|
29
|
-
' --pulls-json <file> gh api --paginate --slurp "repos/<o>/<r>/pulls?state=open&per_page=100"\n'
|
|
30
|
-
' --branches <file> git ls-remote --heads <remote> "feat/<n>-*"\n'
|
|
31
|
-
' --events-json <file> gh api --paginate --slurp repos/<o>/<r>/issues/<n>/events (verify)\n'
|
|
32
|
-
' --claimant <login> GitHub login of the person (check, verify, release)\n'
|
|
33
|
-
' --branch <feat/<n>-<slug>> the branch this delivery will use (check, verify)\n'
|
|
34
|
-
' [--repo <owner/repo>] [--label status:in-progress] [--stale-days 7] [--now <ISO-8601>]\n'
|
|
35
|
-
'Exit 0: proceed (free, claimed-by-you, released, claimed, unclaimed); 1: stop; 2: unusable.'
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class Unusable(Exception):
|
|
40
|
-
"""The inputs cannot be evaluated (rule CL1)."""
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def _write_out(text):
|
|
44
|
-
sys.stdout.buffer.write((text + '\n').encode('utf-8', 'surrogateescape'))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def _fold(value):
|
|
48
|
-
return value.casefold() if isinstance(value, str) else ''
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _login(value):
|
|
52
|
-
if isinstance(value, dict):
|
|
53
|
-
value = value.get('login')
|
|
54
|
-
return value if isinstance(value, str) and value.strip() else None
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _flatten(value):
|
|
58
|
-
if isinstance(value, list) and all(isinstance(item, list) for item in value):
|
|
59
|
-
return [item for page in value for item in page]
|
|
60
|
-
return value
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _time(value):
|
|
64
|
-
if not isinstance(value, str):
|
|
65
|
-
return None
|
|
66
|
-
try:
|
|
67
|
-
parsed = datetime.fromisoformat(value.strip().replace('Z', '+00:00'))
|
|
68
|
-
except ValueError:
|
|
69
|
-
return None
|
|
70
|
-
return parsed if parsed.tzinfo else parsed.replace(tzinfo=timezone.utc)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def _read(path, label):
|
|
74
|
-
try:
|
|
75
|
-
with open(path, encoding='utf-8') as handle:
|
|
76
|
-
return handle.read()
|
|
77
|
-
except OSError:
|
|
78
|
-
raise Unusable(label + ' cannot be read.')
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _load_json(path, label):
|
|
82
|
-
try:
|
|
83
|
-
return json.loads(_read(path, label))
|
|
84
|
-
except ValueError:
|
|
85
|
-
raise Unusable(label + ' is not valid JSON.')
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def load_issue(path):
|
|
89
|
-
raw = _load_json(path, 'Issue JSON')
|
|
90
|
-
if not isinstance(raw, dict) or not isinstance(raw.get('state'), str):
|
|
91
|
-
raise Unusable('Issue JSON needs a state.')
|
|
92
|
-
number = raw.get('number')
|
|
93
|
-
if not isinstance(number, int):
|
|
94
|
-
raise Unusable('Issue JSON needs a numeric number.')
|
|
95
|
-
labels = []
|
|
96
|
-
for label in raw.get('labels') or []:
|
|
97
|
-
name = label.get('name') if isinstance(label, dict) else label
|
|
98
|
-
if isinstance(name, str):
|
|
99
|
-
labels.append(name)
|
|
100
|
-
return {
|
|
101
|
-
'number': number,
|
|
102
|
-
'author': _login(raw.get('user')) or _login(raw.get('author')),
|
|
103
|
-
'open': raw['state'].lower() == 'open',
|
|
104
|
-
'assignees': [login for login in map(_login, raw.get('assignees') or []) if login],
|
|
105
|
-
'labels': labels,
|
|
106
|
-
'updated': _time(raw.get('updated_at') or raw.get('updatedAt')),
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def load_pulls(path):
|
|
111
|
-
raw = _flatten(_load_json(path, 'Pull request JSON'))
|
|
112
|
-
if not isinstance(raw, list):
|
|
113
|
-
raise Unusable('Pull request JSON must be an array.')
|
|
114
|
-
pulls = []
|
|
115
|
-
for item in raw:
|
|
116
|
-
if not isinstance(item, dict):
|
|
117
|
-
continue
|
|
118
|
-
head = item.get('head')
|
|
119
|
-
pulls.append({
|
|
120
|
-
'number': item.get('number'),
|
|
121
|
-
'author': _login(item.get('user')) or _login(item.get('author')),
|
|
122
|
-
'head': (head.get('ref') if isinstance(head, dict) else None) or item.get('headRefName') or '',
|
|
123
|
-
'text': (item.get('title') or '') + '\n' + (item.get('body') or ''),
|
|
124
|
-
})
|
|
125
|
-
return pulls
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def load_branches(path):
|
|
129
|
-
names = []
|
|
130
|
-
for line in _read(path, 'Branch list').splitlines():
|
|
131
|
-
match = HEAD_REF.search(line)
|
|
132
|
-
name = match.group(1) if match else line.strip()
|
|
133
|
-
if name:
|
|
134
|
-
names.append(name)
|
|
135
|
-
return names
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def load_events(path):
|
|
139
|
-
raw = _flatten(_load_json(path, 'Issue events JSON'))
|
|
140
|
-
if not isinstance(raw, list):
|
|
141
|
-
raise Unusable('Issue events JSON must be an array.')
|
|
142
|
-
return [item for item in raw if isinstance(item, dict)]
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def mentions(text, number, repo):
|
|
146
|
-
for match in list(REFERENCE.finditer(text)) + list(ISSUE_URL.finditer(text)):
|
|
147
|
-
if int(match.group(2)) != number:
|
|
148
|
-
continue
|
|
149
|
-
if match.group(1) is None or repo is None or _fold(match.group(1)) == _fold(repo):
|
|
150
|
-
return True
|
|
151
|
-
return False
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
def issue_branch(name, number):
|
|
155
|
-
match = BRANCH.fullmatch(name or '')
|
|
156
|
-
return match is not None and int(match.group(1)) == number
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def current_assignments(events):
|
|
160
|
-
"""Login (folded) -> time of the assignment that is still in effect."""
|
|
161
|
-
timed = [(_time(e.get('created_at') or e.get('createdAt')), e) for e in events
|
|
162
|
-
if e.get('event') in ('assigned', 'unassigned')]
|
|
163
|
-
timed = sorted((pair for pair in timed if pair[0] is not None), key=lambda pair: pair[0])
|
|
164
|
-
since = {}
|
|
165
|
-
for at, event in timed:
|
|
166
|
-
who = _fold(_login(event.get('assignee')))
|
|
167
|
-
if event['event'] == 'assigned':
|
|
168
|
-
since[who] = at
|
|
169
|
-
else:
|
|
170
|
-
since.pop(who, None)
|
|
171
|
-
return since
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def label_setter(events, label):
|
|
175
|
-
"""(login folded, time) of whoever set the claim label still in effect, or None."""
|
|
176
|
-
timed = [(_time(e.get('created_at') or e.get('createdAt')), e) for e in events
|
|
177
|
-
if e.get('event') in ('labeled', 'unlabeled') and isinstance(e.get('label'), dict)
|
|
178
|
-
and e['label'].get('name') == label]
|
|
179
|
-
setter = None
|
|
180
|
-
for at, event in sorted((pair for pair in timed if pair[0] is not None), key=lambda pair: pair[0]):
|
|
181
|
-
setter = (_fold(_login(event.get('actor'))), at) if event['event'] == 'labeled' else None
|
|
182
|
-
return setter
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def claim_times(issue, events, label):
|
|
186
|
-
"""Login (folded) -> when each assignee's claim took effect; None for a reporter who is not claiming.
|
|
187
|
-
|
|
188
|
-
The issue author's assignment (issue-reviewer triage) becomes a claim only once the author
|
|
189
|
-
set the claim label, and dates from that moment.
|
|
190
|
-
"""
|
|
191
|
-
since = current_assignments(events)
|
|
192
|
-
missing = [login for login in issue['assignees'] if _fold(login) not in since]
|
|
193
|
-
if missing:
|
|
194
|
-
raise Unusable('No assignment event for: ' + ', '.join(missing) + '.')
|
|
195
|
-
setter = label_setter(events, label)
|
|
196
|
-
times = {}
|
|
197
|
-
for login in issue['assignees']:
|
|
198
|
-
who = _fold(login)
|
|
199
|
-
if who != _fold(issue['author']):
|
|
200
|
-
times[who] = since[who]
|
|
201
|
-
elif setter is not None and setter[0] == who:
|
|
202
|
-
times[who] = max(since[who], setter[1])
|
|
203
|
-
else:
|
|
204
|
-
times[who] = None
|
|
205
|
-
return times
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
class Report:
|
|
209
|
-
def __init__(self):
|
|
210
|
-
self.findings = []
|
|
211
|
-
|
|
212
|
-
def add(self, rule, verdict, detail, who=None):
|
|
213
|
-
finding = {'rule': rule, 'verdict': verdict, 'detail': detail}
|
|
214
|
-
if who:
|
|
215
|
-
finding['who'] = who
|
|
216
|
-
self.findings.append(finding)
|
|
217
|
-
|
|
218
|
-
def verdict(self, default):
|
|
219
|
-
found = {finding['verdict'] for finding in self.findings}
|
|
220
|
-
return next((verdict for verdict in STOP_VERDICTS if verdict in found), default)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def evaluate(phase, issue, pulls, branches, events, options):
|
|
224
|
-
report = Report()
|
|
225
|
-
number, label = issue['number'], options['label']
|
|
226
|
-
me = _fold(options['claimant'])
|
|
227
|
-
has_label = label in issue['labels']
|
|
228
|
-
others = [login for login in issue['assignees'] if _fold(login) != me]
|
|
229
|
-
mine = len(others) < len(issue['assignees'])
|
|
230
|
-
reporter = _fold(issue['author'])
|
|
231
|
-
# Without the claim label, the author's own assignment comes from triage and holds nothing.
|
|
232
|
-
claimers = [login for login in others if _fold(login) != reporter] or (others if has_label else [])
|
|
233
|
-
holding = [login for login in issue['assignees'] if _fold(login) != reporter] or (
|
|
234
|
-
issue['assignees'] if has_label else [])
|
|
235
|
-
linked = [pull for pull in pulls if mentions(pull['text'], number, options['repo']) or issue_branch(pull['head'], number)]
|
|
236
|
-
other_pulls = [pull for pull in linked if _fold(pull['author']) != me]
|
|
237
|
-
claim_branches = [name for name in branches if issue_branch(name, number)]
|
|
238
|
-
holders = {'assignees': issue['assignees'], 'reporter': issue['author'], 'label': has_label,
|
|
239
|
-
'pulls': [{'number': p['number'], 'author': p['author']} for p in linked], 'branches': claim_branches}
|
|
240
|
-
|
|
241
|
-
if phase == 'release':
|
|
242
|
-
if mine:
|
|
243
|
-
report.add('CL10', 'still-held', 'The claimant is still assigned.')
|
|
244
|
-
kept = [login for login in others if _fold(login) != reporter]
|
|
245
|
-
if has_label and not kept and others:
|
|
246
|
-
if events is None:
|
|
247
|
-
raise Unusable('The issue author is still assigned: --events-json is needed to tell '
|
|
248
|
-
'whether the claim label is theirs.')
|
|
249
|
-
times = claim_times(issue, events, label)
|
|
250
|
-
kept = [login for login in others if times[_fold(login)] is not None]
|
|
251
|
-
if has_label and not kept:
|
|
252
|
-
report.add('CL10', 'still-held', 'The claim label is still set and no one else holds the issue.')
|
|
253
|
-
return report.verdict('released'), report, holders
|
|
254
|
-
|
|
255
|
-
if phase == 'status':
|
|
256
|
-
if len(linked) > 1:
|
|
257
|
-
report.add('CL11', 'duplicate-work', 'More than one open pull request works on this issue.',
|
|
258
|
-
['#' + str(p['number']) for p in linked])
|
|
259
|
-
if has_label and not issue['assignees']:
|
|
260
|
-
report.add('CL6', 'orphan-claim', 'The claim label is set but nobody is assigned.')
|
|
261
|
-
held = bool(holding) or has_label
|
|
262
|
-
if held and not linked and not claim_branches:
|
|
263
|
-
if issue['updated'] is None:
|
|
264
|
-
raise Unusable('Issue JSON needs updated_at to judge a stale claim.')
|
|
265
|
-
if options['now'] - issue['updated'] > timedelta(days=options['stale_days']):
|
|
266
|
-
report.add('CL12', 'stale-claim', 'Claimed with no open pull request, no feat/<n>- branch and no '
|
|
267
|
-
'activity for more than ' + str(options['stale_days']) + ' days.', holding)
|
|
268
|
-
claimed = held or bool(linked) or bool(claim_branches)
|
|
269
|
-
return report.verdict('claimed' if claimed else 'unclaimed'), report, holders
|
|
270
|
-
|
|
271
|
-
branch = options['branch']
|
|
272
|
-
if not issue_branch(branch, number):
|
|
273
|
-
report.add('CL7', 'invalid-branch', 'The delivery branch must be feat/' + str(number) + '-<slug>.')
|
|
274
|
-
if not issue['open']:
|
|
275
|
-
report.add('CL2', 'closed', 'The issue is closed; reopen it through issue-dedup before claiming.')
|
|
276
|
-
if other_pulls:
|
|
277
|
-
report.add('CL4', 'claimed-by-other', 'An open pull request by someone else works on this issue.',
|
|
278
|
-
['#' + str(p['number']) + ' @' + str(p['author']) for p in other_pulls])
|
|
279
|
-
foreign = [name for name in claim_branches if name != branch]
|
|
280
|
-
if foreign:
|
|
281
|
-
report.add('CL5', 'claimed-by-other', 'Another feat/' + str(number) + '- branch exists on the remote.', foreign)
|
|
282
|
-
|
|
283
|
-
if phase == 'check':
|
|
284
|
-
if claimers:
|
|
285
|
-
report.add('CL3', 'claimed-by-other', 'The issue is assigned to someone else.', claimers)
|
|
286
|
-
if has_label and not issue['assignees']:
|
|
287
|
-
report.add('CL6', 'orphan-claim', 'The claim label is set but nobody is assigned.')
|
|
288
|
-
yours = mine or any(_fold(p['author']) == me for p in linked)
|
|
289
|
-
return report.verdict('claimed-by-you' if yours else 'free'), report, holders
|
|
290
|
-
|
|
291
|
-
if not mine or not has_label:
|
|
292
|
-
report.add('CL8', 'unrecorded-claim', 'After claiming, the claimant must be assigned and the label set.')
|
|
293
|
-
if mine and others:
|
|
294
|
-
if events is None:
|
|
295
|
-
raise Unusable('Several assignees: --events-json is needed to order the assignments.')
|
|
296
|
-
times = claim_times(issue, events, label)
|
|
297
|
-
claiming = [login for login in issue['assignees'] if times[_fold(login)] is not None]
|
|
298
|
-
winner = min(claiming, key=lambda login: (times[_fold(login)], _fold(login))) if claiming else None
|
|
299
|
-
if _fold(winner) != me:
|
|
300
|
-
report.add('CL9', 'contended-lost', 'Someone else was assigned first; unassign yourself and remove nothing else.',
|
|
301
|
-
[winner])
|
|
302
|
-
return report.verdict('claimed-by-you'), report, holders
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def parse_args(argv):
|
|
306
|
-
options = {'phase': None, 'issue': None, 'pulls': None, 'branches': None, 'events': None, 'claimant': None,
|
|
307
|
-
'branch': None, 'repo': None, 'label': DEFAULT_LABEL, 'stale_days': DEFAULT_STALE_DAYS, 'now': None}
|
|
308
|
-
keys = {'--phase': 'phase', '--issue-json': 'issue', '--pulls-json': 'pulls', '--branches': 'branches',
|
|
309
|
-
'--events-json': 'events', '--claimant': 'claimant', '--branch': 'branch', '--repo': 'repo',
|
|
310
|
-
'--label': 'label', '--stale-days': 'stale_days', '--now': 'now'}
|
|
311
|
-
args = list(argv)
|
|
312
|
-
while args:
|
|
313
|
-
arg = args.pop(0)
|
|
314
|
-
if arg in ('-h', '--help'):
|
|
315
|
-
return None
|
|
316
|
-
if arg not in keys or not args:
|
|
317
|
-
raise Unusable('Unexpected argument ' + arg + '; see --help.')
|
|
318
|
-
options[keys[arg]] = args.pop(0)
|
|
319
|
-
if options['phase'] not in PHASES:
|
|
320
|
-
raise Unusable('--phase must be one of: ' + ', '.join(PHASES) + '.')
|
|
321
|
-
if options['issue'] is None:
|
|
322
|
-
raise Unusable('--issue-json is required.')
|
|
323
|
-
if options['phase'] != 'release' and (options['pulls'] is None or options['branches'] is None):
|
|
324
|
-
raise Unusable('--pulls-json and --branches are required for ' + options['phase'] + '.')
|
|
325
|
-
if options['phase'] != 'status' and not options['claimant']:
|
|
326
|
-
raise Unusable('--claimant is required for ' + options['phase'] + '.')
|
|
327
|
-
if options['phase'] in ('check', 'verify') and not options['branch']:
|
|
328
|
-
raise Unusable('--branch is required for ' + options['phase'] + '.')
|
|
329
|
-
try:
|
|
330
|
-
options['stale_days'] = int(options['stale_days'])
|
|
331
|
-
except ValueError:
|
|
332
|
-
raise Unusable('--stale-days must be an integer.')
|
|
333
|
-
now = _time(options['now']) if options['now'] else datetime.now(timezone.utc)
|
|
334
|
-
if now is None:
|
|
335
|
-
raise Unusable('--now must be an ISO-8601 time.')
|
|
336
|
-
options['now'] = now
|
|
337
|
-
return options
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
def main(argv):
|
|
341
|
-
try:
|
|
342
|
-
options = parse_args(argv)
|
|
343
|
-
if options is None:
|
|
344
|
-
_write_out(HELP)
|
|
345
|
-
return 0
|
|
346
|
-
phase = options['phase']
|
|
347
|
-
issue = load_issue(options['issue'])
|
|
348
|
-
pulls = load_pulls(options['pulls']) if options['pulls'] else []
|
|
349
|
-
branches = load_branches(options['branches']) if options['branches'] else []
|
|
350
|
-
events = load_events(options['events']) if options['events'] else None
|
|
351
|
-
verdict, report, holders = evaluate(phase, issue, pulls, branches, events, options)
|
|
352
|
-
except Unusable as error:
|
|
353
|
-
_write_out(json.dumps({'verdict': 'unusable', 'proceed': False,
|
|
354
|
-
'findings': [{'rule': 'CL1', 'verdict': 'unusable', 'detail': str(error)}]}, indent=2))
|
|
355
|
-
return 2
|
|
356
|
-
proceed = verdict not in STOP_VERDICTS
|
|
357
|
-
_write_out(json.dumps({'verdict': verdict, 'proceed': proceed, 'phase': phase, 'issue': issue['number'],
|
|
358
|
-
'claimant': options['claimant'], 'holders': holders, 'findings': report.findings}, indent=2))
|
|
359
|
-
return 0 if proceed else 1
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if __name__ == '__main__':
|
|
363
|
-
sys.exit(main(sys.argv[1:]))
|