fix: extract file_action_issue helper to eliminate duplicate code blocks
CI duplicate-detection flagged shared action-issue filing pattern between gardener-run.sh and planner-poll.sh. Extract into lib/file-action-issue.sh and refactor both scripts to use it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
eb90a42095
commit
59b6d76afa
4 changed files with 87 additions and 78 deletions
|
|
@ -8,16 +8,17 @@
|
|||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
FACTORY_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
FACTORY_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
|
||||
# Load shared environment (with optional project TOML override)
|
||||
# Usage: gardener-run.sh [projects/harb.toml]
|
||||
export PROJECT_TOML="${1:-}"
|
||||
# shellcheck source=../lib/env.sh
|
||||
source "$FACTORY_ROOT/lib/env.sh"
|
||||
# shellcheck source=../lib/file-action-issue.sh
|
||||
source "$FACTORY_ROOT/lib/file-action-issue.sh"
|
||||
|
||||
LOG_FILE="$SCRIPT_DIR/gardener.log"
|
||||
LOG_FILE="$FACTORY_ROOT/gardener/gardener.log"
|
||||
LOCK_FILE="/tmp/gardener-run.lock"
|
||||
|
||||
log() { echo "[$(date -u +%Y-%m-%dT%H:%M:%S)Z] $*" >> "$LOG_FILE"; }
|
||||
|
|
@ -43,28 +44,7 @@ fi
|
|||
|
||||
log "--- Gardener run start ---"
|
||||
|
||||
# ── Dedup: skip if an open run-gardener action issue already exists ───────
|
||||
OPEN_ACTIONS=$(codeberg_api GET "/issues?state=open&type=issues&labels=action&limit=50" 2>/dev/null || true)
|
||||
if [ -n "$OPEN_ACTIONS" ] && [ "$OPEN_ACTIONS" != "null" ]; then
|
||||
EXISTING=$(printf '%s' "$OPEN_ACTIONS" | \
|
||||
jq '[.[] | select(.title | test("run-gardener"))] | length' 2>/dev/null || echo 0)
|
||||
if [ "${EXISTING:-0}" -gt 0 ]; then
|
||||
log "poll: open run-gardener action issue already exists — skipping"
|
||||
log "--- Gardener run done ---"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# ── Fetch 'action' label ID ──────────────────────────────────────────────
|
||||
ACTION_LABEL_ID=$(codeberg_api GET "/labels" 2>/dev/null | \
|
||||
jq -r '.[] | select(.name == "action") | .id' 2>/dev/null || true)
|
||||
|
||||
if [ -z "$ACTION_LABEL_ID" ]; then
|
||||
log "ERROR: 'action' label not found — cannot file gardener issue"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ── File action issue ─────────────────────────────────────────────────────
|
||||
# ── File action issue for run-gardener formula ────────────────────────────
|
||||
ISSUE_BODY="---
|
||||
formula: run-gardener
|
||||
model: opus
|
||||
|
|
@ -76,21 +56,20 @@ AGENTS.md update, and commit-and-pr.
|
|||
|
||||
Filed automatically by \`gardener-run.sh\`."
|
||||
|
||||
PAYLOAD=$(jq -nc \
|
||||
--arg title "action: run-gardener — periodic housekeeping" \
|
||||
--arg body "$ISSUE_BODY" \
|
||||
--argjson labels "[$ACTION_LABEL_ID]" \
|
||||
'{title: $title, body: $body, labels: $labels}')
|
||||
_rc=0
|
||||
file_action_issue "run-gardener" "action: run-gardener — periodic housekeeping" "$ISSUE_BODY" || _rc=$?
|
||||
case "$_rc" in
|
||||
0) ;;
|
||||
1) log "poll: open run-gardener action issue already exists — skipping"
|
||||
log "--- Gardener run done ---"
|
||||
exit 0 ;;
|
||||
2) log "ERROR: 'action' label not found — cannot file gardener issue"
|
||||
exit 1 ;;
|
||||
*) log "ERROR: failed to create action issue for run-gardener"
|
||||
exit 1 ;;
|
||||
esac
|
||||
|
||||
RESULT=$(codeberg_api POST "/issues" -d "$PAYLOAD" 2>/dev/null || true)
|
||||
ISSUE_NUM=$(printf '%s' "$RESULT" | jq -r '.number // empty' 2>/dev/null || true)
|
||||
|
||||
if [ -z "$ISSUE_NUM" ]; then
|
||||
log "ERROR: failed to create action issue for run-gardener"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Filed action issue #${ISSUE_NUM} for run-gardener formula"
|
||||
matrix_send "gardener" "Filed action #${ISSUE_NUM}: run-gardener — periodic housekeeping" 2>/dev/null || true
|
||||
log "Filed action issue #${FILED_ISSUE_NUM} for run-gardener formula"
|
||||
matrix_send "gardener" "Filed action #${FILED_ISSUE_NUM}: run-gardener — periodic housekeeping" 2>/dev/null || true
|
||||
|
||||
log "--- Gardener run done ---"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue