feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# lib/forge-forgejo.sh — the Forgejo backend: /api/v1 over curl + jq
|
|
|
|
|
# (issue #188, term 1). Sourced by lib/forge.sh when forge_detect says
|
|
|
|
|
# forgejo; never sourced directly, and never at the same time as the github
|
|
|
|
|
# backend — they define the same verbs on purpose.
|
|
|
|
|
#
|
|
|
|
|
# curl+jq rather than a CLI because that is what the runner has. The image
|
|
|
|
|
# this instance runs jobs in (ghcr.io/catthehacker/ubuntu:act-22.04, probe
|
|
|
|
|
# task 278) carries curl, jq and node, and has neither `gh` nor `stoke`.
|
|
|
|
|
|
|
|
|
|
# forgejo_api_base — the /api/v1 root, from the runner's own environment.
|
|
|
|
|
# GITHUB_API_URL already IS the /api/v1 root on a Forgejo runner (measured:
|
|
|
|
|
# https://forgejo.heavyduty.builders/api/v1). CEREMONY_FORGE_API overrides
|
|
|
|
|
# it for tests and for anyone driving this outside Actions.
|
|
|
|
|
forgejo_api_base() {
|
|
|
|
|
local base="${CEREMONY_FORGE_API:-${GITHUB_API_URL:-}}"
|
|
|
|
|
if [ -z "$base" ]; then
|
|
|
|
|
echo "forgejo_api_base: no GITHUB_API_URL or CEREMONY_FORGE_API — cannot reach the forge (#188)" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
printf '%s\n' "${base%/}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forgejo_page_url <endpoint> <page> — pure, so the page-size contract is
|
|
|
|
|
# testable without a network. Returns the endpoint with this backend's OWN
|
|
|
|
|
# paging parameters applied.
|
|
|
|
|
#
|
|
|
|
|
# THE TRAP THIS EXISTS TO REMOVE, measured 2026-08-02 against
|
|
|
|
|
# heavy-duty/rig (137 issues and PRs) and heavy-duty/ceremony on GitHub:
|
|
|
|
|
#
|
|
|
|
|
# ?per_page=100 GitHub: 100 items Forgejo: 30 items (IGNORED)
|
|
|
|
|
# ?limit=100 GitHub: 30 items Forgejo: 50 items (capped)
|
|
|
|
|
#
|
|
|
|
|
# Each forge silently ignores the other's page-size parameter, answers
|
|
|
|
|
# HTTP 200 with valid JSON, and says nothing. Every call site in this repo
|
|
|
|
|
# was written GitHub-shaped, so a verbatim port would have swept 30 of
|
|
|
|
|
# rig's 137 and printed "reconciled." — acceptance criterion 2 failing
|
|
|
|
|
# green, and the same "degraded read that does not report it degraded"
|
|
|
|
|
# failure class this whole issue exists to kill.
|
|
|
|
|
#
|
|
|
|
|
# So NO CALL SITE NAMES A PAGE SIZE. The backend owns it. Fixing the
|
|
|
|
|
# boundary once beats fixing nine call sites and trusting the tenth — the
|
|
|
|
|
# same argument that chose shape C over B, one level down.
|
|
|
|
|
#
|
|
|
|
|
# 50 is not a preference: Forgejo caps a page at MAX_RESPONSE_ITEMS (50 on
|
|
|
|
|
# this instance) whatever you ask for, so asking for more cannot help and
|
|
|
|
|
# pagination is mandatory rather than an optimisation.
|
|
|
|
|
forgejo_page_url() {
|
|
|
|
|
local endpoint="${1:?forgejo_page_url: endpoint required}" page="${2:?forgejo_page_url: page required}"
|
|
|
|
|
# Strip any page-size parameter a caller left behind, in either dialect,
|
|
|
|
|
# rather than trusting that none did: this function is the one place that
|
|
|
|
|
# decides paging, and a stray per_page= would be exactly the silent
|
|
|
|
|
# truncation above.
|
|
|
|
|
local clean="$endpoint"
|
|
|
|
|
clean="$(printf '%s' "$clean" | sed -E 's/([?&])(per_page|limit|page)=[0-9]+/\1/g; s/[?&]+$//; s/([?&])&+/\1/g')"
|
|
|
|
|
case "$clean" in
|
|
|
|
|
*\?) printf '%slimit=50&page=%s\n' "$clean" "$page" ;;
|
|
|
|
|
*\?*) printf '%s&limit=50&page=%s\n' "$clean" "$page" ;;
|
|
|
|
|
*) printf '%s?limit=50&page=%s\n' "$clean" "$page" ;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forge_api [--paginate] <endpoint> [--jq <expr>]
|
|
|
|
|
#
|
|
|
|
|
# --paginate walks page= until a short page, then PROVES the walk was
|
|
|
|
|
# complete by comparing what it collected against the server's declared
|
|
|
|
|
# x-total-count. @kimi-reviewer-andresmgsl's hardening (#4699): a MISSING
|
|
|
|
|
# header is a loud refusal, not a pass. Header exposure is a server setting
|
|
|
|
|
# (access-control-expose-headers), and an instance that withholds it would
|
|
|
|
|
# make the completeness check compare null to a number — the guard itself
|
|
|
|
|
# degrading silently, which is the failure class re-entering through the
|
|
|
|
|
# door built to stop it.
|
|
|
|
|
forge_api() {
|
|
|
|
|
local paginate=false endpoint="" jqexpr="" have_jq=false
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--paginate) paginate=true ;;
|
|
|
|
|
--jq) jqexpr="$2"; have_jq=true; shift ;;
|
|
|
|
|
-*) ;;
|
|
|
|
|
*) [ -n "$endpoint" ] || endpoint="$1" ;;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
[ -n "$endpoint" ] || { echo "forge_api: endpoint required" >&2; return 1; }
|
|
|
|
|
|
|
|
|
|
local base token
|
|
|
|
|
base="$(forgejo_api_base)" || return 1
|
|
|
|
|
token="${GH_TOKEN:-${GITHUB_TOKEN:-${FORGEJO_TOKEN:-}}}"
|
|
|
|
|
|
|
|
|
|
local hdr body
|
|
|
|
|
hdr="$(mktemp)"; body="$(mktemp)"
|
|
|
|
|
# shellcheck disable=SC2064 # the paths are fixed at trap time on purpose
|
|
|
|
|
trap "rm -f '$hdr' '$body'" RETURN
|
|
|
|
|
|
|
|
|
|
if [ "$paginate" = false ]; then
|
|
|
|
|
if ! curl -sS -D "$hdr" -o "$body" \
|
|
|
|
|
-H "Authorization: token $token" -H 'Accept: application/json' \
|
|
|
|
|
"$base/$endpoint"; then
|
|
|
|
|
echo "forge_api: request failed: $endpoint" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
forgejo_http_ok "$hdr" "$endpoint" || return 1
|
|
|
|
|
if [ "$have_jq" = true ]; then jq -r "$jqexpr" <"$body"; else cat "$body"; fi
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Paginated: accumulate into ONE array and apply --jq once at the end.
|
|
|
|
|
# gh --paginate applies --jq per page and concatenates; for the `.[] | …`
|
|
|
|
|
# shapes every call site here uses, the two are identical, and merging
|
|
|
|
|
# first is what makes the completeness assert possible at all.
|
|
|
|
|
local page=1 total="" got=0 n all="[]" pagejson
|
|
|
|
|
while :; do
|
|
|
|
|
if ! curl -sS -D "$hdr" -o "$body" \
|
|
|
|
|
-H "Authorization: token $token" -H 'Accept: application/json' \
|
|
|
|
|
"$base/$(forgejo_page_url "$endpoint" "$page")"; then
|
|
|
|
|
echo "forge_api: request failed: $endpoint (page $page)" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
forgejo_http_ok "$hdr" "$endpoint" || return 1
|
|
|
|
|
|
2026-08-02 19:07:32 +00:00
|
|
|
# Re-read on EVERY page, not once (#4712). A board that changes size
|
|
|
|
|
# under the walk was invisible: page 1 declaring 4 and page 2 declaring
|
|
|
|
|
# 9 stopped at 4 believing itself whole. A moving total means the read
|
|
|
|
|
# cannot have been atomic, so it is refused rather than reconciled.
|
|
|
|
|
local page_total
|
|
|
|
|
page_total="$(forgejo_total_count "$hdr")" || return 1
|
feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
if [ -z "$total" ]; then
|
2026-08-02 19:07:32 +00:00
|
|
|
total="$page_total"
|
|
|
|
|
elif [ "$page_total" != "$total" ]; then
|
|
|
|
|
cat >&2 <<EOF
|
|
|
|
|
forge_api: the declared total for '$endpoint' changed between pages — $total then $page_total (#188).
|
|
|
|
|
The collection moved under the walk, so no page set can be proven whole.
|
|
|
|
|
Refusing rather than reconciling a board that is already out of date.
|
|
|
|
|
EOF
|
|
|
|
|
return 1
|
feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
fi
|
2026-08-02 19:07:32 +00:00
|
|
|
|
feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
pagejson="$(cat "$body")"
|
2026-08-02 19:07:32 +00:00
|
|
|
# A 200 whose body is not a collection counted as zero items (#4712),
|
|
|
|
|
# so an error object or a scalar arriving where a list belongs read as
|
|
|
|
|
# a complete EMPTY collection whenever the declared total was 0.
|
|
|
|
|
if [ "$(jq -r 'type' <<<"$pagejson" 2>/dev/null)" != array ]; then
|
|
|
|
|
cat >&2 <<EOF
|
|
|
|
|
forge_api: '$endpoint' did not return a collection (#188).
|
|
|
|
|
Expected a JSON array; got: $(head -c 200 <<<"$pagejson")
|
|
|
|
|
Refusing: a body this shim cannot count must not be counted as empty.
|
|
|
|
|
EOF
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
n="$(jq 'length' <<<"$pagejson")"
|
feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
[ "$n" -gt 0 ] || break
|
|
|
|
|
all="$(jq -s '.[0] + .[1]' <<<"$all"$'\n'"$pagejson")"
|
|
|
|
|
got=$((got + n))
|
|
|
|
|
[ "$got" -lt "$total" ] || break
|
|
|
|
|
page=$((page + 1))
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# The assert. A short read here is the silent-truncation bug arriving by
|
|
|
|
|
# another route, so it is fatal rather than a warning.
|
|
|
|
|
if [ "$got" -ne "$total" ]; then
|
|
|
|
|
cat >&2 <<EOF
|
|
|
|
|
forge_api: incomplete gather for '$endpoint' — collected $got of $total declared (#188).
|
|
|
|
|
Refusing rather than reconciling a partial board: a sweep over part of the
|
|
|
|
|
queue that reports success is the failure this shim exists to prevent.
|
|
|
|
|
EOF
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "$have_jq" = true ]; then jq -r "$jqexpr" <<<"$all"; else printf '%s\n' "$all"; fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forgejo_total_count <header-file> — the declared size of the collection.
|
|
|
|
|
# Absent is fatal (#4699): without it the completeness assert cannot run,
|
|
|
|
|
# and an assert that cannot run must not silently pass.
|
|
|
|
|
forgejo_total_count() {
|
|
|
|
|
local hdr="$1" total
|
|
|
|
|
total="$(tr -d '\r' <"$hdr" | awk 'tolower($1) == "x-total-count:" { print $2 }' | tail -n1)"
|
|
|
|
|
if [ -z "$total" ]; then
|
|
|
|
|
cat >&2 <<EOF
|
|
|
|
|
forge_api: this forge did not send x-total-count — cannot prove the gather is complete (#188).
|
|
|
|
|
The header is exposed by a server setting (access-control-expose-headers).
|
|
|
|
|
Refusing: an unprovable read must not be reported as a whole one.
|
|
|
|
|
EOF
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
2026-08-02 19:07:32 +00:00
|
|
|
# Validate before it reaches arithmetic (#4712). `X-Total-Count:
|
|
|
|
|
# not-a-number` used to sail through and become the bound the walk was
|
|
|
|
|
# compared against — a guard whose own input was never checked.
|
|
|
|
|
case "$total" in
|
|
|
|
|
'' | *[!0-9]*)
|
|
|
|
|
cat >&2 <<EOF
|
|
|
|
|
forge_api: x-total-count is not a non-negative integer: '$total' (#188).
|
|
|
|
|
Refusing: the completeness bound must be a number, or the assert that
|
|
|
|
|
uses it proves nothing.
|
|
|
|
|
EOF
|
|
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
feat(forge): two backends behind one call surface, and the shim owns paging
Term 1's foundation. lib/forge.sh gains forge_select, which sources exactly
one of lib/forge-github.sh or lib/forge-forgejo.sh; both define the same
verbs, so no branching reaches the 61 call sites. The github backend is the
current gh invocation extracted 1:1 — term 5 is kept by making that path
boring.
The page size moves OUT of the call sites and into the backend, because it
is not portable and fails silently. Measured 2026-08-02:
?per_page=100 GitHub 100 items Forgejo 30 items (ignored)
?limit=100 GitHub 30 items Forgejo 50 items (capped)
Both answer HTTP 200 with valid JSON. Every call site here is GitHub-shaped,
so a verbatim port would have swept 30 of rig's 137 issues and printed
"reconciled." — criterion 2 failing green, the same failure class as the
blind sweep. Both page_url helpers strip a stray page-size parameter in
either dialect, so a call site cannot reintroduce it by accident.
Forgejo caps a page at 50 whatever is asked, so pagination is mandatory, not
an optimisation. The gather is then PROVEN complete against x-total-count
rather than assumed complete because a loop ended.
@kimi-reviewer-andresmgsl's hardening (#4699): a missing x-total-count is
itself a loud refusal. Header exposure is a server setting, and an assert
that cannot run must not silently pass — that is the failure class
re-entering through the guard built to stop it.
Call sites are not ported yet; that is the next commit.
Refs #188
2026-08-02 19:00:58 +00:00
|
|
|
printf '%s\n' "$total"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forgejo_http_ok <header-file> <endpoint> — a non-2xx is named, not
|
|
|
|
|
# swallowed. gh exits non-zero on HTTP failure; curl does not without -f,
|
|
|
|
|
# and -f would throw away the body that says why.
|
|
|
|
|
forgejo_http_ok() {
|
|
|
|
|
local hdr="$1" endpoint="$2" code
|
|
|
|
|
code="$(tr -d '\r' <"$hdr" | awk '/^HTTP\// { c = $2 } END { print c }')"
|
|
|
|
|
case "$code" in
|
|
|
|
|
2*) return 0 ;;
|
|
|
|
|
*)
|
|
|
|
|
echo "forge_api: HTTP $code from '$endpoint'" >&2
|
|
|
|
|
return 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
|
|
|
|
|
# --- the verbs the reconcilers use, over /api/v1 --------------------------
|
|
|
|
|
# Three asymmetries with gh, all measured against this instance on
|
|
|
|
|
# 2026-08-02 using a scratch repo (never a live board):
|
|
|
|
|
#
|
|
|
|
|
# 1. Adding labels takes NAMES POST /issues/{n}/labels {"labels":["x"]} -> 200
|
|
|
|
|
# Removing one takes a numeric ID DELETE /issues/{n}/labels/x -> 422
|
|
|
|
|
# DELETE /issues/{n}/labels/149 -> 204
|
|
|
|
|
# So a removal must resolve name -> id first. gh hides this; the shim
|
|
|
|
|
# cannot.
|
|
|
|
|
#
|
|
|
|
|
# 2. Assignees are SET, not added and removed. PATCH /issues/{n} takes the
|
|
|
|
|
# whole list ({"assignees":[]} clears it, 201), so --remove-assignee is
|
|
|
|
|
# a read-modify-write rather than a delete.
|
|
|
|
|
#
|
|
|
|
|
# 3. There is no statusCheckRollup. The portable equivalent is the
|
|
|
|
|
# combined commit status, GET /commits/{sha}/status, which returns
|
|
|
|
|
# {state, statuses[]}.
|
|
|
|
|
|
|
|
|
|
# forgejo_label_ids — name<TAB>id for every label in the repo, read once per
|
|
|
|
|
# call site that needs it. Paginated through forge_api, so a repo with more
|
|
|
|
|
# than one page of labels cannot silently lose the tail (#188).
|
|
|
|
|
forgejo_label_ids() {
|
|
|
|
|
forge_api --paginate "repos/$REPO/labels" --jq '.[] | "\(.name)\t\(.id)"'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forge_issue_edit <n> [--add-label X]… [--remove-label X]… [--add-assignee U]… [--remove-assignee U]…
|
|
|
|
|
# gh's flag surface, translated. Accepts comma-separated values, as gh does.
|
|
|
|
|
forge_issue_edit() {
|
|
|
|
|
local n="${1:?forge_issue_edit: number required}"
|
|
|
|
|
shift
|
|
|
|
|
local add_labels=() rm_labels=() add_assignees=() rm_assignees=() v
|
fix(forge): parity gaps in the forgejo verbs — upsert, timestamps, typos
@codex-reviewer-andresmgsl's three findings (#4743), all real.
1. forge_label_create is now an UPSERT, matching gh label create --force.
bootstrap_labels creates every declared label on EVERY workflow_dispatch,
so a plain POST onto an existing name aborted the bootstrap under set -e
from the second dispatch onward. Resolves name -> id and PATCHes when it
exists.
2. forge_pr_view carries createdAt/completedAt. checks_state groups repeated
contexts and selects the newest by [.startedAt, .createdAt, .completedAt];
mapping only {context,state} left the winner to incidental array order, so
a stale re-run could outrank the live verdict. The combined status carries
created_at and updated_at — measured.
3. forge_issue_edit refuses unknown flags and missing values. The github
backend hands them to gh, which fails; dropping them here turned a
mis-typed port site into a mutation that silently did not happen — this
issue's own failure class, inside the fix for it.
Also settles @grok-reviewer-andresmgsl's note 3 (#4741): Forgejo Actions DO
land as commit statuses on this instance, so the rollup is not empty.
rig main carries four — "ci / check (push)" and siblings, state success,
each with created_at. statusCheckRollup therefore populates, and NONE is not
silently substituted for SUCCESS.
Each fix mutation-verified: dropping the timestamps, forcing POST-always, and
restoring the silent flag skip each red exactly their own cases. The
newest-verdict case drives the real checks_state, not a copy.
Refs #188
2026-08-02 19:22:28 +00:00
|
|
|
# Unknown flags REFUSE (#4743). The github backend forwards whatever it is
|
|
|
|
|
# given to `gh`, which fails on a flag it does not know; dropping it here
|
|
|
|
|
# instead would turn a port typo into a green no-op — a mutation that
|
|
|
|
|
# silently did not happen, which is precisely this issue's failure class
|
|
|
|
|
# arriving inside the fix for it.
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
|
case "$1" in
|
fix(forge): parity gaps in the forgejo verbs — upsert, timestamps, typos
@codex-reviewer-andresmgsl's three findings (#4743), all real.
1. forge_label_create is now an UPSERT, matching gh label create --force.
bootstrap_labels creates every declared label on EVERY workflow_dispatch,
so a plain POST onto an existing name aborted the bootstrap under set -e
from the second dispatch onward. Resolves name -> id and PATCHes when it
exists.
2. forge_pr_view carries createdAt/completedAt. checks_state groups repeated
contexts and selects the newest by [.startedAt, .createdAt, .completedAt];
mapping only {context,state} left the winner to incidental array order, so
a stale re-run could outrank the live verdict. The combined status carries
created_at and updated_at — measured.
3. forge_issue_edit refuses unknown flags and missing values. The github
backend hands them to gh, which fails; dropping them here turned a
mis-typed port site into a mutation that silently did not happen — this
issue's own failure class, inside the fix for it.
Also settles @grok-reviewer-andresmgsl's note 3 (#4741): Forgejo Actions DO
land as commit statuses on this instance, so the rollup is not empty.
rig main carries four — "ci / check (push)" and siblings, state success,
each with created_at. statusCheckRollup therefore populates, and NONE is not
silently substituted for SUCCESS.
Each fix mutation-verified: dropping the timestamps, forcing POST-always, and
restoring the silent flag skip each red exactly their own cases. The
newest-verdict case drives the real checks_state, not a copy.
Refs #188
2026-08-02 19:22:28 +00:00
|
|
|
--add-label | --remove-label | --add-assignee | --remove-assignee)
|
|
|
|
|
if [ "$#" -lt 2 ]; then
|
|
|
|
|
echo "forge_issue_edit: $1 requires a value (#188)" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
IFS=, read -ra v <<<"$2"
|
|
|
|
|
case "$1" in
|
|
|
|
|
--add-label) add_labels+=("${v[@]}") ;;
|
|
|
|
|
--remove-label) rm_labels+=("${v[@]}") ;;
|
|
|
|
|
--add-assignee) add_assignees+=("${v[@]}") ;;
|
|
|
|
|
--remove-assignee) rm_assignees+=("${v[@]}") ;;
|
|
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "forge_issue_edit: unknown flag '$1' — refusing rather than silently skipping the edit (#188)" >&2
|
|
|
|
|
return 1
|
|
|
|
|
;;
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
esac
|
|
|
|
|
shift
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ "${#add_labels[@]}" -gt 0 ]; then
|
|
|
|
|
local payload
|
|
|
|
|
payload="$(printf '%s\n' "${add_labels[@]}" | jq -R . | jq -s '{labels: .}')"
|
|
|
|
|
forgejo_write POST "repos/$REPO/issues/$n/labels" "$payload" >/dev/null || return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${#rm_labels[@]}" -gt 0 ]; then
|
|
|
|
|
local ids id name
|
|
|
|
|
ids="$(forgejo_label_ids)" || return 1
|
|
|
|
|
for name in "${rm_labels[@]}"; do
|
|
|
|
|
id="$(awk -F '\t' -v want="$name" '$1 == want { print $2; exit }' <<<"$ids")"
|
|
|
|
|
# A label the repo does not have is not an error: the reconcilers call
|
|
|
|
|
# --remove-label unconditionally to converge state, and gh's own
|
|
|
|
|
# behaviour there is a no-op.
|
|
|
|
|
[ -n "$id" ] || continue
|
|
|
|
|
forgejo_write DELETE "repos/$REPO/issues/$n/labels/$id" '' >/dev/null || return 1
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ "${#add_assignees[@]}" -gt 0 ] || [ "${#rm_assignees[@]}" -gt 0 ]; then
|
|
|
|
|
local current want payload
|
|
|
|
|
current="$(forge_api "repos/$REPO/issues/$n" --jq '[.assignees[]?.login] | join("\n")')" || return 1
|
|
|
|
|
want="$(
|
|
|
|
|
{
|
|
|
|
|
printf '%s\n' "$current"
|
|
|
|
|
[ "${#add_assignees[@]}" -gt 0 ] && printf '%s\n' "${add_assignees[@]}"
|
|
|
|
|
} | grep -v '^$' | sort -u
|
|
|
|
|
)"
|
|
|
|
|
if [ "${#rm_assignees[@]}" -gt 0 ]; then
|
|
|
|
|
want="$(grep -vxF -f <(printf '%s\n' "${rm_assignees[@]}") <<<"$want" || true)"
|
|
|
|
|
fi
|
|
|
|
|
payload="$(printf '%s' "$want" | jq -R . | jq -s '{assignees: [.[] | select(. != "")]}')"
|
|
|
|
|
forgejo_write PATCH "repos/$REPO/issues/$n" "$payload" >/dev/null || return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forge_issue_comment() {
|
|
|
|
|
local n="${1:?forge_issue_comment: number required}" body="${2?forge_issue_comment: body required}"
|
|
|
|
|
forgejo_write POST "repos/$REPO/issues/$n/comments" "$(jq -n --arg b "$body" '{body: $b}')" >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forge_pr_list() {
|
|
|
|
|
forge_api --paginate "repos/$REPO/pulls?state=open" --jq '.[].number'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forge_pr_view <n> — the {mergeable, statusCheckRollup} shape the state
|
|
|
|
|
# machine reads, assembled from the two places Forgejo keeps it. The rollup
|
|
|
|
|
# is mapped into the node shape checks_state already parses, so the decision
|
|
|
|
|
# code is untouched.
|
|
|
|
|
forge_pr_view() {
|
|
|
|
|
local n="${1:?forge_pr_view: number required}" pr sha status
|
|
|
|
|
pr="$(forge_api "repos/$REPO/pulls/$n")" || return 1
|
|
|
|
|
sha="$(jq -r '.head.sha // ""' <<<"$pr")"
|
|
|
|
|
[ -n "$sha" ] || { echo "forge_pr_view: PR $n has no head sha" >&2; return 1; }
|
|
|
|
|
status="$(forge_api "repos/$REPO/commits/$sha/status")" || return 1
|
|
|
|
|
jq -n --argjson pr "$pr" --argjson st "$status" '
|
|
|
|
|
{
|
|
|
|
|
mergeable: (if $pr.mergeable == true then "MERGEABLE"
|
|
|
|
|
elif $pr.mergeable == false then "CONFLICTING"
|
|
|
|
|
else "UNKNOWN" end),
|
|
|
|
|
statusCheckRollup: [
|
|
|
|
|
$st.statuses[]? | {
|
|
|
|
|
__typename: "StatusContext",
|
|
|
|
|
context: .context,
|
fix(forge): parity gaps in the forgejo verbs — upsert, timestamps, typos
@codex-reviewer-andresmgsl's three findings (#4743), all real.
1. forge_label_create is now an UPSERT, matching gh label create --force.
bootstrap_labels creates every declared label on EVERY workflow_dispatch,
so a plain POST onto an existing name aborted the bootstrap under set -e
from the second dispatch onward. Resolves name -> id and PATCHes when it
exists.
2. forge_pr_view carries createdAt/completedAt. checks_state groups repeated
contexts and selects the newest by [.startedAt, .createdAt, .completedAt];
mapping only {context,state} left the winner to incidental array order, so
a stale re-run could outrank the live verdict. The combined status carries
created_at and updated_at — measured.
3. forge_issue_edit refuses unknown flags and missing values. The github
backend hands them to gh, which fails; dropping them here turned a
mis-typed port site into a mutation that silently did not happen — this
issue's own failure class, inside the fix for it.
Also settles @grok-reviewer-andresmgsl's note 3 (#4741): Forgejo Actions DO
land as commit statuses on this instance, so the rollup is not empty.
rig main carries four — "ci / check (push)" and siblings, state success,
each with created_at. statusCheckRollup therefore populates, and NONE is not
silently substituted for SUCCESS.
Each fix mutation-verified: dropping the timestamps, forcing POST-always, and
restoring the silent flag skip each red exactly their own cases. The
newest-verdict case drives the real checks_state, not a copy.
Refs #188
2026-08-02 19:22:28 +00:00
|
|
|
state: (.status | ascii_upcase),
|
|
|
|
|
# checks_state groups repeated contexts and takes the NEWEST by
|
|
|
|
|
# [.startedAt, .createdAt, .completedAt]. Without a timestamp the
|
|
|
|
|
# winner would be decided by incidental array order, so a stale
|
|
|
|
|
# re-run could outrank the live verdict (#4743). The combined
|
|
|
|
|
# status carries both fields; measured on this instance.
|
|
|
|
|
createdAt: .created_at,
|
|
|
|
|
completedAt: .updated_at
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forge_label_list() { forge_api --paginate "repos/$REPO/labels" --jq '.[].name'; }
|
|
|
|
|
|
fix(forge): parity gaps in the forgejo verbs — upsert, timestamps, typos
@codex-reviewer-andresmgsl's three findings (#4743), all real.
1. forge_label_create is now an UPSERT, matching gh label create --force.
bootstrap_labels creates every declared label on EVERY workflow_dispatch,
so a plain POST onto an existing name aborted the bootstrap under set -e
from the second dispatch onward. Resolves name -> id and PATCHes when it
exists.
2. forge_pr_view carries createdAt/completedAt. checks_state groups repeated
contexts and selects the newest by [.startedAt, .createdAt, .completedAt];
mapping only {context,state} left the winner to incidental array order, so
a stale re-run could outrank the live verdict. The combined status carries
created_at and updated_at — measured.
3. forge_issue_edit refuses unknown flags and missing values. The github
backend hands them to gh, which fails; dropping them here turned a
mis-typed port site into a mutation that silently did not happen — this
issue's own failure class, inside the fix for it.
Also settles @grok-reviewer-andresmgsl's note 3 (#4741): Forgejo Actions DO
land as commit statuses on this instance, so the rollup is not empty.
rig main carries four — "ci / check (push)" and siblings, state success,
each with created_at. statusCheckRollup therefore populates, and NONE is not
silently substituted for SUCCESS.
Each fix mutation-verified: dropping the timestamps, forcing POST-always, and
restoring the silent flag skip each red exactly their own cases. The
newest-verdict case drives the real checks_state, not a copy.
Refs #188
2026-08-02 19:22:28 +00:00
|
|
|
# forge_label_create — an UPSERT, matching `gh label create --force` (#4743).
|
|
|
|
|
# bootstrap_labels creates every declared label on every workflow_dispatch, so
|
|
|
|
|
# the second dispatch must update rather than conflict; a plain POST onto an
|
|
|
|
|
# existing name aborts the bootstrap under set -e.
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
forge_label_create() {
|
fix(forge): parity gaps in the forgejo verbs — upsert, timestamps, typos
@codex-reviewer-andresmgsl's three findings (#4743), all real.
1. forge_label_create is now an UPSERT, matching gh label create --force.
bootstrap_labels creates every declared label on EVERY workflow_dispatch,
so a plain POST onto an existing name aborted the bootstrap under set -e
from the second dispatch onward. Resolves name -> id and PATCHes when it
exists.
2. forge_pr_view carries createdAt/completedAt. checks_state groups repeated
contexts and selects the newest by [.startedAt, .createdAt, .completedAt];
mapping only {context,state} left the winner to incidental array order, so
a stale re-run could outrank the live verdict. The combined status carries
created_at and updated_at — measured.
3. forge_issue_edit refuses unknown flags and missing values. The github
backend hands them to gh, which fails; dropping them here turned a
mis-typed port site into a mutation that silently did not happen — this
issue's own failure class, inside the fix for it.
Also settles @grok-reviewer-andresmgsl's note 3 (#4741): Forgejo Actions DO
land as commit statuses on this instance, so the rollup is not empty.
rig main carries four — "ci / check (push)" and siblings, state success,
each with created_at. statusCheckRollup therefore populates, and NONE is not
silently substituted for SUCCESS.
Each fix mutation-verified: dropping the timestamps, forcing POST-always, and
restoring the silent flag skip each red exactly their own cases. The
newest-verdict case drives the real checks_state, not a copy.
Refs #188
2026-08-02 19:22:28 +00:00
|
|
|
local name="${1:?}" color="${2:?}" desc="${3:-}" ids id payload
|
|
|
|
|
payload="$(jq -n --arg n "$name" --arg c "$color" --arg d "$desc" '{name:$n,color:$c,description:$d}')"
|
|
|
|
|
ids="$(forgejo_label_ids)" || return 1
|
|
|
|
|
id="$(awk -F '\t' -v want="$name" '$1 == want { print $2; exit }' <<<"$ids")"
|
|
|
|
|
if [ -n "$id" ]; then
|
|
|
|
|
forgejo_write PATCH "repos/$REPO/labels/$id" "$payload" >/dev/null
|
|
|
|
|
else
|
|
|
|
|
forgejo_write POST "repos/$REPO/labels" "$payload" >/dev/null
|
|
|
|
|
fi
|
feat(forge): the reconciler verb surface on both backends
github is the existing gh invocation extracted 1:1 (term 5). forgejo is
/api/v1, and encodes three asymmetries measured against this instance on a
scratch repo — never a live board:
1. Adding labels takes NAMES; removing one takes a numeric ID.
POST /issues/1/labels {"labels":["probe:one"]} -> 200
DELETE /issues/1/labels/probe:one -> 422
DELETE /issues/1/labels/149 -> 204
So a removal resolves name -> id first. gh hides this; the shim cannot.
2. Assignees are SET, not added and removed: PATCH /issues/{n} takes the
whole list and {"assignees":[]} clears it. --remove-assignee is therefore
a read-modify-write, not a delete.
3. There is no statusCheckRollup. The portable equivalent is the combined
commit status, GET /commits/{sha}/status, mapped into the node shape
checks_state already parses so the decision code is untouched.
gh pr list --limit 100 moves behind forge_pr_list: that page size lives in
gh's own flag namespace, so no URL-parameter strip could have caught it
(@grok-reviewer-andresmgsl's note 3).
Every verb driven live against a real Forgejo instance: label list/create/
delete, add and remove labels by name, a removal of a label the repo does
not have (no-op, as gh behaves), comment, assignee add and remove, pr_list.
Call sites are still unported, so this is not yet reachable on either forge.
Refs #188
2026-08-02 19:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
forge_label_delete() {
|
|
|
|
|
local name="${1:?}" ids id
|
|
|
|
|
ids="$(forgejo_label_ids)" || return 1
|
|
|
|
|
id="$(awk -F '\t' -v want="$name" '$1 == want { print $2; exit }' <<<"$ids")"
|
|
|
|
|
[ -n "$id" ] || return 0
|
|
|
|
|
forgejo_write DELETE "repos/$REPO/labels/$id" '' >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# forgejo_write <method> <endpoint> <json-body> — every mutation goes through
|
|
|
|
|
# here so a non-2xx is named rather than swallowed, the same contract
|
|
|
|
|
# forgejo_http_ok gives reads.
|
|
|
|
|
forgejo_write() {
|
|
|
|
|
local method="$1" endpoint="$2" payload="$3" base token hdr body rc
|
|
|
|
|
base="$(forgejo_api_base)" || return 1
|
|
|
|
|
token="${GH_TOKEN:-${GITHUB_TOKEN:-${FORGEJO_TOKEN:-}}}"
|
|
|
|
|
hdr="$(mktemp)"; body="$(mktemp)"
|
|
|
|
|
if [ -n "$payload" ]; then
|
|
|
|
|
curl -sS -X "$method" -D "$hdr" -o "$body" \
|
|
|
|
|
-H "Authorization: token $token" -H 'Content-Type: application/json' \
|
|
|
|
|
-d "$payload" "$base/$endpoint"
|
|
|
|
|
else
|
|
|
|
|
curl -sS -X "$method" -D "$hdr" -o "$body" \
|
|
|
|
|
-H "Authorization: token $token" "$base/$endpoint"
|
|
|
|
|
fi
|
|
|
|
|
rc=$?
|
|
|
|
|
if [ "$rc" -ne 0 ]; then
|
|
|
|
|
rm -f "$hdr" "$body"
|
|
|
|
|
echo "forge: $method $endpoint failed to send" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
if ! forgejo_http_ok "$hdr" "$method $endpoint"; then
|
|
|
|
|
head -c 300 "$body" >&2; echo >&2
|
|
|
|
|
rm -f "$hdr" "$body"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
cat "$body"
|
|
|
|
|
rm -f "$hdr" "$body"
|
|
|
|
|
}
|