This commit is contained in:
@@ -508,7 +508,7 @@ gcr_sweep_stale_runners() {
|
|||||||
case "$allowed_repo" in
|
case "$allowed_repo" in
|
||||||
*/\*)
|
*/\*)
|
||||||
owner="${allowed_repo%/*}"
|
owner="${allowed_repo%/*}"
|
||||||
repos="$(gcr_gitea_list_org_repos "$owner")" || {
|
repos="$(gcr_gitea_list_owner_repos "$owner")" || {
|
||||||
IFS=,
|
IFS=,
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,21 +61,49 @@ gcr_gitea_list_runners() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# gcr_gitea_list_org_repos OWNER — prints fully-qualified repository names.
|
# gcr_gitea_list_owner_repos OWNER — prints fully-qualified repository names.
|
||||||
gcr_gitea_list_org_repos() {
|
# Allowed owner globs may refer to either organizations or users. Probe the
|
||||||
|
# organization route first, then use the user route on a confirmed 404.
|
||||||
|
gcr_gitea_list_owner_repos() {
|
||||||
owner="$1"
|
owner="$1"
|
||||||
gcr_gitea_admin_token >/dev/null || return 1
|
gcr_gitea_admin_token >/dev/null || return 1
|
||||||
|
owner_kind=orgs
|
||||||
page=1
|
page=1
|
||||||
while :; do
|
while :; do
|
||||||
repos="$(gcr_gitea_curl -fsS \
|
owner_page="$(mktemp "${TMPDIR:-/tmp}/gcr-owner-repos.XXXXXX")" \
|
||||||
"$GCR_GITEA_URL/api/v1/orgs/$owner/repos?page=$page&limit=50")" || return 1
|
|| return 1
|
||||||
printf '%s' "$repos" | jq -r '.[]? | .full_name'
|
owner_status="$(gcr_gitea_curl -sS -o "$owner_page" -w '%{http_code}' \
|
||||||
count="$(printf '%s' "$repos" | jq 'length')" || return 1
|
"$GCR_GITEA_URL/api/v1/$owner_kind/$owner/repos?page=$page&limit=50")" \
|
||||||
|
|| { rm -f "$owner_page"; return 1; }
|
||||||
|
if [ "$owner_status" = 404 ] && [ "$owner_kind" = orgs ] && [ "$page" = 1 ]; then
|
||||||
|
owner_kind=users
|
||||||
|
rm -f "$owner_page"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
[ "$owner_status" = 200 ] || {
|
||||||
|
rm -f "$owner_page"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
jq -e 'type == "array"' "$owner_page" >/dev/null || {
|
||||||
|
rm -f "$owner_page"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
jq -r '.[] | .full_name' "$owner_page"
|
||||||
|
count="$(jq 'length' "$owner_page")" || {
|
||||||
|
rm -f "$owner_page"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
rm -f "$owner_page"
|
||||||
[ "$count" -lt 50 ] && return 0
|
[ "$count" -lt 50 ] && return 0
|
||||||
page=$((page + 1))
|
page=$((page + 1))
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Compatibility name for callers outside active controller path.
|
||||||
|
gcr_gitea_list_org_repos() {
|
||||||
|
gcr_gitea_list_owner_repos "$1"
|
||||||
|
}
|
||||||
|
|
||||||
# gcr_gitea_job_state REPO JOB_ID — prints "<status>:<conclusion>".
|
# gcr_gitea_job_state REPO JOB_ID — prints "<status>:<conclusion>".
|
||||||
gcr_gitea_job_state() {
|
gcr_gitea_job_state() {
|
||||||
repo="$1"; job_id="$2"
|
repo="$1"; job_id="$2"
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/dash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
. "$LOG_SH"
|
||||||
|
. "$GITEA_SH"
|
||||||
|
|
||||||
|
export GITEA_ADMIN_TOKEN_FILE="$GCR_STATE_DIR/admin-token"
|
||||||
|
export GCR_GITEA_URL='https://gitea.example.test'
|
||||||
|
printf 'test-token\n' > "$GITEA_ADMIN_TOKEN_FILE"
|
||||||
|
gcr_gitea_admin_token() { printf 'test-token'; }
|
||||||
|
|
||||||
|
gcr_gitea_curl() {
|
||||||
|
output=""
|
||||||
|
previous=""
|
||||||
|
for arg do
|
||||||
|
if [ "$previous" = -o ]; then
|
||||||
|
output="$arg"
|
||||||
|
fi
|
||||||
|
previous="$arg"
|
||||||
|
done
|
||||||
|
case "$*" in
|
||||||
|
*'/orgs/yukkop/repos'*)
|
||||||
|
: > "$output"
|
||||||
|
printf '404'
|
||||||
|
;;
|
||||||
|
*'/users/yukkop/repos'*)
|
||||||
|
printf '[{"full_name":"yukkop/project"}]\n' > "$output"
|
||||||
|
printf '200'
|
||||||
|
;;
|
||||||
|
*'/orgs/hectic-lab/repos'*)
|
||||||
|
printf '[{"full_name":"hectic-lab/util.nix"}]\n' > "$output"
|
||||||
|
printf '200'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
test "$(gcr_gitea_list_owner_repos yukkop)" = 'yukkop/project'
|
||||||
|
test "$(gcr_gitea_list_owner_repos hectic-lab)" = 'hectic-lab/util.nix'
|
||||||
Reference in New Issue
Block a user