Commit f49119f3 authored by Xueshan Feng's avatar Xueshan Feng
Browse files

fix(upgrade-check): hourly fetch throttle and release notes link



Lower the default OTICA_UPGRADE_CHECK_INTERVAL from 24h to 1h so new
releases surface in `make help` within the hour, and add a link to the
GitLab release page (derived from the OTICA_RELEASE_REMOTE git URL) to
the upgrade notice.

Changelog: fixed
Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent b34fe873
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
set -uo pipefail

OTICA_DIR="${OTICA_DIR:-${HOME}/.otica}"
INTERVAL="${OTICA_UPGRADE_CHECK_INTERVAL:-86400}"   # min seconds between fetches; 0 = every run
INTERVAL="${OTICA_UPGRADE_CHECK_INTERVAL:-3600}"   # min seconds between fetches; 0 = every run
STAMP="${OTICA_DIR}/.git/.otica-upgrade-check"

YELLOW='\033[1;33m'
@@ -23,6 +23,25 @@ command -v git >/dev/null 2>&1 || exit 0

git_otica() { git -C "${OTICA_DIR}" "$@"; }

# Best-effort web base URL for the release remote, derived from its git URL so
# we can link straight to the GitLab release page. Handles scp-style
# (git@host:group/repo.git), ssh:// and https:// forms; empty if undeterminable.
release_web_base() {
    local remote url rest
    remote="${OTICA_RELEASE_REMOTE:-origin}"
    url=$(git_otica remote get-url "${remote}" 2>/dev/null || true)
    [ -n "${url}" ] || return 0
    url="${url%.git}"
    case "${url}" in
        git@*:*)      rest="${url#git@}"; url="https://${rest%%:*}/${rest#*:}" ;;
        ssh://git@*)  url="https://${url#ssh://git@}" ;;
        ssh://*)      url="https://${url#ssh://}" ;;
        http://*|https://*) : ;;
        *) return 0 ;;
    esac
    printf '%s' "${url}"
}

# Latest release tag known locally (refreshed by the throttled fetch below).
latest_tag=$(git_otica tag --list 'v*' --sort=-v:refname 2>/dev/null | head -n1)

@@ -51,6 +70,10 @@ if [ -n "${latest_tag}" ]; then
        else
            echo -e "Checkout is not on a release."
        fi
        web_base=$(release_web_base)
        if [ -n "${web_base}" ]; then
            echo -e "Release notes: ${GREEN}${web_base}/-/releases/${latest_tag}${NC}"
        fi
        echo -e "Review the CHANGELOG, then run ${GREEN}make update-otica${NC}, or"
        echo -e "${GREEN}make update-otica VERSION=<ref>${NC} to stay on a specific version."
    fi