**Motivations:** - Single config file per project (projects/<id>/conf.json) - Project must not depend on ia_dev; only ia_dev solicits the project **Root causes:** - N/A (evolution) **Correctifs:** - N/A **Evolutions:** - lib/project_config.sh: resolve PROJECT_SLUG from IA_PROJECT, .ia_project, ai_project_id; PROJECT_CONFIG_PATH = projects/<id>/conf.json - projects/lecoffreio.json moved to projects/lecoffreio/conf.json; projects/ia_dev/conf.json added - deploy: branch-align, bump-version, change-to-all-branches, pousse, deploy-by-script-to use PROJECT_ROOT/IA_DEV_ROOT and project_config.sh; SCRIPT_REAL for symlink-safe paths - deploy/_lib: shared colors, env-map, ssh, git-flow - gitea-issues: mail list/mark-read/get-thread/send-reply, thread log, agent-loop, wiki scripts; lib.sh loads project config - README: principle no dependency from host project; invoke ./ia_dev/deploy/bump-version.sh etc. from repo root **Pages affectées:** - README.md, projects/README.md, lib/, deploy/, gitea-issues/, projects/lecoffreio/, projects/ia_dev/
111 lines
3.6 KiB
Bash
Executable File
111 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Shared config and helpers for Gitea issues scripts.
|
|
# Source from gitea-issues/*.sh after cd to project root.
|
|
#
|
|
set -euo pipefail
|
|
|
|
GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
|
GITEA_API_URL="${GITEA_API_URL:-https://git.4nkweb.com/api/v1}"
|
|
GITEA_REPO_OWNER="${GITEA_REPO_OWNER:-4nk}"
|
|
GITEA_REPO_NAME="${GITEA_REPO_NAME:-lecoffre_ng}"
|
|
|
|
# Optional: load project config from ia_dev (projects/<id>/conf.json) when gitea-issues is inside ia_dev
|
|
PROJECT_CONFIG_PATH=""
|
|
if [[ -f "${GITEA_ISSUES_DIR}/../lib/project_config.sh" ]]; then
|
|
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || true
|
|
IA_DEV_ROOT="$(cd "$GITEA_ISSUES_DIR/.." && pwd)"
|
|
if [[ -n "${PROJECT_ROOT:-}" ]]; then
|
|
# shellcheck source=../lib/project_config.sh
|
|
source "${GITEA_ISSUES_DIR}/../lib/project_config.sh"
|
|
fi
|
|
fi
|
|
|
|
# Load token: GITEA_TOKEN env, then project config git.token_file, then default .secrets path
|
|
load_gitea_token() {
|
|
if [[ -n "${GITEA_TOKEN:-}" ]]; then
|
|
return 0
|
|
fi
|
|
local token_file=""
|
|
if [[ -n "${PROJECT_CONFIG_PATH:-}" && -f "$PROJECT_CONFIG_PATH" ]] && command -v jq >/dev/null 2>&1; then
|
|
local rel_path
|
|
rel_path="$(jq -r '.git.token_file // empty' "$PROJECT_CONFIG_PATH" 2>/dev/null)"
|
|
if [[ -n "$rel_path" && -n "${PROJECT_ROOT:-}" && -f "${PROJECT_ROOT}/${rel_path}" ]]; then
|
|
token_file="${PROJECT_ROOT}/${rel_path}"
|
|
fi
|
|
fi
|
|
if [[ -z "$token_file" ]]; then
|
|
token_file="${GITEA_ISSUES_DIR}/../.secrets/gitea-issues/token"
|
|
fi
|
|
if [[ -f "$token_file" ]]; then
|
|
GITEA_TOKEN="$(cat "$token_file")"
|
|
return 0
|
|
fi
|
|
echo "[gitea-issues] ERROR: GITEA_TOKEN not set and ${token_file} not found" >&2
|
|
echo "[gitea-issues] Set GITEA_TOKEN or create the token file with a Gitea Personal Access Token." >&2
|
|
return 1
|
|
}
|
|
|
|
# curl wrapper for Gitea API (GET). Usage: gitea_api_get "/repos/owner/repo/issues"
|
|
gitea_api_get() {
|
|
local path="$1"
|
|
load_gitea_token || return 1
|
|
curl -sS -H "Accept: application/json" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_API_URL}${path}"
|
|
}
|
|
|
|
# curl wrapper for Gitea API (POST). Usage: gitea_api_post "/repos/owner/repo/issues/123/comments" '{"body":"..."}'
|
|
gitea_api_post() {
|
|
local path="$1"
|
|
local data="${2:-}"
|
|
load_gitea_token || return 1
|
|
curl -sS -X POST -H "Accept: application/json" -H "Content-Type: application/json" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-d "$data" \
|
|
"${GITEA_API_URL}${path}"
|
|
}
|
|
|
|
# curl wrapper for Gitea API (PATCH). Usage: gitea_api_patch "/repos/owner/repo/wiki/page/Foo" '{"content_base64":"..."}'
|
|
gitea_api_patch() {
|
|
local path="$1"
|
|
local data="${2:-}"
|
|
load_gitea_token || return 1
|
|
curl -sS -X PATCH -H "Accept: application/json" -H "Content-Type: application/json" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-d "$data" \
|
|
"${GITEA_API_URL}${path}"
|
|
}
|
|
|
|
# curl wrapper for Gitea API (DELETE). Usage: gitea_api_delete "/repos/owner/repo/wiki/page/Foo"
|
|
gitea_api_delete() {
|
|
local path="$1"
|
|
load_gitea_token || return 1
|
|
curl -sS -X DELETE -H "Accept: application/json" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
"${GITEA_API_URL}${path}"
|
|
}
|
|
|
|
log_ts() { date -u '+%Y-%m-%dT%H:%M:%SZ'; }
|
|
log_info() { echo "[$(log_ts)] [gitea-issues] $*"; }
|
|
log_err() { echo "[$(log_ts)] [gitea-issues] $*" >&2; }
|
|
|
|
# Require jq for JSON output
|
|
require_jq() {
|
|
if ! command -v jq &>/dev/null; then
|
|
log_err "jq is required. Install with: apt install jq / brew install jq"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Ensure we are in the git repo root (for create-branch, etc.)
|
|
require_git_root() {
|
|
local root
|
|
root="$(git rev-parse --show-toplevel 2>/dev/null)" || true
|
|
if [[ -z "$root" ]]; then
|
|
log_err "Not inside a git repository."
|
|
return 1
|
|
fi
|
|
cd "$root"
|
|
}
|