diff --git a/dev/dev-poll.sh b/dev/dev-poll.sh index bd3e67d..dd58306 100755 --- a/dev/dev-poll.sh +++ b/dev/dev-poll.sh @@ -125,7 +125,7 @@ open_pr_exists() { # Relabel a stale in-progress issue to blocked with diagnostic comment # Args: issue_number reason -# Returns: 0 on success, 1 on failure +# Uses shared helpers from lib/issue-lifecycle.sh relabel_stale_issue() { local issue="$1" reason="$2" @@ -149,25 +149,17 @@ relabel_stale_issue() { -d "{\"labels\":[${bk_id}]}" >/dev/null 2>&1 || true fi - # Post diagnostic comment - local tmpfile - tmpfile=$(mktemp /tmp/stale-issue-XXXXXX.md) - { + # Post diagnostic comment using shared helper + local comment_body + comment_body=$( printf '### Stale in-progress issue detected\n\n' printf '| Field | Value |\n|---|---|\n' printf '| Detection reason | `%s` |\n' "$reason" printf '| Timestamp | `%s` |\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" printf '\n**Status:** This issue was labeled `in-progress` but no active tmux session exists.\n' printf '**Action required:** A maintainer should triage this issue.\n' - } > "$tmpfile" - - jq -Rs '{body:.}' < "$tmpfile" > "${tmpfile}.json" - curl -sf -o /dev/null -X POST \ - -H "Authorization: token ${FORGE_TOKEN}" \ - -H "Content-Type: application/json" \ - "${API}/issues/${issue}/comments" \ - --data-binary @"${tmpfile}.json" 2>/dev/null || true - rm -f "$tmpfile" "${tmpfile}.json" + ) + _ilc_post_comment "$issue" "$comment_body" _ilc_log "stale issue #${issue} relabeled to blocked: ${reason}" } diff --git a/lib/issue-lifecycle.sh b/lib/issue-lifecycle.sh index 81586f9..6b14090 100644 --- a/lib/issue-lifecycle.sh +++ b/lib/issue-lifecycle.sh @@ -161,6 +161,27 @@ issue_release() { _ilc_log "released issue #${issue}" } +# --------------------------------------------------------------------------- +# _ilc_post_comment — Post a comment to an issue (internal helper) +# Args: issue_number body_text +# Uses a temp file to avoid large inline strings. +# --------------------------------------------------------------------------- +_ilc_post_comment() { + local issue="$1" body="$2" + + local tmpfile tmpjson + tmpfile=$(mktemp /tmp/ilc-comment-XXXXXX.md) + tmpjson="${tmpfile}.json" + printf '%s' "$body" > "$tmpfile" + jq -Rs '{body:.}' < "$tmpfile" > "$tmpjson" + curl -sf -o /dev/null -X POST \ + -H "Authorization: token ${FORGE_TOKEN}" \ + -H "Content-Type: application/json" \ + "${FORGE_API}/issues/${issue}/comments" \ + --data-binary @"$tmpjson" 2>/dev/null || true + rm -f "$tmpfile" "$tmpjson" +} + # --------------------------------------------------------------------------- # issue_block — add "blocked" label, post diagnostic comment, remove in-progress. # Args: issue_number reason [result_text] @@ -187,14 +208,9 @@ issue_block() { fi } > "$tmpfile" - # Post comment - jq -Rs '{body:.}' < "$tmpfile" > "${tmpfile}.json" - curl -sf -o /dev/null -X POST \ - -H "Authorization: token ${FORGE_TOKEN}" \ - -H "Content-Type: application/json" \ - "${FORGE_API}/issues/${issue}/comments" \ - --data-binary @"${tmpfile}.json" 2>/dev/null || true - rm -f "$tmpfile" "${tmpfile}.json" + # Post comment using shared helper + _ilc_post_comment "$issue" "$(cat "$tmpfile")" + rm -f "$tmpfile" # Remove in-progress, add blocked local ip_id bk_id