**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/
101 lines
3.0 KiB
Bash
Executable File
101 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Migrate all docs/*.md (repo root) to Gitea wiki as pages.
|
|
# Mapping: docs/FILE.md → page "File" (stem with _ → -, first letter upper per segment).
|
|
# Requires GITEA_TOKEN or .secrets/gitea-issues/token.
|
|
# Usage: ./wiki-migrate-docs.sh [--dry-run] [file.md ...]
|
|
# --dry-run: print mapping and skip API calls.
|
|
# If file(s) given: migrate only those; else migrate all docs/*.md.
|
|
#
|
|
set -euo pipefail
|
|
|
|
GITEA_ISSUES_DIR="${GITEA_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
|
REPO_ROOT="${GITEA_ISSUES_DIR}/.."
|
|
DOCS_DIR="${REPO_ROOT}/docs"
|
|
# shellcheck source=lib.sh
|
|
source "${GITEA_ISSUES_DIR}/lib.sh"
|
|
|
|
REPO_PATH="/repos/${GITEA_REPO_OWNER}/${GITEA_REPO_NAME}"
|
|
GITEA_WIKI_REF="${GITEA_WIKI_REF:-master}"
|
|
WIKI_PAGE="${REPO_PATH}/wiki/page"
|
|
WIKI_NEW="${REPO_PATH}/wiki/new"
|
|
|
|
# docs/FILE.md → page name for wiki (stem: _ → -, title-case: First-Letter-Of-Each-Segment)
|
|
file_to_page_name() {
|
|
local base="$1"
|
|
local stem="${base%.md}"
|
|
echo "$stem" | tr '_' '-' | awk -F- '{
|
|
for(i=1;i<=NF;i++) {
|
|
s = $i; l = length(s)
|
|
if (l > 0) $i = toupper(substr(s,1,1)) tolower(substr(s,2))
|
|
}
|
|
}1' OFS='-'
|
|
}
|
|
|
|
dry_run=false
|
|
files=()
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--dry-run) dry_run=true; shift ;;
|
|
*.md) files+=("$1"); shift ;;
|
|
*) log_err "Unknown option or not .md: $1"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
if [[ ${#files[@]} -eq 0 ]]; then
|
|
while IFS= read -r -d '' f; do
|
|
files+=("$f")
|
|
done < <(find "$DOCS_DIR" -maxdepth 1 -name '*.md' -print0 | sort -z)
|
|
else
|
|
# Resolve args to full paths under DOCS_DIR
|
|
for i in "${!files[@]}"; do
|
|
u="${files[$i]}"
|
|
if [[ "$u" != */* ]] && [[ -f "${DOCS_DIR}/${u}" ]]; then
|
|
files[$i]="${DOCS_DIR}/${u}"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [[ ${#files[@]} -eq 0 ]]; then
|
|
log_err "No .md files found in ${DOCS_DIR}"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$dry_run" == true ]]; then
|
|
log_info "Dry run: would migrate ${#files[@]} file(s)"
|
|
for f in "${files[@]}"; do
|
|
base="$(basename "$f")"
|
|
page="$(file_to_page_name "$base")"
|
|
echo " $f → $page"
|
|
done
|
|
exit 0
|
|
fi
|
|
|
|
load_gitea_token || exit 1
|
|
require_jq || exit 1
|
|
|
|
for f in "${files[@]}"; do
|
|
base="$(basename "$f")"
|
|
page="$(file_to_page_name "$base")"
|
|
if [[ ! -f "$f" ]]; then
|
|
log_err "Skip (not a file): $f"
|
|
continue
|
|
fi
|
|
content="$(cat "$f")"
|
|
content_b64="$(echo -n "$content" | base64 -w 0)"
|
|
body="$(jq -n --arg title "$page" --arg content "$content_b64" --arg msg "Migrate from docs/$base" \
|
|
'{ title: $title, content_base64: $content, message: $msg }')"
|
|
# Check if page exists (GET); if 200 use PATCH else POST
|
|
resp="$(gitea_api_get "${REPO_PATH}/wiki/page/${page}?ref=${GITEA_WIKI_REF}")"
|
|
if echo "$resp" | jq -e .title &>/dev/null; then
|
|
log_info "Update: $base → $page"
|
|
patch_body="$(jq -n --arg content "$content_b64" --arg msg "Update from docs/$base" '{ content_base64: $content, message: $msg }')"
|
|
gitea_api_patch "${WIKI_PAGE}/${page}?ref=${GITEA_WIKI_REF}" "$patch_body" >/dev/null || true
|
|
else
|
|
log_info "Create: $base → $page"
|
|
gitea_api_post "${WIKI_NEW}" "$body" >/dev/null || true
|
|
fi
|
|
done
|
|
|
|
log_info "Migration done: ${#files[@]} file(s)."
|