#!/usr/bin/env bash # add-comment.sh "" # Adds a comment to a tracker issue. # Reads TRACKER_URL and JIRA_TOKEN from the environment. No secrets are hardcoded. set -euo pipefail KEY="${1:?usage: add-comment.sh \"\"}" TEXT="${2:?usage: add-comment.sh \"\"}" : "${TRACKER_URL:?set TRACKER_URL (or take the tracker address from the session corporate context)}" : "${JIRA_TOKEN:?set JIRA_TOKEN (tracker personal access token)}" BASE="${TRACKER_URL%/}" # Build JSON body safely (jq escapes the text); fall back to a naive body if jq is absent. if command -v jq >/dev/null 2>&1; then BODY="$(jq -n --arg b "$TEXT" '{body: $b}')" else BODY="{\"body\": \"${TEXT//\"/\\\"}\"}" fi curl -fsS -X POST \ -H "Authorization: Bearer ${JIRA_TOKEN}" \ -H "Content-Type: application/json" \ -d "$BODY" \ "${BASE}/rest/api/2/issue/${KEY}/comment" >/dev/null echo "Comment added to ${KEY}"