#!/usr/bin/env bash # Seed a running local stack (e2e/stack.sh) through the dashboard's own HTTP # API, so the seed exercises real validation. Safe to run again: each step # skips what already exists. set -euo pipefail base=${ARCHIE_E2E_API:-http://localhost:8484} here=$(cd "$(dirname "$0")" && pwd) H=(-H 'Content-Type: application/json' -H 'X-Archie-CSRF: 1' -H "Origin: $base") get() { curl -fsS "$base$1"; } post() { curl -fsS -X POST "$base$1" "${H[@]}" -d "$2"; } # jq-free JSON reads: py EXPR, with the parsed body as d. py() { python3 -c "import sys, json; d = json.load(sys.stdin); print($1)"; } # Repository policy. archied applies it live; the pause lets the watch publish it. if ! get /api/control-plane/resources/repository-policies | grep -q '"widgets"'; then version=$(get /api/control-plane/resources/repository-policies | py 'd["resource"]["version"]') post /api/control-plane/resources/repository-policies/commands/replace \ "{\"value\":[{\"owner\":\"acme\",\"name\":\"widgets\",\"base\":\"main\"}],\"expected_version\":$version}" >/dev/null sleep 5 fi # Work requests. Without Docker they park within a minute, which fills # Needs you, Quality gates and the task pages. tasks=$(get /api/tasks) for t in "Fix flaky login test" "Add retry to webhook sender" "Document the gate" "Speed up the CI cache"; do grep -qF "\"$t\"" <<<"$tasks" && continue post /api/work-requests "{\"identity\":\"archie-dev\",\"repository\":\"acme/widgets\",\"workflow\":\"triage\",\"title\":\"$t\",\"instructions\":\"Do it.\"}" >/dev/null done # An unsigned capture source with one delivery, an event type, a mapping and # a binding left pending approval. src=e2e-hook if ! get /api/sources | grep -q "\"$src\""; then post /api/sources "{\"path\":\"$src\"}" >/dev/null post "/api/sources/$src/signing" '{"signed":false}' >/dev/null post "/api/sources/$src/approve-unsigned" '{}' >/dev/null bash "$here/../tools/webhook-send.sh" --url "$base" --source "$src" --kind github-issue >/dev/null fi et=$(get /api/event-types | py '"".join(t["id"] for t in (d.get("event_types", []) if isinstance(d, dict) else d) if t["name"] == "issue-opened")') if [ -z "$et" ]; then et=$(post /api/event-types "{\"source\":\"$src\",\"name\":\"issue-opened\",\"rule\":{\"headers\":[],\"payload\":[{\"path\":\"action\",\"op\":\"equals\",\"value\":\"opened\"}]},\"example\":{\"headers\":{},\"body\":\"{\\\"action\\\":\\\"opened\\\",\\\"issue\\\":{\\\"title\\\":\\\"x\\\"}}\"}}" | py 'd["id"]') fi if ! get /api/bindings | grep -q '"e2e-binding"'; then mapping=$(post /api/mappings "{\"name\":\"e2e-issue\",\"source_hint\":\"$src\",\"event_type_id\":\"$et\",\"fields\":[{\"name\":\"title\",\"path\":\"issue.title\",\"type\":\"string\",\"required\":true}]}" | py 'd["id"]') post /api/bindings "{\"name\":\"e2e-binding\",\"matcher\":{\"source\":\"$src\"},\"mapping_id\":\"$mapping\",\"workflow\":\"feasibility\",\"owner\":\"acme\",\"repo\":\"widgets\"}" >/dev/null fi echo "seeded: $(get /api/tasks | py 'len(d.get("tasks", d) if isinstance(d, dict) else d)') tasks"