- Add scripts/lib/common.sh (ORG/BOT/FORGE_BACKEND, logging, process_running) - discover.sh: dedupe review-requested+assignee PRs; JSON+summary formats - discover.sh: FORGE_BACKEND=forgejo via Forgejo API + stoke token - Fix poll-loop process detection (basename, not install path) - health-check: jq-safe JSON; backend-aware auth (gh or stoke) - install-live: require rsync/jq/tmux; soft-warn missing gh/stoke - self-test.sh offline smoke; restore/poll-once use shared config - Docs: Forgejo table, watcher.env, OPERATIONS troubleshooting
65 lines
1.8 KiB
Bash
Executable file
65 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Shared helpers for heavy-duty-watcher scripts.
|
|
# shellcheck shell=bash
|
|
# Usage: source "$(dirname "$0")/lib/common.sh" (from scripts/*.sh)
|
|
|
|
# Resolve repo root from the calling script when WATCHER_DIR is unset.
|
|
if [[ -z "${WATCHER_DIR:-}" ]]; then
|
|
_COMMON_HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
WATCHER_DIR="$(cd "${_COMMON_HERE}/../.." && pwd)"
|
|
unset _COMMON_HERE
|
|
fi
|
|
|
|
# Optional local overrides (never committed — see .gitignore).
|
|
if [[ -f "${WATCHER_DIR}/config/watcher.env" ]]; then
|
|
# shellcheck disable=SC1091
|
|
set -a
|
|
# shellcheck source=/dev/null
|
|
source "${WATCHER_DIR}/config/watcher.env"
|
|
set +a
|
|
fi
|
|
|
|
ORG="${ORG:-heavy-duty}"
|
|
BOT_LOGIN="${BOT_LOGIN:-grok-bot-andresmgsl}"
|
|
# github | forgejo — discovery/posting backend
|
|
FORGE_BACKEND="${FORGE_BACKEND:-github}"
|
|
FORGEJO_URL="${FORGEJO_URL:-https://forgejo.heavyduty.builders}"
|
|
POLL_INTERVAL_SEC="${POLL_INTERVAL_SEC:-900}"
|
|
HEALTH_INTERVAL_SEC="${HEALTH_INTERVAL_SEC:-3600}"
|
|
STALE_POLL_MINUTES="${STALE_POLL_MINUTES:-45}"
|
|
TMUX_SESSION="${TMUX_SESSION:-heavy-duty-watcher}"
|
|
LEGACY_TMUX="${LEGACY_TMUX:-rig-watcher}"
|
|
LIMIT="${LIMIT:-50}"
|
|
|
|
LOG_DIR="${LOG_DIR:-${WATCHER_DIR}/logs}"
|
|
STATE_FILE="${STATE_FILE:-${WATCHER_DIR}/state.json}"
|
|
|
|
watcher_log() {
|
|
local file="$1"
|
|
shift
|
|
mkdir -p "$(dirname "${file}")"
|
|
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >> "${file}"
|
|
}
|
|
|
|
utc_now() {
|
|
date -u +%Y-%m-%dT%H:%M:%SZ
|
|
}
|
|
|
|
require_cmd() {
|
|
local c
|
|
for c in "$@"; do
|
|
if ! command -v "${c}" >/dev/null 2>&1; then
|
|
echo "error: required command not found: ${c}" >&2
|
|
return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
# True if a process whose args contain the given regex is running (excludes awk).
|
|
process_running() {
|
|
local pattern="$1"
|
|
ps -eo args 2>/dev/null | awk -v p="${pattern}" '
|
|
$0 ~ p && $0 !~ /awk/ { found=1 }
|
|
END { exit !found }
|
|
'
|
|
}
|