Files
gitea-cli/scripts/visibility.sh
timmy faee15bc78 Initial commit
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 13:04:09 +08:00

43 lines
921 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
source "${SCRIPT_DIR}/lib/common.sh"
usage() {
cat >&2 <<'EOF'
Usage: visibility.sh <repo> <public|private>
EOF
exit 1
}
[[ $# -eq 2 ]] || usage
REPO="$1"
VIS="$2"
case "$VIS" in
public) PRIVATE=false ;;
private) PRIVATE=true ;;
*) log_err "可見性只能是 public 或 private"; exit 1 ;;
esac
load_config
log_info "切換 ${GITEA_USER}/${REPO}${VIS}"
gitea_api PATCH "/repos/${GITEA_USER}/${REPO}" "{\"private\":${PRIVATE}}"
case "$HTTP_CODE" in
200|201) log_ok "已更新" ;;
404) log_err "找不到 repo${GITEA_USER}/${REPO}"; exit 1 ;;
*)
log_err "更新失敗 (HTTP ${HTTP_CODE})"
{ cat "$GITEA_API_RESP_FILE"; echo ""; } >&2
exit 1
;;
esac
log_done "完成"
echo "${GITEA_URL}/${GITEA_USER}/${REPO}"