Skip to content

Commit 424d60d

Browse files
Merge pull request #587 from appdevforall/fix/K2GO-420-forgejo-adopt-casing
K2GO-420 fix(forgejo): seed the per-tier repos (lowercased adopt path)
2 parents 1891606 + 5b1c265 commit 424d60d

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

‎static/forgejo/orchestration‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ FORGEJO_WAIT_TRIES="${FORGEJO_WAIT_TRIES:-60}" # 502 window toler
4545
# drops history; the migrate API cannot go shallow.
4646
FORGEJO_SEED_METHOD="${FORGEJO_SEED_METHOD:-shallow}"
4747

48-
# Canonical repo lists (owner|name|clone_addr|branch; branch optional -> default). Single source
49-
# for the repo URLs: the installer gate selects one by tier, it does not restate the URLs.
50-
FORGEJO_REPOS_FULL="${FORGEJO_ORG}|CodeOnTheGo|https://github.com/appdevforall/CodeOnTheGo|stage
51-
${FORGEJO_ORG}|KnowledgeToGo|https://github.com/appdevforall/KnowledgeToGo|
52-
${FORGEJO_ORG}|plugin-examples|https://github.com/appdevforall/plugin-examples|"
53-
FORGEJO_REPOS_STANDARD="${FORGEJO_ORG}|KnowledgeToGo|https://github.com/appdevforall/KnowledgeToGo|"
48+
# Canonical repo definitions (owner|name|clone_addr|branch; branch optional -> default). One source
49+
# per repo; the tier lists compose from these, and the installer gate picks a tier by name.
50+
_FJ_REPO_K2GO="${FORGEJO_ORG}|KnowledgeToGo|https://github.com/appdevforall/KnowledgeToGo|"
51+
_FJ_REPO_COGO="${FORGEJO_ORG}|CodeOnTheGo|https://github.com/appdevforall/CodeOnTheGo|stage"
52+
_FJ_REPO_ADDONS="${FORGEJO_ORG}|addons|https://github.com/appdevforall/addons|"
53+
# Medium (standard): k2go + cogo. Large (full): + addons. Basic has forgejo off, so it seeds nothing.
54+
FORGEJO_REPOS_STANDARD="$_FJ_REPO_K2GO
55+
$_FJ_REPO_COGO"
56+
FORGEJO_REPOS_FULL="$_FJ_REPO_K2GO
57+
$_FJ_REPO_COGO
58+
$_FJ_REPO_ADDONS"
5459
FORGEJO_REPOS="${FORGEJO_REPOS:-$FORGEJO_REPOS_FULL}"
5560

5661
# ===== small helpers (reuse installer's log/ok/warn if present) ============
@@ -60,6 +65,7 @@ command -v warn >/dev/null 2>&1 || warn(){ printf ' WARN: %s\n' "$*" >&2; }
6065

6166
_fj_su() { su -s /bin/sh "$FORGEJO_RUN_USER" -c "$1"; } # run as the forgejo user
6267
_fj_api() { curl -fsS -u "$FORGEJO_ADMIN_USER:$FORGEJO_ADMIN_PASS" "$@"; }
68+
_fj_lc() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; } # Forgejo stores repos at lowercased on-disk paths
6369

6470
# Wait for forgejo to answer 200 THROUGH nginx (tolerate the post-restart 502 window).
6571
_fj_wait_200() {
@@ -103,7 +109,7 @@ _fj_repo_ready() {
103109
# Purge a broken/empty repo before retry. On proot, a single rm leaves dangling
104110
# link2symlink (l2s) entries -> the dir survives -> next seed 409s. So rm TWICE (+ once more).
105111
_fj_purge_repo() {
106-
local owner="$1" name="$2" dir="$FORGEJO_REPO_ROOT/$1/$2.git"
112+
local owner="$1" name="$2" dir="$FORGEJO_REPO_ROOT/$(_fj_lc "$1")/$(_fj_lc "$2").git"
107113
_fj_api -X DELETE "$FORGEJO_API/repos/$owner/$name" >/dev/null 2>&1 || true
108114
if [ "$FORGEJO_PROOT" = "1" ]; then
109115
rm -rf "$dir" 2>/dev/null; rm -rf "$dir" 2>/dev/null; rm -rf "$dir" 2>/dev/null
@@ -124,13 +130,18 @@ _fj_migrate() {
124130
# Method B: shallow snapshot -> adopt (recommended; full current tree, compilable, no history).
125131
# K2GO-212: keep the failure output for debugging.
126132
_fj_shallow_adopt() {
127-
local owner="$1" name="$2" addr="$3" branch="$4" dir="$FORGEJO_REPO_ROOT/$1/$2.git" out
133+
local owner="$1" name="$2" addr="$3" branch="$4" out
134+
# Forgejo derives the on-disk path as <root>/<owner_lc>/<repo_lc>.git (RepoPath lowercases owner and
135+
# repo), so the bare clone must land at the lowercased path or the adopt call gets 404 (dir not found).
136+
# The adopt API keeps the original case, so the repo keeps its display name (e.g. CodeOnTheGo).
137+
local ldir="$FORGEJO_REPO_ROOT/$(_fj_lc "$owner")"
138+
local dir="$ldir/$(_fj_lc "$name").git"
128139
local br=""; [ -n "$branch" ] && br="--branch $branch"
129-
mkdir -p "$FORGEJO_REPO_ROOT/$owner"
140+
mkdir -p "$ldir"
130141
# shellcheck disable=SC2086
131142
out="$(git clone --bare --depth 1 --single-branch $br "$addr" "$dir" 2>&1)" \
132143
|| { warn "clone $owner/$name failed: $out"; return 1; }
133-
chown -R "$FORGEJO_RUN_USER:$FORGEJO_RUN_USER" "$FORGEJO_REPO_ROOT/$owner"
144+
chown -R "$FORGEJO_RUN_USER:$FORGEJO_RUN_USER" "$ldir"
134145
out="$(_fj_api -X POST "$FORGEJO_API/admin/unadopted/$owner/$name" 2>&1)" \
135146
|| { warn "adopt $owner/$name failed: $out"; return 1; } # HTTP 204 on success
136147
}

0 commit comments

Comments
 (0)