Skip to content

Commit eb6acd5

Browse files
authored
Merge pull request #1 from wanghaojie124/dev
fix(apps): align csgclaw latest version with GitHub-style release JSON
2 parents f94d732 + 8e01f39 commit eb6acd5

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

internal/apps/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func appSpecs() []appSpec {
240240
latest: &latestVersionSource{
241241
baseURL: "https://csgclaw.opencsg.com/releases/latest",
242242
envVar: "CSGHUB_LITE_CSGCLAW_LATEST_URL",
243-
format: "version-json",
243+
format: "github-release",
244244
},
245245
unix: &scriptSource{
246246
mirrorURL: "https://csgclaw.opencsg.com/install.sh",

internal/apps/manager_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ func TestAppUpdateAvailableComparesVersionOrder(t *testing.T) {
275275

276276
func TestFetchLatestVersionParsesGitHubReleaseTag(t *testing.T) {
277277
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
278-
if r.URL.Path != "/repos/OpenCSGs/csgclaw/releases/latest" {
279-
t.Fatalf("latest path = %q, want /repos/OpenCSGs/csgclaw/releases/latest", r.URL.Path)
278+
// Mirrors https://csgclaw.opencsg.com/releases/latest (GitHub-compatible JSON).
279+
if r.URL.Path != "/releases/latest" {
280+
t.Fatalf("latest path = %q, want /releases/latest", r.URL.Path)
280281
}
281282
w.Header().Set("Content-Type", "application/json")
282283
_, _ = w.Write([]byte(`{"tag_name":"v0.2.8"}`))
@@ -287,7 +288,7 @@ func TestFetchLatestVersionParsesGitHubReleaseTag(t *testing.T) {
287288
latest, err := mgr.fetchLatestVersion(context.Background(), appSpec{
288289
id: "csgclaw",
289290
latest: &latestVersionSource{
290-
baseURL: server.URL + "/repos/OpenCSGs/csgclaw/releases/latest",
291+
baseURL: server.URL + "/releases/latest",
291292
format: "github-release",
292293
},
293294
})

internal/apps/scripts/csgclaw-install.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -euo pipefail
33

44
APP="${APP:-csgclaw}"
5-
REPO="${REPO:-OpenCSGs/csgclaw}"
65
VERSION="${VERSION:-${1:-latest}}"
76
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
87
LIB_DIR="${LIB_DIR:-$HOME/.local/lib/${APP}}"
@@ -66,8 +65,11 @@ ensure_supported_platform() {
6665
}
6766

6867
resolve_latest_version() {
69-
local api_url tag
70-
api_url="https://api.github.com/repos/${REPO}/releases/latest"
68+
local api_url tag base
69+
# Mirror serves GitHub-compatible JSON at ${BASE_URL}/latest (tag_name, assets, ...).
70+
base="${BASE_URL:-https://csgclaw.opencsg.com/releases}"
71+
while [[ "$base" == */ ]]; do base="${base%/}"; done
72+
api_url="${base}/latest"
7173
tag="$(curl -fsSL "$api_url" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)"
7274
if [[ -z "$tag" ]]; then
7375
log "ERROR: failed to resolve latest release from ${api_url}"

0 commit comments

Comments
 (0)