chore: triage review findings
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmpdir"' EXIT
|
||||
|
||||
curl_log="$tmpdir/curl.log"
|
||||
bin_dir="$tmpdir/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
|
||||
cat >"$bin_dir/curl" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
log_file="${CURL_LOG:?}"
|
||||
printf '%s\n' "$*" >>"$log_file"
|
||||
|
||||
last_arg="${!#}"
|
||||
|
||||
if [[ " $* " == *" -X DELETE "* ]]; then
|
||||
printf '204'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$last_arg" in
|
||||
*page=1)
|
||||
printf '%s' '[{"id":4,"tag_name":"v4","name":"release-4","created_at":"2024-04-01T00:00:00Z"},{"id":3,"tag_name":"v3","name":"release-3","created_at":"2024-03-01T00:00:00Z"}]'
|
||||
;;
|
||||
*page=2)
|
||||
printf '%s' '[{"id":2,"tag_name":"v2","name":"release-2","created_at":"2024-02-01T00:00:00Z"},{"id":1,"tag_name":"v1","name":"release-1","created_at":"2024-01-01T00:00:00Z"}]'
|
||||
;;
|
||||
*page=3)
|
||||
printf '%s' '[]'
|
||||
;;
|
||||
*)
|
||||
printf 'unexpected request: %s\n' "$last_arg" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$bin_dir/curl"
|
||||
|
||||
cat >"$bin_dir/jq.py" <<'PY'
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
expr = ""
|
||||
flags = set()
|
||||
args = sys.argv[1:]
|
||||
|
||||
while args:
|
||||
current = args.pop(0)
|
||||
if current in {"-e", "-c", "-r", "-s"}:
|
||||
flags.add(current)
|
||||
continue
|
||||
if current == "--":
|
||||
if not args:
|
||||
raise SystemExit("missing jq expression")
|
||||
expr = args.pop(0)
|
||||
break
|
||||
if current.startswith("-"):
|
||||
flags.add(current)
|
||||
continue
|
||||
expr = current
|
||||
break
|
||||
|
||||
raw = sys.stdin.read()
|
||||
|
||||
def dump(value):
|
||||
if "-r" in flags and isinstance(value, (str, int, float)) and not isinstance(value, bool):
|
||||
sys.stdout.write(str(value))
|
||||
else:
|
||||
sys.stdout.write(json.dumps(value, separators=(",", ":")))
|
||||
|
||||
if expr == "length":
|
||||
data = json.loads(raw or "null")
|
||||
print(len(data))
|
||||
raise SystemExit(0)
|
||||
|
||||
if expr == "add":
|
||||
arrays = [json.loads(line) for line in raw.splitlines() if line.strip()]
|
||||
merged = []
|
||||
for item in arrays:
|
||||
merged.extend(item)
|
||||
dump(merged)
|
||||
raise SystemExit(0)
|
||||
|
||||
if expr == "sort_by(.created_at) | reverse":
|
||||
data = json.loads(raw or "[]")
|
||||
dump(sorted(data, key=lambda item: item["created_at"], reverse=True))
|
||||
raise SystemExit(0)
|
||||
|
||||
match = re.fullmatch(r"\.\[(\d+):\]", expr)
|
||||
if match:
|
||||
data = json.loads(raw or "[]")
|
||||
dump(data[int(match.group(1)):])
|
||||
raise SystemExit(0)
|
||||
|
||||
if expr == ".[]":
|
||||
data = json.loads(raw or "[]")
|
||||
for item in data:
|
||||
dump(item)
|
||||
sys.stdout.write("\n")
|
||||
raise SystemExit(0)
|
||||
|
||||
match = re.fullmatch(r"\.(id|tag_name|name)", expr)
|
||||
if match:
|
||||
data = json.loads(raw or "null")
|
||||
value = data.get(match.group(1))
|
||||
dump(value)
|
||||
raise SystemExit(0)
|
||||
|
||||
raise SystemExit(f"unsupported jq expression: {expr}")
|
||||
PY
|
||||
chmod +x "$bin_dir/jq.py"
|
||||
|
||||
cat >"$bin_dir/jq" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
exec python3 "$0.py" "$@"
|
||||
EOF
|
||||
chmod +x "$bin_dir/jq"
|
||||
|
||||
PATH="$bin_dir:$PATH" \
|
||||
CURL_LOG="$curl_log" \
|
||||
GITEA_SERVER_URL="https://gitea.example.test" \
|
||||
GITEA_REPOSITORY="owner/repo" \
|
||||
KEEP_COUNT="2" \
|
||||
RUNNER_TOKEN="" \
|
||||
bash ./entrypoint.sh >/dev/null
|
||||
|
||||
grep -q 'page=1' "$curl_log"
|
||||
grep -q 'page=2' "$curl_log"
|
||||
grep -q 'page=3' "$curl_log"
|
||||
grep -q '/releases/2' "$curl_log"
|
||||
grep -q '/releases/1' "$curl_log"
|
||||
|
||||
if grep -q '/releases/3' "$curl_log" || grep -q '/releases/4' "$curl_log"; then
|
||||
printf 'unexpected deletion request in %s\n' "$curl_log" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user