-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrubyish-post-edit.sh
More file actions
executable file
·68 lines (56 loc) · 1.98 KB
/
rubyish-post-edit.sh
File metadata and controls
executable file
·68 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
set -o nounset
set -o pipefail
# Delegated Ruby-ish post-edit entrypoint.
# Policy: fail closed on malformed payloads or missing delegates, but aggregate
# delegate diagnostics so one failure does not mask later high-signal warnings.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_LIB="${SCRIPT_DIR}/workspace-root-lib.sh"
emit_missing_dependency_block() {
local dependency="$1"
echo "BLOCKED: rubyish-post-edit.sh cannot inspect Ruby edits because ${dependency} is unavailable." >&2
echo "Restore the dependency or disable the delegated post-edit hook explicitly before continuing." >&2
exit 2
}
[[ -r "$ROOT_LIB" && ! -L "$ROOT_LIB" ]] || emit_missing_dependency_block "workspace-root-lib.sh"
# shellcheck disable=SC1090,SC1091
source "$ROOT_LIB"
read_hook_input
INPUT="$HOOK_INPUT_VALUE"
case "${HOOK_INPUT_STATUS:-empty}" in
truncated|invalid)
if [[ "${HOOK_INPUT_STATUS}" == "invalid" ]]; then
echo "BLOCKED: rubyish-post-edit.sh could not safely inspect an invalid hook payload." >&2
else
echo "BLOCKED: rubyish-post-edit.sh could not safely inspect a truncated hook payload." >&2
fi
echo "Fix the hook input before retrying delegated Ruby post-edit hooks." >&2
exit 2
;;
esac
STATUS=0
FAILURES=0
run_hook() {
local target="$1"
local code=0
[[ -f "$target" && ! -L "$target" ]] || emit_missing_dependency_block "$(path_basename "$target")"
printf '%s' "$INPUT" | "$target"
code=$?
if [[ "$code" -ne 0 ]]; then
FAILURES=$((FAILURES + 1))
if [[ "$code" -eq 2 ]]; then
STATUS=2
elif [[ "$STATUS" -eq 0 ]]; then
STATUS=$code
fi
fi
return 0
}
run_hook "${SCRIPT_DIR}/iron-law-verifier.sh"
run_hook "${SCRIPT_DIR}/format-ruby.sh"
run_hook "${SCRIPT_DIR}/verify-ruby.sh"
run_hook "${SCRIPT_DIR}/debug-statement-warning.sh"
if [[ "$FAILURES" -gt 1 ]]; then
echo "BLOCKED: rubyish-post-edit.sh saw ${FAILURES} delegated post-edit failures; see diagnostics above." >&2
fi
exit "$STATUS"