@soleur/opencode 3.378.17 → 3.379.0
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/package.json +1 -1
- package/skills/community/test/community-argv.test.sh +1 -1
- package/skills/eval-harness/README.md +1 -1
- package/skills/launch-check/SKILL.md +66 -11
- package/skills/launch-check/references/issue-body.template +13 -0
- package/skills/launch-check/references/phrases.txt +48 -0
- package/skills/launch-check/scripts/launch-check.sh +81 -12
- package/skills/launch-check/scripts/lib/common.sh +10 -0
- package/skills/launch-check/scripts/lib/issues.sh +908 -0
- package/skills/launch-check/scripts/lib/redact-gate.sh +9 -2
- package/skills/launch-check/scripts/lib/render.sh +31 -10
- package/skills/launch-check/test/fixtures/plan-sample/epic.md +12 -0
- package/skills/launch-check/test/fixtures/plan-sample/issues/CI-01.md +13 -0
- package/skills/launch-check/test/fixtures/plan-sample/plan.tsv +8 -0
- package/skills/launch-check/test/gh-stub.sh +392 -0
- package/skills/launch-check/test/issues-common.sh +182 -0
- package/skills/launch-check/test/issues-guards.test.sh +688 -0
- package/skills/launch-check/test/issues-resume.test.sh +348 -0
- package/skills/launch-check/test/lib.sh +4 -1
- package/skills/launch-check/test/redact-gate.test.sh +18 -1
- package/skills/launch-check/test/render.test.sh +2 -0
- package/skills/launch-check/test/wording.test.sh +23 -1
- package/skills/plan/references/plan-sharp-edges.md +2 -0
|
@@ -0,0 +1,908 @@
|
|
|
1
|
+
# shellcheck shell=bash
|
|
2
|
+
# The issue writer: the only part of launch-check that writes to a customer's tracker, and only from a saved plan.
|
|
3
|
+
# Contract with launch-check.sh: TARGET, WORK, FACTS, JUDGED, LC_DRY, REPORT_REL, SKILL_DIR and the ISSUES_* option variables
|
|
4
|
+
# are set by cmd_issues. Sourced; never executed. Bash 3.2 safe (no associative arrays, no mapfile).
|
|
5
|
+
#
|
|
6
|
+
# Four guards (ADR-314, amendment 2026-11-03; pinned by test/issues-guards.test.sh and test/issues-resume.test.sh):
|
|
7
|
+
# 1 saved-plan-only writes lc__gh_exec is the only place the CLI is invoked; lc_gh_read always sends -X GET; lc_gh_write
|
|
8
|
+
# is a closed allowlist (headless, dry-run, four REST shapes, field keys, confined @file operands).
|
|
9
|
+
# 2 authored bytes are scanned bytes every title, body, label and epic section passes lc_emit_checked (scan-only) on the exact
|
|
10
|
+
# bytes that are sent; bodies are regenerated from catalog, facts and ids and byte-compared to the plan.
|
|
11
|
+
# 3 idempotency and resume the live identity is the scope label plus the body marker, read through one paginated listing.
|
|
12
|
+
# 4 epic edits are confined to the marked section (lc_epic_splice).
|
|
13
|
+
# Nothing here prints raw CLI stderr or tracker text: failures are mapped to a closed detail= token set, and every printed
|
|
14
|
+
# line passes lc_scrub. Markers are emitted from this file on purpose (outside the telemetry drift guard's walk).
|
|
15
|
+
|
|
16
|
+
ISSUES_RE_SLUG='^[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*$'
|
|
17
|
+
ISSUES_RE_ID='^[A-Z]+-[A-Za-z0-9-]+$'
|
|
18
|
+
ISSUES_RE_TITLE="^[A-Za-z0-9 .,:;()'/+_-]+\$"
|
|
19
|
+
ISSUES_CAP=30
|
|
20
|
+
LC_TAB=$(printf '\t')
|
|
21
|
+
ISSUES_MAX_BYTES=65536
|
|
22
|
+
LC_WRITES_DONE=0
|
|
23
|
+
LC_GH_HTTP=""; LC_GH_KIND=ok
|
|
24
|
+
|
|
25
|
+
lc__say() { printf '%s\n' "$(lc_scrub "$*")"; }
|
|
26
|
+
# lc__fmt <phrase-key> [values...]: a shipped phrase with its %s slots filled, as one scrubbed line.
|
|
27
|
+
lc__fmt() {
|
|
28
|
+
local f; f=$(lc_phrase "$1"); shift
|
|
29
|
+
# shellcheck disable=SC2059 # the format is our own shipped phrase, never repository content
|
|
30
|
+
lc__say "$(printf -- "$f" "$@")"
|
|
31
|
+
}
|
|
32
|
+
# lc__re <ERE> <value>: the whole one-line value matches (awk, so the same grammar on every platform).
|
|
33
|
+
lc__re() { RE_X=$1 awk '{ if (NR == 1 && $0 ~ ENVIRON["RE_X"]) ok = 1; n = NR } END { exit !(ok && n == 1) }' <<<"$2"; }
|
|
34
|
+
lc__refuse() { lc_abort write-shape-refused 2 "detail=$1"; }
|
|
35
|
+
lc__pbad() { lc_abort plan-invalid 2 "detail=$1"; }
|
|
36
|
+
lc__stale() { lc__fmt report_stale_fix; lc_abort report-stale 2 "detail=$1"; }
|
|
37
|
+
lc__lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
|
|
38
|
+
lc__same_slug() { [ "$(lc__lower "$1")" = "$(lc__lower "$2")" ]; }
|
|
39
|
+
|
|
40
|
+
# ---------------------------------------------------------------- Guard 1: the gh wrappers
|
|
41
|
+
# lc__gh_exec <args...>: the ONLY place the GitHub CLI is invoked. Environment scrubbed (a repository's shell profile cannot
|
|
42
|
+
# redirect the call), a neutral working directory (except for the two verbs that resolve the repository from its remotes),
|
|
43
|
+
# stderr captured and classified, never printed. Sets LC_GH_HTTP and LC_GH_KIND (ok | rate-limit | http-NNN | failed);
|
|
44
|
+
# stdout lands in $WORK/gh.out.
|
|
45
|
+
lc__gh_exec() {
|
|
46
|
+
local cwd=$WORK rc=0 bound="" err="$WORK/gh.err"
|
|
47
|
+
local -a scrub=(-u GH_REPO -u GH_ENTERPRISE_TOKEN -u GITHUB_ENTERPRISE_TOKEN -u GH_DEBUG -u DEBUG -u GH_CONFIG_DIR -u GH_PATH -u GH_FORCE_TTY -u SSL_CERT_FILE -u SSL_CERT_DIR
|
|
48
|
+
-u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u NO_PROXY -u http_proxy -u https_proxy -u all_proxy -u no_proxy)
|
|
49
|
+
case "${1:-}" in auth|repo) cwd=$TARGET ;; esac
|
|
50
|
+
# Both enterprise tokens are scrubbed on every host (fail closed): a token from the environment must not steer the call, and a
|
|
51
|
+
# GitHub Enterprise Server user relies on the login gh stores for the host --host names.
|
|
52
|
+
if command -v timeout >/dev/null 2>&1; then bound="timeout 120"; elif command -v gtimeout >/dev/null 2>&1; then bound="gtimeout 120"; fi
|
|
53
|
+
: > "$WORK/gh.out"; : > "$err"
|
|
54
|
+
# GH_HOST is always the target host (github.com included), so an inherited value or a remote on another host cannot redirect the call.
|
|
55
|
+
# shellcheck disable=SC2086 # $bound is deliberately split into command and argument
|
|
56
|
+
( cd "$cwd" && exec $bound env "${scrub[@]}" \
|
|
57
|
+
GH_HOST="${ISSUES_HOST:-github.com}" GH_PROMPT_DISABLED=1 NO_COLOR=1 GH_NO_UPDATE_NOTIFIER=1 \
|
|
58
|
+
gh "$@" ) > "$WORK/gh.out" 2> "$err" < /dev/null || rc=$?
|
|
59
|
+
LC_GH_HTTP=""; LC_GH_KIND=ok
|
|
60
|
+
if [ "$rc" -ne 0 ]; then
|
|
61
|
+
LC_GH_HTTP=$(grep -o 'HTTP [0-9][0-9][0-9]' "$err" | tail -n 1 | cut -c6-)
|
|
62
|
+
if grep -qi 'rate limit' "$err"; then LC_GH_KIND=rate-limit
|
|
63
|
+
elif [ -n "$LC_GH_HTTP" ]; then LC_GH_KIND="http-$LC_GH_HTTP"
|
|
64
|
+
else LC_GH_KIND=failed; fi
|
|
65
|
+
fi
|
|
66
|
+
return "$rc"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# lc_gh_read <auth status|repo view|api> ...: a read. `auth` takes only `status` and `repo` only `view`, each with nothing but the flags
|
|
70
|
+
# callers use (a flag outside the shape, such as --show-token, --web, --input, -H or --hostname, is refused). For `api` the method is
|
|
71
|
+
# always sent as -X GET (a field flag would otherwise flip the call to POST); any other method is refused.
|
|
72
|
+
lc__rflag() { lc_abort write-shape-refused 2 "detail=read-flag"; }
|
|
73
|
+
lc_gh_read() {
|
|
74
|
+
case "${1:-}" in
|
|
75
|
+
auth) [ "${2:-}" = status ] || lc_abort write-shape-refused 2 "detail=read-verb"; [ $# -eq 2 ] || lc__rflag; lc__gh_exec "$@"; return $? ;;
|
|
76
|
+
repo) [ "${2:-}" = view ] || lc_abort write-shape-refused 2 "detail=read-verb"
|
|
77
|
+
local -a all=("$@"); shift 2
|
|
78
|
+
while [ $# -gt 0 ]; do
|
|
79
|
+
case "$1" in --json|--jq) [ $# -ge 2 ] || lc__rflag; shift 2 ;; *) lc__rflag ;; esac
|
|
80
|
+
done
|
|
81
|
+
lc__gh_exec "${all[@]}"; return $? ;;
|
|
82
|
+
api) shift ;;
|
|
83
|
+
*) lc_abort write-shape-refused 2 "detail=read-verb" ;;
|
|
84
|
+
esac
|
|
85
|
+
local -a rest=()
|
|
86
|
+
while [ $# -gt 0 ]; do
|
|
87
|
+
case "$1" in
|
|
88
|
+
-X|--method) [ "${2:-}" = GET ] || lc_abort write-shape-refused 2 "detail=read-not-get"; shift 2 ;;
|
|
89
|
+
-X*|--method=*) lc_abort write-shape-refused 2 "detail=read-not-get" ;;
|
|
90
|
+
graphql|*/graphql) lc_abort write-shape-refused 2 "detail=read-graphql" ;;
|
|
91
|
+
-f|--jq) [ $# -ge 2 ] || lc__rflag; rest+=("$1" "$2"); shift 2 ;;
|
|
92
|
+
--paginate) rest+=("$1"); shift ;;
|
|
93
|
+
-*) lc__rflag ;;
|
|
94
|
+
*) rest+=("$1"); shift ;;
|
|
95
|
+
esac
|
|
96
|
+
done
|
|
97
|
+
lc__gh_exec api -X GET ${rest[@]+"${rest[@]}"}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# lc__file_ok <path>: a regular file, not a symlink, whose physical location is inside the validated plan copy or the tool's own
|
|
101
|
+
# scratch directory for epic bodies.
|
|
102
|
+
lc__file_ok() {
|
|
103
|
+
local p=$1 d b real root r
|
|
104
|
+
[ -f "$p" ] && [ ! -L "$p" ] || return 1
|
|
105
|
+
d=$(cd "$(dirname "$p")" 2>/dev/null && pwd -P) || return 1
|
|
106
|
+
b=$(basename "$p"); real="$d/$b"
|
|
107
|
+
for root in "${ISSUES_PLAN_DIR:-}" "${WORK:+$WORK/out}"; do
|
|
108
|
+
[ -n "$root" ] || continue
|
|
109
|
+
r=$(cd "$root" 2>/dev/null && pwd -P) || continue
|
|
110
|
+
case "$real" in "$r"/*) return 0 ;; esac
|
|
111
|
+
done
|
|
112
|
+
return 1
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
# lc__write_shape <args as given to lc_gh_write>: abort write-shape-refused unless the call is one of the four allowlisted forms.
|
|
116
|
+
lc__write_shape() {
|
|
117
|
+
local method path slug="${ISSUES_REPO:-}" shape="" n key val flag kv allowed=""
|
|
118
|
+
[ "$#" -ge 4 ] && [ "$1" = api ] && [ "$2" = -X ] || lc__refuse not-api
|
|
119
|
+
method=$3; path=$4; shift 4
|
|
120
|
+
[ -n "$slug" ] && lc__re "$ISSUES_RE_SLUG" "$slug" || lc__refuse no-repo
|
|
121
|
+
case "$method $path" in
|
|
122
|
+
"POST repos/$slug/labels") shape="labels"; allowed=" name color description " ;;
|
|
123
|
+
"POST repos/$slug/issues") shape="issue"; allowed=" title body labels[] " ;;
|
|
124
|
+
"POST repos/$slug/issues/"*"/sub_issues") shape="sub"; allowed=" sub_issue_id "
|
|
125
|
+
n=${path#"repos/$slug/issues/"}; n=${n%/sub_issues} ;;
|
|
126
|
+
"PATCH repos/$slug/issues/"*) shape="patch"; allowed=" body "; n=${path#"repos/$slug/issues/"} ;;
|
|
127
|
+
*) lc__refuse shape ;;
|
|
128
|
+
esac
|
|
129
|
+
if [ "$shape" = sub ] || [ "$shape" = patch ]; then
|
|
130
|
+
case "$n" in ''|*[!0-9]*) lc__refuse issue-number ;; esac
|
|
131
|
+
# The target is bound to the epic this run found or created: a PATCH or a link under any other issue is not a form we send.
|
|
132
|
+
[ -n "${EPIC_NUM:-}" ] && [ "$n" = "$EPIC_NUM" ] || lc__refuse epic-bind
|
|
133
|
+
fi
|
|
134
|
+
while [ $# -gt 0 ]; do
|
|
135
|
+
case "$1" in
|
|
136
|
+
-f|-F)
|
|
137
|
+
[ $# -ge 2 ] || lc__refuse flag-value
|
|
138
|
+
flag=$1; kv=$2
|
|
139
|
+
case "$kv" in *=*) ;; *) lc__refuse field-form ;; esac
|
|
140
|
+
key=${kv%%=*}; val=${kv#*=}
|
|
141
|
+
# Whole-word match: a key holding a space ("title body") would otherwise be a substring of the allowed list.
|
|
142
|
+
case "$key" in ''|*[[:space:]]*) lc__refuse field-key ;; esac
|
|
143
|
+
case "$allowed" in *" $key "*) ;; *) lc__refuse field-key ;; esac
|
|
144
|
+
# Every label this tool names, on a label create or on an issue, is one of its own lc: labels.
|
|
145
|
+
case "$key" in name|'labels[]') case "$val" in lc:?*) ;; *) lc__refuse label-name ;; esac ;; esac
|
|
146
|
+
if [ "$flag" = -F ]; then
|
|
147
|
+
case "$key" in
|
|
148
|
+
body) case "$val" in @*) lc__file_ok "${val#@}" || lc__refuse file-operand ;; *) lc__refuse typed-field ;; esac ;;
|
|
149
|
+
sub_issue_id) case "$val" in ''|*[!0-9]*) lc__refuse sub-issue-id ;; esac ;;
|
|
150
|
+
*) lc__refuse typed-field ;;
|
|
151
|
+
esac
|
|
152
|
+
else
|
|
153
|
+
case "$key" in body|sub_issue_id) lc__refuse raw-field ;; esac
|
|
154
|
+
fi
|
|
155
|
+
shift 2 ;;
|
|
156
|
+
--jq) [ $# -ge 2 ] || lc__refuse flag-value; shift 2 ;;
|
|
157
|
+
*) lc__refuse flag ;;
|
|
158
|
+
esac
|
|
159
|
+
done
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
lc__pause() {
|
|
163
|
+
local p
|
|
164
|
+
[ "${LC_WRITES_DONE:-0}" -gt 0 ] || return 0
|
|
165
|
+
p=$(lc_seam LAUNCH_CHECK_PAUSE 1)
|
|
166
|
+
case "$p" in ''|*[!0-9]*) p=1 ;; esac
|
|
167
|
+
[ "$p" = 0 ] || sleep "$p"
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
# lc_gh_write api -X <POST|PATCH> <path> [-f k=v | -F k=v | --jq expr]...: a tracker write. The only caller-visible way to write.
|
|
171
|
+
lc_gh_write() {
|
|
172
|
+
if lc_is_headless; then lc_abort headless-write-refused 2 "detail=headless"; fi
|
|
173
|
+
lc__write_shape "$@"
|
|
174
|
+
[ "${LC_DRY:-0}" = 1 ] && return 0
|
|
175
|
+
lc__pause
|
|
176
|
+
local rc=0
|
|
177
|
+
# counted before the call: a write that was in flight when a signal arrived may have reached the tracker
|
|
178
|
+
LC_WRITES_DONE=$((LC_WRITES_DONE + 1))
|
|
179
|
+
lc__gh_exec "$@" || rc=$?
|
|
180
|
+
return "$rc"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# ---------------------------------------------------------------- preflight
|
|
184
|
+
# lc_issues_preflight: sets ISSUES_REASON (empty when ready), ISSUES_RESOLVED, ISSUES_VIS, ISSUES_FORK, and ISSUES_REPO on success.
|
|
185
|
+
lc_issues_preflight() {
|
|
186
|
+
local line v a i p
|
|
187
|
+
ISSUES_REASON=""; ISSUES_RESOLVED=""; ISSUES_VIS=UNKNOWN; ISSUES_FORK=false
|
|
188
|
+
command -v gh >/dev/null 2>&1 || { ISSUES_REASON=gh-missing; return 1; }
|
|
189
|
+
lc_gh_read auth status || { ISSUES_REASON=gh-unauthenticated; return 1; }
|
|
190
|
+
lc_gh_read repo view --json nameWithOwner,isFork --jq '[.nameWithOwner, .isFork] | @tsv' || { ISSUES_REASON=repo-unresolved; return 1; }
|
|
191
|
+
line=$(awk 'NR == 1 { print; exit }' "$WORK/gh.out")
|
|
192
|
+
ISSUES_RESOLVED=$(cut -f1 <<<"$line")
|
|
193
|
+
ISSUES_FORK=$(cut -f2 <<<"$line")
|
|
194
|
+
lc__re "$ISSUES_RE_SLUG" "$ISSUES_RESOLVED" || { ISSUES_REASON=repo-unresolved; return 1; }
|
|
195
|
+
case "$ISSUES_FORK" in true|false) ;; *) ISSUES_FORK=false ;; esac
|
|
196
|
+
lc_gh_read api "repos/$ISSUES_RESOLVED" --jq '[.visibility, (.archived // false), (.has_issues // false), (.permissions.push // false)] | @tsv' \
|
|
197
|
+
|| { ISSUES_REASON=repo-unresolved; return 1; }
|
|
198
|
+
line=$(awk 'NR == 1 { print; exit }' "$WORK/gh.out")
|
|
199
|
+
v=$(cut -f1 <<<"$line"); a=$(cut -f2 <<<"$line"); i=$(cut -f3 <<<"$line"); p=$(cut -f4 <<<"$line")
|
|
200
|
+
case "$v" in public) ISSUES_VIS=PUBLIC ;; private) ISSUES_VIS=PRIVATE ;; internal) ISSUES_VIS=INTERNAL ;; *) ISSUES_VIS=UNKNOWN ;; esac
|
|
201
|
+
[ "$a" != true ] || { ISSUES_REASON=repo-archived; return 1; }
|
|
202
|
+
[ "$i" = true ] || { ISSUES_REASON=issues-disabled; return 1; }
|
|
203
|
+
[ "$p" = true ] || { ISSUES_REASON=no-write-permission; return 1; }
|
|
204
|
+
ISSUES_REPO=$ISSUES_RESOLVED
|
|
205
|
+
return 0
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
# The resolved repository must be the one `origin` names, and origin must be on the target host. `--repo <slug>` does not choose the
|
|
209
|
+
# target: it acknowledges the repository gh resolved (it must equal that slug) when that differs from origin, e.g. a fork that
|
|
210
|
+
# resolves to its upstream, or an origin written through an ssh alias (the owner names the repository, --confirm-repo still transcribes
|
|
211
|
+
# it). The hosts ssh.github.com and www.github.com are github.com. The only ways to change the target are `gh repo set-default` and the
|
|
212
|
+
# origin remote.
|
|
213
|
+
lc_issues_origin_check() {
|
|
214
|
+
local url slug ohost
|
|
215
|
+
url=$(git -C "$TARGET" remote get-url origin 2>/dev/null) || url=""
|
|
216
|
+
case "$url" in
|
|
217
|
+
*://*) ohost=$(printf '%s\n' "$url" | sed -e 's#^[^:/]*://##' -e 's#/.*$##' -e 's#^.*@##' -e 's#:.*$##') ;;
|
|
218
|
+
*@*:*) ohost=$(printf '%s\n' "$url" | sed -e 's#^.*@##' -e 's#:.*$##') ;;
|
|
219
|
+
*) ohost="" ;;
|
|
220
|
+
esac
|
|
221
|
+
ohost=$(lc__lower "$ohost")
|
|
222
|
+
case "$ohost" in ssh.github.com|www.github.com) ohost=github.com ;; esac
|
|
223
|
+
if [ -n "$ohost" ] && [ "$ohost" != "$(lc__lower "${ISSUES_HOST:-github.com}")" ] && [ -z "${ISSUES_REPO_ARG:-}" ]; then
|
|
224
|
+
lc__fmt origin_host_fix; lc_abort repo-unresolved 2 "detail=host-differs resolved=$ISSUES_RESOLVED"
|
|
225
|
+
fi
|
|
226
|
+
if [ -n "${ISSUES_REPO_ARG:-}" ]; then
|
|
227
|
+
lc__same_slug "$ISSUES_REPO_ARG" "$ISSUES_RESOLVED" || lc_abort repo-unresolved 2 "detail=repo-flag-differs resolved=$ISSUES_RESOLVED"
|
|
228
|
+
return 0
|
|
229
|
+
fi
|
|
230
|
+
slug=$(printf '%s\n' "$url" | sed -e 's#^.*[:/]\([^/:]*/[^/:]*\)$#\1#' -e 's#\.git$##')
|
|
231
|
+
lc__same_slug "$slug" "$ISSUES_RESOLVED" || lc_abort repo-unresolved 2 "detail=origin-differs resolved=$ISSUES_RESOLVED"
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# ---------------------------------------------------------------- Guard 3: the live identity
|
|
235
|
+
# lc_issues_live: one paginated listing of every issue that carries the scope label, kept as validated rows in $WORK/live.tsv:
|
|
236
|
+
# number, database id, state, epic-label flag, author, key (a gap id, @epic, or - for no usable marker). A marker counts only as a
|
|
237
|
+
# whole line (a customer note that quotes one mid-text is not a marker; trailing spaces, tabs and a CR are tolerated). A failed or malformed listing
|
|
238
|
+
# is never read as "none found".
|
|
239
|
+
lc_issues_live() {
|
|
240
|
+
: > "$WORK/live.tsv"
|
|
241
|
+
if ! lc_gh_read api "repos/$ISSUES_REPO/issues" -f labels=lc:launch-check -f state=all -f per_page=100 --paginate \
|
|
242
|
+
--jq '.[] | select(.pull_request == null) | . as $i | ((.body // "") | ((scan("(?m)^<!-- launch-check:(gap=[A-Z]+-[A-Za-z0-9-]+|epic) -->[ \t]*\r?$") | .[0]) // "-")) as $m | [$i.number, $i.id, $i.state, (("\t" + ([$i.labels[].name] | @tsv) + "\t") | test("\tlc:epic\t")), ($i.user.login // "-"), $m] | @tsv'; then
|
|
243
|
+
lc__incomplete lookup "$LC_GH_KIND"
|
|
244
|
+
fi
|
|
245
|
+
RE_MARK='^(gap=[A-Z]+-[A-Za-z0-9-]+|epic|-)$' RE_LOGIN='^[A-Za-z0-9][A-Za-z0-9_-]*(\[bot\])?$' \
|
|
246
|
+
awk -F'\t' -v OFS='\t' '
|
|
247
|
+
NF != 6 || $1 !~ /^[0-9]+$/ || $2 !~ /^[0-9]+$/ || ($3 != "open" && $3 != "closed") || ($4 != "true" && $4 != "false") || $6 !~ ENVIRON["RE_MARK"] { bad = 1; exit }
|
|
248
|
+
{ key = ($6 == "epic") ? "@epic" : ($6 == "-") ? "-" : substr($6, 5)
|
|
249
|
+
login = $5; if (login !~ ENVIRON["RE_LOGIN"]) login = "-"
|
|
250
|
+
print $1, $2, $3, $4, login, key }
|
|
251
|
+
END { if (bad) exit 1 }' "$WORK/gh.out" > "$WORK/live.new" || lc__incomplete lookup malformed
|
|
252
|
+
mv "$WORK/live.new" "$WORK/live.tsv"
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
# lc_live_tables: derive live.items (id, number, database id, state; lowest number wins), live.epics (number, database id, state,
|
|
256
|
+
# author) and the ignored issues from live.tsv. An issue is ignored when it carries several distinct markers or none: live.ignored
|
|
257
|
+
# holds the count, live.ign.nums their numbers, live.ign.epic the numbers of the ignored ones that are epic candidates (the epic label,
|
|
258
|
+
# with several markers or none, or an epic marker among several) and live.ign.keys "number<TAB>gap id" for every gap marker of a several-marker issue.
|
|
259
|
+
lc_live_tables() {
|
|
260
|
+
: > "$WORK/live.items"; : > "$WORK/live.epics"; : > "$WORK/live.ignored"; : > "$WORK/live.ign.nums"; : > "$WORK/live.ign.epic"; : > "$WORK/live.ign.keys"
|
|
261
|
+
F_ITEMS="$WORK/live.items" F_EPICS="$WORK/live.epics" F_IGN="$WORK/live.ignored" F_NUMS="$WORK/live.ign.nums" F_IGNE="$WORK/live.ign.epic" F_IGNK="$WORK/live.ign.keys" \
|
|
262
|
+
awk -F'\t' -v OFS='\t' '
|
|
263
|
+
{ n = $1
|
|
264
|
+
if (!(n in first)) { first[n] = $6; ord[++cnt] = n; row[n] = $0; nk[n] = 1; ks[n, 1] = $6; ep[n] = ($4 == "true") }
|
|
265
|
+
else { dup = 0; for (j = 1; j <= nk[n]; j++) if (ks[n, j] == $6) dup = 1
|
|
266
|
+
if (!dup) { ks[n, ++nk[n]] = $6; multi[n] = 1 } } }
|
|
267
|
+
END {
|
|
268
|
+
for (i = 1; i <= cnt; i++) {
|
|
269
|
+
n = ord[i]
|
|
270
|
+
if (n in multi) {
|
|
271
|
+
ign++; print n > (ENVIRON["F_NUMS"]); isep = ep[n]
|
|
272
|
+
for (j = 1; j <= nk[n]; j++) { if (ks[n, j] == "@epic") isep = 1; else print n, ks[n, j] > (ENVIRON["F_IGNK"]) }
|
|
273
|
+
if (isep) print n > (ENVIRON["F_IGNE"])
|
|
274
|
+
continue
|
|
275
|
+
}
|
|
276
|
+
split(row[n], f, "\t")
|
|
277
|
+
if (f[6] == "-") { ign++; print n > (ENVIRON["F_NUMS"]); if (f[4] == "true") print n > (ENVIRON["F_IGNE"]); continue }
|
|
278
|
+
if (f[6] == "@epic") { if (f[4] == "true") print f[1], f[2], f[3], f[5] > (ENVIRON["F_EPICS"]); continue }
|
|
279
|
+
k = f[6]
|
|
280
|
+
if (!(k in bn) || n + 0 < bn[k] + 0) { bn[k] = n; bd[k] = f[2]; bs[k] = f[3] }
|
|
281
|
+
}
|
|
282
|
+
for (k in bn) print k, bn[k], bd[k], bs[k] > (ENVIRON["F_ITEMS"])
|
|
283
|
+
print ign + 0 > (ENVIRON["F_IGN"])
|
|
284
|
+
}' "$WORK/live.tsv" || lc__incomplete lookup malformed
|
|
285
|
+
[ -s "$WORK/live.ignored" ] || printf '0\n' > "$WORK/live.ignored"
|
|
286
|
+
sort -o "$WORK/live.items" "$WORK/live.items"
|
|
287
|
+
EPIC_CANDIDATES=$(grep -c . "$WORK/live.epics")
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
# lc__ign_hits <rows file>: rc 0 when an ignored several-marker issue carries the marker of a gap that file names (column 1), 1 when none
|
|
291
|
+
# does, 2 when the scan itself failed (a dead awk is never read as "no hit").
|
|
292
|
+
lc__ign_hits() {
|
|
293
|
+
local rc=0
|
|
294
|
+
F_ROWS="$1" awk -F'\t' '
|
|
295
|
+
FILENAME == ENVIRON["F_ROWS"] { id[$1] = 1; next }
|
|
296
|
+
($2 in id) { hit = 1 }
|
|
297
|
+
END { exit !hit }' "$1" "$WORK/live.ign.keys" || rc=$?
|
|
298
|
+
return "$rc"
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
# lc__live_gate: stop before any write when the listing holds something the run cannot read safely. An ignored issue that is an epic
|
|
302
|
+
# candidate (the lc:epic label with several marker lines or none) is an ambiguous epic; one that carries a marker of a gap in this plan
|
|
303
|
+
# could hide that gap, so the run stops with one closed reason instead of filing it a second time.
|
|
304
|
+
lc__live_gate() {
|
|
305
|
+
local rc=0
|
|
306
|
+
[ ! -s "$WORK/live.ign.epic" ] || lc_abort epic-ambiguous 2 "detail=ignored-epic"
|
|
307
|
+
if [ -s "$WORK/live.ign.keys" ]; then
|
|
308
|
+
lc__ign_hits "$WORK/plan.rows.tsv" || rc=$?
|
|
309
|
+
case "$rc" in
|
|
310
|
+
0) lc_abort issue-ambiguous 2 "detail=several-markers" ;;
|
|
311
|
+
1) ;;
|
|
312
|
+
*) lc__incomplete lookup malformed ;;
|
|
313
|
+
esac
|
|
314
|
+
fi
|
|
315
|
+
if [ "$EPIC_CANDIDATES" -gt 1 ]; then lc_abort epic-ambiguous 2 "detail=several-epics"; fi
|
|
316
|
+
return 0
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
# ---------------------------------------------------------------- Guard 2: bodies are built from the catalog, never typed
|
|
320
|
+
# lc_issue_body <id> <severity> <domain> <class> <title> <evidence> <closing> <remedy>: one body on stdout. Values reach the
|
|
321
|
+
# template through ENVIRON and index()/substr() only, so a backslash or an ampersand in a value (the domain label "Tests & CI/CD")
|
|
322
|
+
# is carried as it is. Secret-class findings carry only the fixed count phrase.
|
|
323
|
+
lc_issue_body() {
|
|
324
|
+
local ev=$6 cmd=""
|
|
325
|
+
case " $LC_COUNT_ONLY_IDS " in
|
|
326
|
+
*" $1 "*) grep -qE '^[0-9]+ (finding\(s\)|file\(s\)); (locations|names) withheld, run scan --show-secrets locally to see them$' <<<"$ev" || ev=$(lc_phrase sec_withheld) ;;
|
|
327
|
+
esac
|
|
328
|
+
case "$ev" in *'`'*) ev="(evidence withheld)" ;; esac
|
|
329
|
+
[ "$7" = "-" ] || cmd=" Command: \`$7\`"
|
|
330
|
+
V_BANNER=$(cat "$SKILL_DIR/references/banner.txt") V_ID=$1 V_SEVERITY=$2 V_DOMAIN=$(lc_domain_label "$3") V_TITLE=$5 V_EVIDENCE=$ev V_REMEDY=$8 V_COMMAND=$cmd awk '
|
|
331
|
+
{ out = ""; s = $0
|
|
332
|
+
while ((i = index(s, "{{")) > 0) {
|
|
333
|
+
rest = substr(s, i + 2); j = index(rest, "}}")
|
|
334
|
+
if (j == 0) break
|
|
335
|
+
out = out substr(s, 1, i - 1) ENVIRON["V_" substr(rest, 1, j - 1)]
|
|
336
|
+
s = substr(rest, j + 2)
|
|
337
|
+
}
|
|
338
|
+
print out s }' "$SKILL_DIR/references/issue-body.template"
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
lc_epic_title() { lc_phrase epic_heading; }
|
|
342
|
+
lc_epic_initial() {
|
|
343
|
+
printf '<!-- launch-check:epic -->\n\n%s\n\n# %s\n\n%s\n\n<!-- launch-check:begin -->\n<!-- launch-check:end -->\n\n%s\n' \
|
|
344
|
+
"$(cat "$SKILL_DIR/references/banner.txt")" "$(lc_phrase epic_heading)" "$(lc_phrase epic_intro)" "$(lc_phrase epic_outro)"
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
# lc__labels_for <rows file>: the lc: labels a create of these rows ensures (id, severity, domain, class, action, ...), one line, in the
|
|
348
|
+
# order the create ensures them. The preview prints it and the create uses it, so the two cannot differ.
|
|
349
|
+
lc__labels_for() {
|
|
350
|
+
awk -F'\t' 'BEGIN { s = "lc:launch-check lc:epic"; seen["lc:launch-check"] = 1; seen["lc:epic"] = 1 }
|
|
351
|
+
$5 == "create" { for (i = 1; i <= 2; i++) { l = (i == 1) ? "lc:severity-" $2 : "lc:domain-" $3; if (!(l in seen)) { seen[l] = 1; s = s " " l } } }
|
|
352
|
+
END { print s }' "$1"
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
lc__label_color() {
|
|
356
|
+
case "$1" in
|
|
357
|
+
lc:launch-check) printf '5319e7' ;; lc:epic) printf '3e4b9e' ;;
|
|
358
|
+
lc:severity-critical) printf 'b60205' ;; lc:severity-high) printf 'd93f0b' ;;
|
|
359
|
+
lc:severity-medium) printf 'fbca04' ;; lc:severity-low) printf '0e8a16' ;;
|
|
360
|
+
*) printf '1d76db' ;;
|
|
361
|
+
esac
|
|
362
|
+
}
|
|
363
|
+
lc__label_desc() {
|
|
364
|
+
case "$1" in
|
|
365
|
+
lc:launch-check) lc_phrase label_desc_scope ;; lc:epic) lc_phrase label_desc_epic ;;
|
|
366
|
+
lc:severity-*) lc_phrase label_desc_severity ;; *) lc_phrase label_desc_domain ;;
|
|
367
|
+
esac
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
# lc_report_hash: the report's state block, hashed. A finding accepted or reopened after the preview changes it.
|
|
371
|
+
lc_report_hash() {
|
|
372
|
+
tr -d '\r' < "$TARGET/$REPORT_REL" | awk '/^```launch-check-state$/ {f=1; next} /^```$/ && f {f=0} f' > "$WORK/state.blk"
|
|
373
|
+
git hash-object --stdin < "$WORK/state.blk"
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
# lc_issues_stale_check <plan report hash or empty> <plan catalog hash or empty>
|
|
377
|
+
lc_issues_stale_check() {
|
|
378
|
+
local rep_cat cur_cat cur_rep
|
|
379
|
+
cur_cat=$(git hash-object --stdin < "$CAT")
|
|
380
|
+
rep_cat=$(awk -F= '/^catalog_hash=/ {print $2; exit}' "$TARGET/$REPORT_REL" | tr -d '\r')
|
|
381
|
+
[ "$rep_cat" = "$cur_cat" ] || lc__stale catalog
|
|
382
|
+
F_PREV="$WORK/prev.tsv" awk -F'\t' '
|
|
383
|
+
FILENAME == ENVIRON["F_PREV"] { if ($2 == "open") o[$1] = 1; next }
|
|
384
|
+
!($1 in o) { bad = 1 }
|
|
385
|
+
END { exit bad }' "$WORK/prev.tsv" "$WORK/open.ids" || lc__stale not-open-in-report
|
|
386
|
+
if [ -n "${1:-}" ]; then
|
|
387
|
+
cur_rep=$(lc_report_hash)
|
|
388
|
+
[ "$cur_rep" = "$1" ] || lc__stale report-changed
|
|
389
|
+
[ "$cur_cat" = "${2:-}" ] || lc__stale catalog-changed
|
|
390
|
+
fi
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
# ---------------------------------------------------------------- the saved plan (trust chain)
|
|
394
|
+
# lc_plan_load <dir> <strict 0|1>: lstat the directory, copy the recognised files into $WORK/plan, validate the copy against closed
|
|
395
|
+
# vocabularies. Sets ISSUES_ORIG_PLAN_DIR, ISSUES_PLAN_DIR (the copy), PLAN_REPO, PLAN_HOST, PLAN_CATHASH, PLAN_REPHASH,
|
|
396
|
+
# PLAN_CREATE_N and writes plan.rows.tsv, plan.create.ids in $WORK. Strict mode also checks owner and mode (create); the parse-only
|
|
397
|
+
# check skips them so the committed sample is accepted under any umask.
|
|
398
|
+
lc_plan_load() {
|
|
399
|
+
local src=$1 strict=$2 real dst="$WORK/plan" bad uid f mode id n sz m vrc=0
|
|
400
|
+
[ -d "$src" ] || lc__pbad not-a-directory
|
|
401
|
+
[ ! -L "$src" ] || lc__pbad plan-dir-symlink
|
|
402
|
+
real=$(cd "$src" 2>/dev/null && pwd -P) || lc__pbad unreadable
|
|
403
|
+
if [ "$strict" = 1 ]; then
|
|
404
|
+
uid=$(id -u)
|
|
405
|
+
for f in "$real" "$real/issues"; do
|
|
406
|
+
[ -d "$f" ] || continue
|
|
407
|
+
[ -n "$(find "$f" -maxdepth 0 -user "$uid" 2>/dev/null)" ] || lc__pbad owner
|
|
408
|
+
mode=$(ls -ld "$f" | cut -c1-10)
|
|
409
|
+
case "$mode" in ?????-??-*) ;; *) lc__pbad mode ;; esac
|
|
410
|
+
done
|
|
411
|
+
fi
|
|
412
|
+
[ -f "$real/plan.tsv" ] && [ ! -L "$real/plan.tsv" ] || lc__pbad plan-file
|
|
413
|
+
[ -f "$real/epic.md" ] && [ ! -L "$real/epic.md" ] || lc__pbad epic-file
|
|
414
|
+
[ -d "$real/issues" ] && [ ! -L "$real/issues" ] || lc__pbad issues-dir
|
|
415
|
+
[ -z "$(find "$real" -type l 2>/dev/null | head -n 1)" ] || lc__pbad symlink
|
|
416
|
+
for f in "$real/plan.tsv" "$real/epic.md"; do
|
|
417
|
+
sz=$(wc -c < "$f" | tr -d ' ')
|
|
418
|
+
[ "$sz" -le "$ISSUES_MAX_BYTES" ] || lc__pbad size
|
|
419
|
+
done
|
|
420
|
+
rm -rf "${dst:?}"; mkdir -p "$dst/issues" || lc__pbad copy
|
|
421
|
+
cp -P "$real/plan.tsv" "$dst/plan.tsv" && cp -P "$real/epic.md" "$dst/epic.md" || lc__pbad copy
|
|
422
|
+
bad=$(CAPN="$ISSUES_CAP" RE_SLUG="$ISSUES_RE_SLUG" RE_ID="$ISSUES_RE_ID" RE_TITLE="$ISSUES_RE_TITLE" awk -F'\t' '
|
|
423
|
+
function fail(t) { print t; failed = 1; exit 1 }
|
|
424
|
+
BEGIN { split("repo host visibility catalog_hash report_hash created", K, " ") }
|
|
425
|
+
NR <= 6 {
|
|
426
|
+
k = K[NR]; if (index($0, k "=") != 1) fail("header")
|
|
427
|
+
v = substr($0, length(k) + 2)
|
|
428
|
+
if (k == "repo" && v !~ ENVIRON["RE_SLUG"]) fail("repo")
|
|
429
|
+
if (k == "host" && (v !~ /^[a-z0-9][a-z0-9.-]*$/ || length(v) > 253)) fail("host")
|
|
430
|
+
if (k == "visibility" && v !~ /^(PUBLIC|PRIVATE|INTERNAL|UNKNOWN)$/) fail("visibility")
|
|
431
|
+
if ((k == "catalog_hash" || k == "report_hash") && (v !~ /^[0-9a-f]+$/ || length(v) < 7 || length(v) > 64)) fail("hash")
|
|
432
|
+
if (k == "created" && v !~ /^[0-9TZ:-]+$/) fail("created")
|
|
433
|
+
next }
|
|
434
|
+
NR == 7 { if ($0 != "id\tseverity\tdomain\tclass\taction\ttitle") fail("columns"); next }
|
|
435
|
+
{ if (NF != 6) fail("row")
|
|
436
|
+
if ($1 !~ ENVIRON["RE_ID"] || length($1) > 64) fail("id")
|
|
437
|
+
if ($1 in seen) fail("duplicate-id")
|
|
438
|
+
seen[$1] = 1
|
|
439
|
+
if ($2 !~ /^(critical|high|medium|low)$/) fail("severity")
|
|
440
|
+
if ($3 !~ /^(security|tests-ci|tech-debt|reliability-ops)$/) fail("domain")
|
|
441
|
+
if ($4 !~ /^(readiness|baseline)$/) fail("class")
|
|
442
|
+
if ($5 !~ /^(create|exists|closed|accepted|excluded|capped)$/) fail("action")
|
|
443
|
+
if ($6 !~ ENVIRON["RE_TITLE"] || length($6) > 120 || $6 ~ /GH-[0-9]/) fail("title")
|
|
444
|
+
if ($5 == "create") n++ }
|
|
445
|
+
END { if (failed) exit 1; if (NR < 7) fail("columns"); if (n > ENVIRON["CAPN"] + 0) fail("cap") }' "$dst/plan.tsv") || vrc=$?
|
|
446
|
+
# A validator that died (no awk, a crash) said nothing: that is not "valid".
|
|
447
|
+
if [ "$vrc" -ne 0 ]; then lc__pbad "$(printf '%s\n' "${bad:-validator}" | awk 'NR == 1')"; fi
|
|
448
|
+
[ -z "$bad" ] || lc__pbad "$bad"
|
|
449
|
+
PLAN_REPO=$(sed -n 's/^repo=//p' "$dst/plan.tsv" | head -n 1)
|
|
450
|
+
PLAN_HOST=$(sed -n 's/^host=//p' "$dst/plan.tsv" | head -n 1)
|
|
451
|
+
PLAN_CATHASH=$(sed -n 's/^catalog_hash=//p' "$dst/plan.tsv" | head -n 1)
|
|
452
|
+
PLAN_REPHASH=$(sed -n 's/^report_hash=//p' "$dst/plan.tsv" | head -n 1)
|
|
453
|
+
awk 'NR > 7' "$dst/plan.tsv" > "$WORK/plan.rows.tsv" || lc__pbad validator
|
|
454
|
+
awk -F'\t' '$5 == "create" { print $1 }' "$WORK/plan.rows.tsv" > "$WORK/plan.create.ids" || lc__pbad validator
|
|
455
|
+
PLAN_CREATE_N=$(grep -c . "$WORK/plan.create.ids")
|
|
456
|
+
n=$(find "$real/issues" -mindepth 1 -maxdepth 1 | wc -l | tr -d ' ')
|
|
457
|
+
[ "$n" = "$PLAN_CREATE_N" ] || lc__pbad body-files
|
|
458
|
+
while IFS= read -r id; do
|
|
459
|
+
f="$real/issues/$id.md"
|
|
460
|
+
[ -f "$f" ] && [ ! -L "$f" ] || lc__pbad body-file
|
|
461
|
+
sz=$(wc -c < "$f" | tr -d ' ')
|
|
462
|
+
[ "$sz" -le "$ISSUES_MAX_BYTES" ] || lc__pbad size
|
|
463
|
+
cp -P "$f" "$dst/issues/$id.md" || lc__pbad copy
|
|
464
|
+
m=$(grep -o '<!-- launch-check:[^>]*-->' "$dst/issues/$id.md")
|
|
465
|
+
[ "$m" = "<!-- launch-check:gap=$id -->" ] || lc__pbad marker
|
|
466
|
+
done < "$WORK/plan.create.ids"
|
|
467
|
+
m=$(grep -o '<!-- launch-check:[^>]*-->' "$dst/epic.md")
|
|
468
|
+
[ "$m" = "$(printf '<!-- launch-check:epic -->\n<!-- launch-check:begin -->\n<!-- launch-check:end -->')" ] || lc__pbad epic-marker
|
|
469
|
+
[ -z "$(find "$dst" -type l 2>/dev/null | head -n 1)" ] || lc__pbad symlink
|
|
470
|
+
ISSUES_ORIG_PLAN_DIR=$real
|
|
471
|
+
ISSUES_PLAN_DIR=$dst
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
lc_issues_check_plan() {
|
|
475
|
+
lc_plan_load "$ISSUES_PLAN_ARG" 0
|
|
476
|
+
printf 'SOLEUR_LAUNCH_CHECK_PLAN_OK repo=%s host=%s create=%s items=%s\n' "$PLAN_REPO" "$PLAN_HOST" "$PLAN_CREATE_N" "$(grep -c . "$WORK/plan.rows.tsv")"
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
# ---------------------------------------------------------------- shared output helpers
|
|
480
|
+
lc__create_cmd() { # <plan-dir> <create-count>
|
|
481
|
+
local c
|
|
482
|
+
c=$(printf 'bash %q issues --create --target %q --facts %q' "$SKILL_DIR/scripts/launch-check.sh" "$TARGET" "$ISSUES_FACTS_ARG")
|
|
483
|
+
[ -z "$ISSUES_JUDGED_ARG" ] || c="$c $(printf -- '--judged %q' "$ISSUES_JUDGED_ARG")"
|
|
484
|
+
c="$c $(printf -- '--plan %q --confirm-repo %q --confirm-count %q' "$1" "$ISSUES_REPO" "$2")"
|
|
485
|
+
[ -z "${ISSUES_REPO_ARG:-}" ] || c="$c $(printf -- '--repo %q' "$ISSUES_REPO_ARG")"
|
|
486
|
+
[ "${ISSUES_HOST:-github.com}" = github.com ] || c="$c $(printf -- '--host %q' "$ISSUES_HOST")"
|
|
487
|
+
lc__say "$c"
|
|
488
|
+
}
|
|
489
|
+
# lc__public_note: the printed command never carries --confirm-public (a command copied and run whole must not publish a list of
|
|
490
|
+
# unfixed gaps on its own); a separate line says when the owner's own yes may append it.
|
|
491
|
+
lc__public_note() { [ "${ISSUES_VIS:-PRIVATE}" = PRIVATE ] || lc__fmt confirm_public_append; }
|
|
492
|
+
|
|
493
|
+
# ---------------------------------------------------------------- preview
|
|
494
|
+
lc_issues_partition() {
|
|
495
|
+
F_ACC="$WORK/accepted.ids" F_LIVE="$WORK/live.items" X_DOM="$ISSUES_EXCL_DOM" X_CLS="$ISSUES_EXCL_CLS" CAPN="$ISSUES_CAP" \
|
|
496
|
+
awk -F'\t' -v OFS='\t' '
|
|
497
|
+
FILENAME == ENVIRON["F_ACC"] { acc[$1] = 1; next }
|
|
498
|
+
FILENAME == ENVIRON["F_LIVE"] { lst[$1] = $4; lnum[$1] = $2; next }
|
|
499
|
+
{ id = $2; dom = $3; cls = $4
|
|
500
|
+
if (id in acc) a = "accepted"
|
|
501
|
+
else if (index(ENVIRON["X_DOM"], "," dom ",") > 0 || index(ENVIRON["X_CLS"], "," cls ",") > 0) a = "excluded"
|
|
502
|
+
else if (id in lst) a = (lst[id] == "closed") ? "closed" : "exists"
|
|
503
|
+
else if (++made <= ENVIRON["CAPN"] + 0) a = "create"
|
|
504
|
+
else a = "capped"
|
|
505
|
+
print id, $5, dom, cls, a, $6, $7, $8, $9, ((id in lnum) ? lnum[id] : "-") }' \
|
|
506
|
+
"$WORK/accepted.ids" "$WORK/live.items" "$WORK/gaps.tsv" > "$WORK/part.tsv" || lc_abort plan-invalid 2 "detail=validator"
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
lc_issues_preview() {
|
|
510
|
+
local pb="$WORK/pb" plandir="" parent n_create n_exists n_closed n_accepted n_excluded n_capped
|
|
511
|
+
local id sev dom cls act title ev clos rem num c_crit c_high c_med c_low created rc ign_conflict=0
|
|
512
|
+
[ -f "$TARGET/$REPORT_REL" ] || { lc__fmt report_missing_fix; lc_abort report-missing 2 "detail=no-report"; }
|
|
513
|
+
if ! lc_issues_preflight; then
|
|
514
|
+
printf 'SOLEUR_LAUNCH_CHECK_ISSUES mode=report-only reason=%s\n' "$ISSUES_REASON"
|
|
515
|
+
lc__fmt "report_only_$ISSUES_REASON"
|
|
516
|
+
exit 0
|
|
517
|
+
fi
|
|
518
|
+
lc_issues_origin_check
|
|
519
|
+
lc_prepare_inputs
|
|
520
|
+
lc_compute_gaps
|
|
521
|
+
lc_issues_stale_check "" ""
|
|
522
|
+
lc_issues_live
|
|
523
|
+
lc_live_tables
|
|
524
|
+
lc_issues_partition
|
|
525
|
+
# Before anything is written for the customer: a dead scan is a stop, never "no conflict".
|
|
526
|
+
if [ -s "$WORK/live.ign.keys" ]; then
|
|
527
|
+
rc=0; lc__ign_hits "$WORK/part.tsv" || rc=$?
|
|
528
|
+
case "$rc" in 0) ign_conflict=1 ;; 1) ;; *) lc__incomplete lookup malformed ;; esac
|
|
529
|
+
fi
|
|
530
|
+
bad=$(RE_ID="$ISSUES_RE_ID" RE_TITLE="$ISSUES_RE_TITLE" awk -F'\t' '$1 !~ ENVIRON["RE_ID"] || $6 !~ ENVIRON["RE_TITLE"] || length($6) > 120 || $6 ~ /GH-[0-9]/ { print $1; exit }' "$WORK/part.tsv") \
|
|
531
|
+
|| lc_abort plan-invalid 2 "detail=validator"
|
|
532
|
+
[ -z "$bad" ] || lc_abort plan-invalid 2 "detail=catalog-title"
|
|
533
|
+
n_create=$(awk -F'\t' '$5 == "create"' "$WORK/part.tsv" | grep -c .)
|
|
534
|
+
n_exists=$(awk -F'\t' '$5 == "exists"' "$WORK/part.tsv" | grep -c .)
|
|
535
|
+
n_closed=$(awk -F'\t' '$5 == "closed"' "$WORK/part.tsv" | grep -c .)
|
|
536
|
+
n_accepted=$(awk -F'\t' '$5 == "accepted"' "$WORK/part.tsv" | grep -c .)
|
|
537
|
+
n_excluded=$(awk -F'\t' '$5 == "excluded"' "$WORK/part.tsv" | grep -c .)
|
|
538
|
+
n_capped=$(awk -F'\t' '$5 == "capped"' "$WORK/part.tsv" | grep -c .)
|
|
539
|
+
|
|
540
|
+
# Build the plan in $WORK, scan the exact bytes, and only then put it where the customer can see it.
|
|
541
|
+
mkdir -p "$pb/issues" && chmod 700 "$pb" "$pb/issues"
|
|
542
|
+
created=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
543
|
+
{
|
|
544
|
+
printf 'repo=%s\nhost=%s\nvisibility=%s\ncatalog_hash=%s\nreport_hash=%s\ncreated=%s\n' "$ISSUES_REPO" "$ISSUES_HOST" "$ISSUES_VIS" \
|
|
545
|
+
"$(git hash-object --stdin < "$CAT")" "$(lc_report_hash)" "$created"
|
|
546
|
+
printf 'id\tseverity\tdomain\tclass\taction\ttitle\n'
|
|
547
|
+
awk -F'\t' -v OFS='\t' '{ print $1, $2, $3, $4, $5, $6 }' "$WORK/part.tsv"
|
|
548
|
+
} > "$pb/plan.tsv"
|
|
549
|
+
: > "$WORK/blob"
|
|
550
|
+
while IFS=$'\t' read -r id sev dom cls act title ev clos rem num; do
|
|
551
|
+
[ "$act" = create ] || continue
|
|
552
|
+
lc_issue_body "$id" "$sev" "$dom" "$cls" "$title" "$ev" "$clos" "$rem" > "$pb/issues/$id.md"
|
|
553
|
+
{ printf '%s\n' "$title"; cat "$pb/issues/$id.md"; } >> "$WORK/blob"
|
|
554
|
+
done < "$WORK/part.tsv"
|
|
555
|
+
lc_epic_initial > "$pb/epic.md"
|
|
556
|
+
{ lc_epic_title; cat "$pb/epic.md"; } >> "$WORK/blob"
|
|
557
|
+
for id in lc:launch-check lc:epic; do printf '%s\n%s\n' "$id" "$(lc__label_desc "$id")" >> "$WORK/blob"; done
|
|
558
|
+
lc_emit_checked "$WORK/blob" "" 1
|
|
559
|
+
|
|
560
|
+
if [ "${LC_DRY:-0}" = 1 ]; then plandir="-"
|
|
561
|
+
else
|
|
562
|
+
parent=${ISSUES_PLAN_OUT:-${TMPDIR:-/tmp}}
|
|
563
|
+
( umask 077; mkdir -p "$parent" ) || lc_abort write-failed 2 "detail=plan-out"
|
|
564
|
+
plandir=$(mktemp -d "$parent/lc-issues-plan.XXXXXX") || lc_abort write-failed 2 "detail=plan-dir" # lint-trap-ownership: ok the saved plan directory is preview's output and must outlive the process (--create reads it); the customer removes it with the printed guarded discard
|
|
565
|
+
chmod 700 "$plandir"
|
|
566
|
+
cp -R "$pb/." "$plandir/" || lc_abort write-failed 2 "detail=plan-copy"
|
|
567
|
+
plandir=$(cd "$plandir" && pwd -P)
|
|
568
|
+
fi
|
|
569
|
+
|
|
570
|
+
lc__fmt issues_repo_line "$ISSUES_REPO" "$ISSUES_HOST" "$ISSUES_VIS" "$ISSUES_FORK"
|
|
571
|
+
[ "$ISSUES_FORK" != true ] || lc__fmt issues_fork_warn
|
|
572
|
+
[ "$ISSUES_VIS" = PRIVATE ] || lc__fmt issues_public_warn
|
|
573
|
+
if [ "$EPIC_CANDIDATES" -gt 1 ]; then lc__fmt issues_epic_ambiguous_warn
|
|
574
|
+
elif [ "$EPIC_CANDIDATES" = 1 ] && [ "$(cut -f3 "$WORK/live.epics")" = closed ]; then lc__fmt issues_epic_closed_warn
|
|
575
|
+
elif [ "$EPIC_CANDIDATES" = 1 ] && lc_gh_read api user --jq '.login' \
|
|
576
|
+
&& [ "$(cut -f4 "$WORK/live.epics")" != "$(awk 'NR == 1 { print; exit }' "$WORK/gh.out")" ]; then lc__fmt issues_epic_author_warn; fi
|
|
577
|
+
n=$(cat "$WORK/live.ignored")
|
|
578
|
+
[ "$n" = 0 ] || lc__fmt issues_ignored "$n" "$(head -n 10 "$WORK/live.ign.nums" | sed 's/^/#/' | paste -s -d, -)"
|
|
579
|
+
[ ! -s "$WORK/live.ign.epic" ] || lc__fmt issues_epic_candidate_warn
|
|
580
|
+
[ "$ign_conflict" = 0 ] || lc__fmt issues_ignored_conflict_warn
|
|
581
|
+
lc__fmt issues_counts "$n_create" "$n_exists" "$n_closed" "$n_accepted" "$n_excluded" "$n_capped"
|
|
582
|
+
c_crit=$(awk -F'\t' '$5 == "create" && $2 == "critical"' "$WORK/part.tsv" | grep -c .)
|
|
583
|
+
c_high=$(awk -F'\t' '$5 == "create" && $2 == "high"' "$WORK/part.tsv" | grep -c .)
|
|
584
|
+
c_med=$(awk -F'\t' '$5 == "create" && $2 == "medium"' "$WORK/part.tsv" | grep -c .)
|
|
585
|
+
c_low=$(awk -F'\t' '$5 == "create" && $2 == "low"' "$WORK/part.tsv" | grep -c .)
|
|
586
|
+
lc__fmt issues_by_severity "$c_crit" "$c_high" "$c_med" "$c_low"
|
|
587
|
+
lc__fmt issues_cap_rule "$ISSUES_CAP" "$n_capped"
|
|
588
|
+
# Informational lines: a filed issue whose gap is resolved, and one the customer closed while the gap is still open.
|
|
589
|
+
F_CUR="$WORK/cur.ids" F_LIVE="$WORK/live.items" awk -F'\t' '
|
|
590
|
+
FILENAME == ENVIRON["F_CUR"] { cur[$1] = 1; next }
|
|
591
|
+
$4 == "open" && !($1 in cur) { print $2 }' "$WORK/cur.ids" "$WORK/live.items" > "$WORK/resolved.nums"
|
|
592
|
+
while IFS= read -r num; do [ -n "$num" ] || continue; lc__fmt issues_resolved "#$num"; done < "$WORK/resolved.nums"
|
|
593
|
+
while IFS=$'\t' read -r id sev dom cls act title ev clos rem num; do
|
|
594
|
+
[ "$act" = closed ] || continue
|
|
595
|
+
lc__fmt issues_closed_open "#$num"
|
|
596
|
+
done < "$WORK/part.tsv"
|
|
597
|
+
if [ "$n_create" -gt 0 ]; then
|
|
598
|
+
lc__fmt issues_table_hdr
|
|
599
|
+
while IFS=$'\t' read -r id sev dom cls act title ev clos rem num; do
|
|
600
|
+
[ "$act" = create ] || continue
|
|
601
|
+
lc__say "$id | $sev | $title | $ev"
|
|
602
|
+
done < "$WORK/part.tsv"
|
|
603
|
+
lc__fmt issues_labels_line "$(lc__labels_for "$WORK/part.tsv")"
|
|
604
|
+
if [ "${LC_DRY:-0}" = 1 ]; then lc__fmt dry_run_note
|
|
605
|
+
else
|
|
606
|
+
lc__fmt issues_create_hdr
|
|
607
|
+
lc__create_cmd "$plandir" "$n_create"
|
|
608
|
+
lc__public_note
|
|
609
|
+
lc__fmt issues_guard_note
|
|
610
|
+
fi
|
|
611
|
+
else
|
|
612
|
+
lc__fmt issues_none
|
|
613
|
+
fi
|
|
614
|
+
printf 'SOLEUR_LAUNCH_CHECK_ISSUES_PLAN repo=%s host=%s visibility=%s fork=%s create=%s exists=%s closed=%s accepted=%s excluded=%s capped=%s plan=%s\n' \
|
|
615
|
+
"$ISSUES_REPO" "$ISSUES_HOST" "$ISSUES_VIS" "$ISSUES_FORK" "$n_create" "$n_exists" "$n_closed" "$n_accepted" "$n_excluded" "$n_capped" "$plandir"
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
# ---------------------------------------------------------------- Guard 4: epic edits confined to the marked section
|
|
619
|
+
# lc_epic_splice <old-body-file> <new-section-file>: the new body on stdout, or rc 1 (nothing printed) when the markers are not
|
|
620
|
+
# exactly one begin line followed by one end line. Only the lines between them change; every other byte is carried over (a CR
|
|
621
|
+
# before the newline is tolerated when finding a marker, and kept). The new section takes the line ending of the begin marker.
|
|
622
|
+
lc_epic_splice() {
|
|
623
|
+
local old=$1 sec=$2 line bare state=0 nb=0 ne=0 crlf=0 out="$WORK/out/splice.tmp" total last
|
|
624
|
+
[ -s "$old" ] || return 1
|
|
625
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
626
|
+
bare=${line%$'\r'}
|
|
627
|
+
if [ "$bare" = "<!-- launch-check:begin -->" ]; then nb=$((nb + 1)); [ "$ne" = 0 ] || return 1
|
|
628
|
+
elif [ "$bare" = "<!-- launch-check:end -->" ]; then ne=$((ne + 1)); [ "$nb" = 1 ] || return 1; fi
|
|
629
|
+
done < "$old"
|
|
630
|
+
[ "$nb" = 1 ] && [ "$ne" = 1 ] || return 1
|
|
631
|
+
: > "$out"
|
|
632
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
633
|
+
bare=${line%$'\r'}
|
|
634
|
+
case "$state" in
|
|
635
|
+
0) printf '%s\n' "$line" >> "$out"
|
|
636
|
+
if [ "$bare" = "<!-- launch-check:begin -->" ]; then
|
|
637
|
+
state=1; [ "$bare" = "$line" ] || crlf=1
|
|
638
|
+
while IFS= read -r sline || [ -n "$sline" ]; do
|
|
639
|
+
if [ "$crlf" = 1 ]; then printf '%s\r\n' "${sline%$'\r'}" >> "$out"; else printf '%s\n' "$sline" >> "$out"; fi
|
|
640
|
+
done < "$sec"
|
|
641
|
+
fi ;;
|
|
642
|
+
1) if [ "$bare" = "<!-- launch-check:end -->" ]; then state=2; printf '%s\n' "$line" >> "$out"; fi ;;
|
|
643
|
+
2) printf '%s\n' "$line" >> "$out" ;;
|
|
644
|
+
esac
|
|
645
|
+
done < "$old"
|
|
646
|
+
last=$(tail -c 1 "$old" | od -An -tx1 | tr -d ' \n')
|
|
647
|
+
total=$(wc -c < "$out" | tr -d ' ')
|
|
648
|
+
if [ "$last" = 0a ]; then cat "$out"; else head -c $((total - 1)) "$out"; fi
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
# lc__strip_nl <in> <out>: drop the single trailing newline that the CLI's --jq adds to a string.
|
|
652
|
+
lc__strip_nl() {
|
|
653
|
+
local sz
|
|
654
|
+
sz=$(wc -c < "$1" | tr -d ' ')
|
|
655
|
+
if [ "$sz" -gt 0 ] && [ "$(tail -c 1 "$1" | od -An -tx1 | tr -d ' \n')" = 0a ]; then head -c $((sz - 1)) "$1" > "$2"; else cp "$1" "$2"; fi
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
# ---------------------------------------------------------------- create
|
|
659
|
+
lc__summary() { # <phase>
|
|
660
|
+
local made=${CNT_CREATED:-0}
|
|
661
|
+
printf 'SOLEUR_LAUNCH_CHECK_ISSUES created=%s linked=%s skipped=%s failed=%s fallback=%s epic=%s epic-section=%s plan=%s phase=%s\n' \
|
|
662
|
+
"$made" "${CNT_LINKED:-0}" "${CNT_SKIPPED:-0}" "${FAILED_IDS:--}" "${ISSUES_FALLBACK:-none}" "${EPIC_REF:--}" "${EPIC_STATE:-skipped}" \
|
|
663
|
+
"${ISSUES_ORIG_PLAN_DIR:--}" "$1"
|
|
664
|
+
}
|
|
665
|
+
# lc__incomplete <phase> <detail>: the run stopped with something unfinished. Print the summary, the rate-limit hint and the exact
|
|
666
|
+
# resume command, then abort. Nothing the CLI printed is echoed; detail is one of the closed tokens.
|
|
667
|
+
lc__resume_block() { # <phase> <detail>: the summary, the rate-limit hint and the exact resume command
|
|
668
|
+
lc__summary "$1"
|
|
669
|
+
[ "$2" != rate-limit ] || lc__fmt rate_limit_hint
|
|
670
|
+
if [ -n "${ISSUES_ORIG_PLAN_DIR:-}" ]; then
|
|
671
|
+
lc__fmt resume_hint
|
|
672
|
+
lc__create_cmd "$ISSUES_ORIG_PLAN_DIR" "${PLAN_CREATE_N:-0}"
|
|
673
|
+
lc__public_note
|
|
674
|
+
fi
|
|
675
|
+
}
|
|
676
|
+
lc__incomplete() {
|
|
677
|
+
lc__resume_block "$1" "$2"
|
|
678
|
+
lc_abort issues-incomplete 2 "phase=$1 detail=$2 plan=${ISSUES_ORIG_PLAN_DIR:--}"
|
|
679
|
+
}
|
|
680
|
+
# A signal ends the run (the exit code is 128 plus the signal). When a write was already attempted, the summary and the exact
|
|
681
|
+
# resume command are printed first: a created issue is found again by its marker, so the resume is safe even when the counts lag.
|
|
682
|
+
lc__on_signal() { # <exit code>
|
|
683
|
+
trap '' INT TERM HUP
|
|
684
|
+
if [ "${LC_WRITES_DONE:-0}" -gt 0 ]; then
|
|
685
|
+
lc__resume_block interrupted signal
|
|
686
|
+
printf 'SOLEUR_LAUNCH_CHECK_ABORT reason=issues-incomplete phase=interrupted detail=signal plan=%s\n' "${ISSUES_ORIG_PLAN_DIR:--}"
|
|
687
|
+
fi
|
|
688
|
+
exit "$1"
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
# lc__record_failed: the record of what a run created (created.tsv) could not be written. The issue exists and is found again by its
|
|
692
|
+
# marker, so the summary and the resume command are printed before the run stops.
|
|
693
|
+
lc__record_failed() {
|
|
694
|
+
lc__resume_block create record
|
|
695
|
+
lc_abort write-failed 2 "detail=created-tsv"
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
# lc__parse_pair: the "number<TAB>database id" line a create printed, into NEW_NUM and NEW_ID.
|
|
699
|
+
lc__parse_pair() {
|
|
700
|
+
local line
|
|
701
|
+
line=$(awk 'NR == 1 { print; exit }' "$WORK/gh.out")
|
|
702
|
+
lc__re $'^[0-9]+\t[0-9]+$' "$line" || return 1
|
|
703
|
+
NEW_NUM=$(cut -f1 <<<"$line"); NEW_ID=$(cut -f2 <<<"$line")
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
# lc__link_failed: the policy for a failed sub-issue call (the link POST, the children listing). Only a refusal of the feature itself
|
|
707
|
+
# (403, 404, 410 or 422) latches the run to the task list. A rate limit, a transport failure, a timeout or a 5xx says nothing about the
|
|
708
|
+
# feature, so it stops the run resumably (phase=link): the re-run links what is still unlinked, and a later run can still use the real links.
|
|
709
|
+
lc__link_failed() {
|
|
710
|
+
case "$LC_GH_KIND" in
|
|
711
|
+
http-403|http-404|http-410|http-422) ISSUES_FALLBACK=task-list ;;
|
|
712
|
+
*) lc__incomplete link "$LC_GH_KIND" ;;
|
|
713
|
+
esac
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
# lc__link <issue database id> <number> <gap id>: link a child under the epic (policy: lc__link_failed).
|
|
717
|
+
lc__link() {
|
|
718
|
+
if lc_gh_write api -X POST "repos/$ISSUES_REPO/issues/$EPIC_NUM/sub_issues" -F "sub_issue_id=$1"; then
|
|
719
|
+
CNT_LINKED=$((CNT_LINKED + 1))
|
|
720
|
+
lc__say "linked: #$2 $3"
|
|
721
|
+
else
|
|
722
|
+
lc__link_failed
|
|
723
|
+
fi
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
# lc__epic_section <old-body-file> <outfile>: the text between the markers, from live state.
|
|
727
|
+
lc__epic_section() {
|
|
728
|
+
local old=$1 out=$2 num id state n tick
|
|
729
|
+
awk '
|
|
730
|
+
{ l = $0; sub(/\r$/, "", l) }
|
|
731
|
+
l == "<!-- launch-check:begin -->" { s = 1; next }
|
|
732
|
+
l == "<!-- launch-check:end -->" { s = 0; next }
|
|
733
|
+
s && l ~ /^- \[[xX]\] #[0-9]+/ { t = l; sub(/^- \[[xX]\] #/, "", t); sub(/[^0-9].*$/, "", t); print t }' "$old" > "$WORK/ticked.nums" \
|
|
734
|
+
|| lc__incomplete epic malformed
|
|
735
|
+
lc__fmt epic_counts "$CNT_CREATED" "$CNT_SKIPPED" "$ISSUES_FALLBACK" > "$out"
|
|
736
|
+
if [ "$ISSUES_FALLBACK" = task-list ]; then
|
|
737
|
+
# Items that exist now: the live open ones named by the plan, plus what this run made.
|
|
738
|
+
F_ROWS="$WORK/plan.rows.tsv" F_LIVE="$WORK/live.items" F_MADE="$WORK/made.tsv" awk -F'\t' -v OFS='\t' '
|
|
739
|
+
FILENAME == ENVIRON["F_ROWS"] { if ($5 == "create" || $5 == "exists") want[$1] = 1; next }
|
|
740
|
+
FILENAME == ENVIRON["F_LIVE"] { if ($4 == "open" && ($1 in want)) print $2, $1; next }
|
|
741
|
+
{ if ($1 in want) print $2, $1 }' "$WORK/plan.rows.tsv" "$WORK/live.items" "$WORK/made.tsv" | sort -t "$LC_TAB" -u -k1,1n > "$WORK/items.nums" \
|
|
742
|
+
|| lc__incomplete epic malformed
|
|
743
|
+
while IFS=$'\t' read -r num id; do
|
|
744
|
+
[ -n "$num" ] || continue
|
|
745
|
+
tick=" "; grep -qxF "$num" "$WORK/ticked.nums" && tick="x"
|
|
746
|
+
printf -- '- [%s] #%s %s\n' "$tick" "$num" "$id" >> "$out"
|
|
747
|
+
done < "$WORK/items.nums"
|
|
748
|
+
fi
|
|
749
|
+
n=$(awk -F'\t' '$5 == "capped" { printf "%s%s", (c++ ? ", " : ""), $1 }' "$WORK/plan.rows.tsv")
|
|
750
|
+
[ -z "$n" ] || lc__fmt epic_capped "$n" >> "$out"
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
# lc__epic_update: GET the epic body just before the splice, rebuild the marked section, scan it, PATCH only if the result differs.
|
|
754
|
+
lc__epic_update() {
|
|
755
|
+
local sec="$WORK/out/section.md" live="$WORK/out/epic.live" raw="$WORK/out/epic.raw" new="$WORK/out/epic.new" rc=0
|
|
756
|
+
[ "$EPIC_REF" != "-" ] || return 0
|
|
757
|
+
lc_gh_read api "repos/$ISSUES_REPO/issues/$EPIC_NUM" --jq '.body // ""' || lc__incomplete epic "$LC_GH_KIND"
|
|
758
|
+
cp "$WORK/gh.out" "$raw"; lc__strip_nl "$raw" "$live"
|
|
759
|
+
lc__epic_section "$live" "$sec"
|
|
760
|
+
if ! lc_epic_splice "$live" "$sec" > "$new"; then EPIC_STATE=markers-damaged; return 0; fi
|
|
761
|
+
( lc_emit_checked "$sec" "" 1 ) || rc=$?
|
|
762
|
+
if [ "$rc" -ne 0 ]; then EPIC_STATE=blocked; lc__summary complete; exit "$rc"; fi
|
|
763
|
+
if cmp -s "$live" "$new"; then EPIC_STATE=unchanged; return 0; fi
|
|
764
|
+
if lc_gh_write api -X PATCH "repos/$ISSUES_REPO/issues/$EPIC_NUM" -F "body=@$new"; then EPIC_STATE=updated
|
|
765
|
+
else lc__incomplete epic "$LC_GH_KIND"; fi
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
lc_issues_create() {
|
|
769
|
+
local id sev dom cls act title ev clos rem num want lbl made_epic=0 k
|
|
770
|
+
CNT_CREATED=0; CNT_LINKED=0; CNT_SKIPPED=0; FAILED_IDS="-"; ISSUES_FALLBACK=none; EPIC_REF="-"; EPIC_NUM=""; EPIC_STATE=skipped
|
|
771
|
+
mkdir -p "$WORK/out"; : > "$WORK/made.tsv"
|
|
772
|
+
lc_plan_load "$ISSUES_PLAN_ARG" 1
|
|
773
|
+
trap 'lc__on_signal 130' INT; trap 'lc__on_signal 143' TERM; trap 'lc__on_signal 129' HUP
|
|
774
|
+
if [ "$ISSUES_CONFIRM_REPO" != "$PLAN_REPO" ] || [ "$ISSUES_CONFIRM_COUNT" != "$PLAN_CREATE_N" ]; then
|
|
775
|
+
lc__fmt confirm_flags_fix; lc_abort usage 2 "detail=confirm-mismatch"
|
|
776
|
+
fi
|
|
777
|
+
[ "$PLAN_HOST" = "$ISSUES_HOST" ] || lc_abort usage 2 "detail=host-mismatch plan-host=$PLAN_HOST (pass --host $PLAN_HOST, or none for github.com)"
|
|
778
|
+
lc_prepare_inputs
|
|
779
|
+
lc_compute_gaps
|
|
780
|
+
lc_issues_preflight || lc_abort issues-unavailable 2 "detail=$ISSUES_REASON"
|
|
781
|
+
lc__same_slug "$ISSUES_RESOLVED" "$PLAN_REPO" || lc_abort plan-repo-mismatch 2 "detail=resolved-repo-differs resolved=$ISSUES_RESOLVED"
|
|
782
|
+
lc_issues_origin_check
|
|
783
|
+
if [ "$ISSUES_VIS" != PRIVATE ] && [ "$ISSUES_CONFIRM_PUBLIC" != 1 ]; then
|
|
784
|
+
lc__fmt confirm_public_fix; lc_abort confirm-public-required 2 "visibility=$ISSUES_VIS"
|
|
785
|
+
fi
|
|
786
|
+
lc_issues_stale_check "$PLAN_REPHASH" "$PLAN_CATHASH"
|
|
787
|
+
# An exists or capped row carries no body file, so nothing else ties it to this catalog: it must name a catalog check that is a gap now.
|
|
788
|
+
F_CAT="$WORK/cat.ids" F_GAPS="$WORK/gaps.tsv" awk -F'\t' '
|
|
789
|
+
FILENAME == ENVIRON["F_CAT"] { c[$1] = 1; next }
|
|
790
|
+
FILENAME == ENVIRON["F_GAPS"] { g[$2] = 1; next }
|
|
791
|
+
($5 == "capped" || $5 == "exists") && (!($1 in c) || !($1 in g)) { bad = 1 }
|
|
792
|
+
END { exit bad }' "$WORK/cat.ids" "$WORK/gaps.tsv" "$WORK/plan.rows.tsv" || lc__pbad row-id
|
|
793
|
+
sort "$WORK/plan.create.ids" > "$WORK/plan.create.sorted"
|
|
794
|
+
[ -z "$(comm -23 "$WORK/plan.create.sorted" "$WORK/open.ids")" ] || { lc__fmt report_stale_fix; lc_abort report-stale 2 "detail=row-not-open"; }
|
|
795
|
+
|
|
796
|
+
# Regenerate every title and body from the catalog, facts and ids, and byte-compare with the plan copy.
|
|
797
|
+
mkdir -p "$WORK/regen/issues"
|
|
798
|
+
: > "$WORK/blob"
|
|
799
|
+
while IFS=$'\t' read -r _ id dom cls sev title ev clos rem; do
|
|
800
|
+
grep -qxF "$id" "$WORK/plan.create.ids" || continue
|
|
801
|
+
[ "$(awk -F'\t' -v i="$id" '$1 == i' "$WORK/plan.rows.tsv")" = "$(printf '%s\t%s\t%s\t%s\tcreate\t%s' "$id" "$sev" "$dom" "$cls" "$title")" ] || lc_abort plan-invalid 2 "detail=row-mismatch"
|
|
802
|
+
lc_issue_body "$id" "$sev" "$dom" "$cls" "$title" "$ev" "$clos" "$rem" > "$WORK/regen/issues/$id.md"
|
|
803
|
+
cmp -s "$WORK/regen/issues/$id.md" "$ISSUES_PLAN_DIR/issues/$id.md" || lc_abort plan-invalid 2 "detail=body-mismatch"
|
|
804
|
+
done < "$WORK/gaps.tsv"
|
|
805
|
+
[ "$(find "$WORK/regen/issues" -type f | wc -l | tr -d ' ')" = "$PLAN_CREATE_N" ] || lc_abort plan-invalid 2 "detail=row-mismatch"
|
|
806
|
+
lc_epic_initial > "$WORK/regen/epic.md"
|
|
807
|
+
cmp -s "$WORK/regen/epic.md" "$ISSUES_PLAN_DIR/epic.md" || lc_abort plan-invalid 2 "detail=epic-mismatch"
|
|
808
|
+
|
|
809
|
+
# Authored bytes are scanned bytes: one blob in send order, before the first write.
|
|
810
|
+
want=$(lc__labels_for "$WORK/plan.rows.tsv")
|
|
811
|
+
while IFS=$'\t' read -r id sev dom cls act title; do
|
|
812
|
+
[ "$act" = create ] || continue
|
|
813
|
+
{ printf '%s\n' "$title"; cat "$ISSUES_PLAN_DIR/issues/$id.md"; } >> "$WORK/blob"
|
|
814
|
+
done < "$WORK/plan.rows.tsv"
|
|
815
|
+
{ lc_epic_title; cat "$ISSUES_PLAN_DIR/epic.md"; } >> "$WORK/blob"
|
|
816
|
+
for lbl in $want; do printf '%s\n%s\n' "$lbl" "$(lc__label_desc "$lbl")" >> "$WORK/blob"; done
|
|
817
|
+
# The blob is the concatenation of exactly the files that are sent (title line, then the file), in send order, read from the
|
|
818
|
+
# private copy that is also the only place the writes read from; scanning each file again would only repeat it.
|
|
819
|
+
lc_emit_checked "$WORK/blob" "" 1
|
|
820
|
+
|
|
821
|
+
# Live state decides what exists.
|
|
822
|
+
lc_issues_live
|
|
823
|
+
lc_live_tables
|
|
824
|
+
lc__live_gate
|
|
825
|
+
if [ "$EPIC_CANDIDATES" = 1 ]; then
|
|
826
|
+
EPIC_NUM=$(cut -f1 "$WORK/live.epics"); EPIC_REF="#$EPIC_NUM"
|
|
827
|
+
if [ "$(cut -f3 "$WORK/live.epics")" = closed ]; then lc__fmt epic_closed_fix; lc_abort epic-closed 2 "detail=epic-closed"; fi
|
|
828
|
+
lc_gh_read api user --jq '.login' || lc__incomplete lookup "$LC_GH_KIND"
|
|
829
|
+
[ "$(cut -f4 "$WORK/live.epics")" = "$(awk 'NR == 1 { print; exit }' "$WORK/gh.out")" ] || { lc__fmt epic_author_fix; lc_abort plan-invalid 2 "detail=epic-author"; }
|
|
830
|
+
fi
|
|
831
|
+
|
|
832
|
+
if [ "${LC_DRY:-0}" = 1 ]; then
|
|
833
|
+
while IFS=$'\t' read -r id sev dom cls act title; do
|
|
834
|
+
[ "$act" = create ] || continue
|
|
835
|
+
grep -q "^$id$LC_TAB" "$WORK/live.items" || lc__say "would file: $id | $sev | $title"
|
|
836
|
+
done < "$WORK/plan.rows.tsv"
|
|
837
|
+
lc__fmt dry_run_note
|
|
838
|
+
lc__summary dry-run
|
|
839
|
+
return 0
|
|
840
|
+
fi
|
|
841
|
+
|
|
842
|
+
# Labels: only names absent from a fresh listing are created; an existing label is never touched, and nothing is created
|
|
843
|
+
# when the plan files nothing.
|
|
844
|
+
[ "$PLAN_CREATE_N" -gt 0 ] || want=""
|
|
845
|
+
lc_gh_read api "repos/$ISSUES_REPO/labels" -f per_page=100 --paginate --jq '.[].name' || lc__incomplete lookup "$LC_GH_KIND"
|
|
846
|
+
tr '[:upper:]' '[:lower:]' < "$WORK/gh.out" > "$WORK/labels.have"
|
|
847
|
+
for lbl in $want; do
|
|
848
|
+
grep -qxF "$lbl" "$WORK/labels.have" && continue
|
|
849
|
+
if ! lc_gh_write api -X POST "repos/$ISSUES_REPO/labels" -f "name=$lbl" -f "color=$(lc__label_color "$lbl")" -f "description=$(lc__label_desc "$lbl")"; then
|
|
850
|
+
grep -q 'already_exists' "$WORK/gh.out" || lc__incomplete create "$LC_GH_KIND"
|
|
851
|
+
fi
|
|
852
|
+
done
|
|
853
|
+
|
|
854
|
+
# The epic.
|
|
855
|
+
if [ -z "$EPIC_NUM" ]; then
|
|
856
|
+
if [ "$PLAN_CREATE_N" -gt 0 ]; then
|
|
857
|
+
lc_gh_write api -X POST "repos/$ISSUES_REPO/issues" -f "title=$(lc_epic_title)" -F "body=@$ISSUES_PLAN_DIR/epic.md" \
|
|
858
|
+
-f 'labels[]=lc:launch-check' -f 'labels[]=lc:epic' --jq '[.number, .id] | @tsv' || lc__incomplete epic "$LC_GH_KIND"
|
|
859
|
+
lc__parse_pair || lc__incomplete epic failed
|
|
860
|
+
EPIC_NUM=$NEW_NUM; EPIC_REF="#$EPIC_NUM"; made_epic=1
|
|
861
|
+
printf 'EPIC\t%s\thttps://%s/%s/issues/%s\n' "$NEW_NUM" "$ISSUES_HOST" "$ISSUES_REPO" "$NEW_NUM" >> "$ISSUES_ORIG_PLAN_DIR/created.tsv" || lc__record_failed
|
|
862
|
+
lc_issues_live
|
|
863
|
+
lc_live_tables
|
|
864
|
+
lc__live_gate
|
|
865
|
+
fi
|
|
866
|
+
fi
|
|
867
|
+
|
|
868
|
+
# Orphans: a live open item the plan names that is not under the epic yet is linked, never recreated.
|
|
869
|
+
if [ -n "$EPIC_NUM" ]; then
|
|
870
|
+
: > "$WORK/children"
|
|
871
|
+
if [ "$made_epic" = 0 ]; then
|
|
872
|
+
if lc_gh_read api "repos/$ISSUES_REPO/issues/$EPIC_NUM/sub_issues" --paginate --jq '.[].number'; then cp "$WORK/gh.out" "$WORK/children"
|
|
873
|
+
else lc__link_failed; fi
|
|
874
|
+
fi
|
|
875
|
+
fi
|
|
876
|
+
if [ "$ISSUES_FALLBACK" = none ] && [ -n "$EPIC_NUM" ]; then
|
|
877
|
+
F_ROWS="$WORK/plan.rows.tsv" F_LIVE="$WORK/live.items" F_KIDS="$WORK/children" awk -F'\t' -v OFS='\t' '
|
|
878
|
+
FILENAME == ENVIRON["F_ROWS"] { if ($5 == "create" || $5 == "exists") want[$1] = 1; next }
|
|
879
|
+
FILENAME == ENVIRON["F_KIDS"] { kid[$1] = 1; next }
|
|
880
|
+
$4 == "open" && ($1 in want) && !($2 in kid) { print $3, $2, $1 }' "$WORK/plan.rows.tsv" "$WORK/children" "$WORK/live.items" > "$WORK/orphans.ids" || lc__incomplete link malformed
|
|
881
|
+
while IFS=$'\t' read -r k num id; do
|
|
882
|
+
[ -n "$k" ] || continue
|
|
883
|
+
[ "$ISSUES_FALLBACK" = none ] || break
|
|
884
|
+
lc__link "$k" "$num" "$id"
|
|
885
|
+
done < "$WORK/orphans.ids"
|
|
886
|
+
fi
|
|
887
|
+
|
|
888
|
+
# The items, in the saved order. The first failed write stops the run.
|
|
889
|
+
while IFS=$'\t' read -r id sev dom cls act title; do
|
|
890
|
+
[ "$act" = create ] || continue
|
|
891
|
+
if grep -q "^$id$LC_TAB" "$WORK/live.items"; then CNT_SKIPPED=$((CNT_SKIPPED + 1)); continue; fi
|
|
892
|
+
if ! lc_gh_write api -X POST "repos/$ISSUES_REPO/issues" -f "title=$title" -F "body=@$ISSUES_PLAN_DIR/issues/$id.md" \
|
|
893
|
+
-f 'labels[]=lc:launch-check' -f "labels[]=lc:severity-$sev" -f "labels[]=lc:domain-$dom" --jq '[.number, .id] | @tsv'; then
|
|
894
|
+
FAILED_IDS=$id; lc__incomplete create "$LC_GH_KIND"
|
|
895
|
+
fi
|
|
896
|
+
if ! lc__parse_pair; then FAILED_IDS=$id; lc__incomplete create failed; fi
|
|
897
|
+
printf '%s\t%s\thttps://%s/%s/issues/%s\n' "$id" "$NEW_NUM" "$ISSUES_HOST" "$ISSUES_REPO" "$NEW_NUM" >> "$ISSUES_ORIG_PLAN_DIR/created.tsv" || lc__record_failed
|
|
898
|
+
printf '%s\t%s\n' "$id" "$NEW_NUM" >> "$WORK/made.tsv" || lc__record_failed
|
|
899
|
+
CNT_CREATED=$((CNT_CREATED + 1))
|
|
900
|
+
lc__say "created: #$NEW_NUM $id"
|
|
901
|
+
if [ "$ISSUES_FALLBACK" = none ]; then lc__link "$NEW_ID" "$NEW_NUM" "$id"; fi
|
|
902
|
+
done < "$WORK/plan.rows.tsv"
|
|
903
|
+
|
|
904
|
+
lc__epic_update
|
|
905
|
+
lc__summary complete
|
|
906
|
+
[ "$EPIC_STATE" != markers-damaged ] || lc__fmt markers_damaged_hint
|
|
907
|
+
return 0
|
|
908
|
+
}
|