|
27 | 27 | # is posted when nothing was triaged. |
28 | 28 | # |
29 | 29 | # Usage: |
30 | | -# test-classifier-dispatcher.sh # auto-discover PR; print only |
| 30 | +# test-classifier-dispatcher.sh # no args → --unpushed (local committed+staged, report-only) |
| 31 | +# test-classifier-dispatcher.sh origin/main # bare ref → --against origin/main |
31 | 32 | # test-classifier-dispatcher.sh --pr 1234 --post-comment # post the PR comment |
32 | 33 | # test-classifier-dispatcher.sh --pr 1234 --submit # post + prompt "helpful?" + append a Testing Events row |
33 | 34 | # test-classifier-dispatcher.sh --against origin/main # explicit base ref |
@@ -154,6 +155,49 @@ while [[ $# -gt 0 ]]; do |
154 | 155 | esac |
155 | 156 | done |
156 | 157 |
|
| 158 | +# ── Convenience defaulting (so callers/wrappers stay dumb) ────────────────── |
| 159 | +# The shell wrapper that fronts this dispatcher is a one-line passthrough; the |
| 160 | +# ergonomic defaults live HERE so they're versioned with the bundle and never |
| 161 | +# drift out of a hand-pasted ~/.zshrc function. Applied only when the caller |
| 162 | +# gave no diff-range/PR selector (--against / --unpushed / --pr) of its own: |
| 163 | +# |
| 164 | +# • a bare ref (e.g. `origin/main`) → --against <ref> (classify <ref>..HEAD) |
| 165 | +# • otherwise → --unpushed (committed + staged, |
| 166 | +# local report-only backstop) |
| 167 | +# |
| 168 | +# Other flags (--dry-run, --json-only, --post-comment, …) pass through unchanged. |
| 169 | +# |
| 170 | +# We detect "did the caller already choose a range/PR?" by scanning the args |
| 171 | +# bound for the lib for --against/--unpushed, plus our own --pr. If any is |
| 172 | +# present we add nothing. This runs BEFORE discover_pr_context, which inspects |
| 173 | +# REMAINING_FOR_LIB for --against/--unpushed to decide whether to skip PR lookup. |
| 174 | +ai_classifier::has_range_selector() { |
| 175 | + [[ -n "${PR_NUMBER}" ]] && return 0 |
| 176 | + local a |
| 177 | + for a in "${REMAINING_FOR_LIB[@]+"${REMAINING_FOR_LIB[@]}"}"; do |
| 178 | + case "$a" in |
| 179 | + --against|--against=*|--unpushed) return 0 ;; |
| 180 | + esac |
| 181 | + done |
| 182 | + return 1 |
| 183 | +} |
| 184 | + |
| 185 | +if ! ai_classifier::has_range_selector; then |
| 186 | + # A bare positional (doesn't start with '-') is a base ref; the lib would |
| 187 | + # otherwise drop it into AI_REVIEW_REMAINING and ignore it. Rewrite it to |
| 188 | + # --against and keep any other flags (--dry-run, --json-only, …) intact. |
| 189 | + bare_ref="" rest=() |
| 190 | + for a in "${REMAINING_FOR_LIB[@]+"${REMAINING_FOR_LIB[@]}"}"; do |
| 191 | + if [[ -z "${bare_ref}" && "${a#-}" == "${a}" ]]; then bare_ref="$a"; else rest+=("$a"); fi |
| 192 | + done |
| 193 | + if [[ -n "${bare_ref}" ]]; then |
| 194 | + REMAINING_FOR_LIB=("--against" "${bare_ref}" "${rest[@]+"${rest[@]}"}") |
| 195 | + else |
| 196 | + # No range/PR/ref anywhere → default to the local unpushed backstop. |
| 197 | + REMAINING_FOR_LIB+=("--unpushed") |
| 198 | + fi |
| 199 | +fi |
| 200 | + |
157 | 201 | # ── PR / base-ref discovery (mirrors the security dispatcher) ─────────────── |
158 | 202 | require_gh_cli() { |
159 | 203 | local why="$1" |
|
0 commit comments