This commit is contained in:
2025-11-09 06:26:59 -05:00
parent 260016a55b
commit 3b7f6a5a39
2 changed files with 27 additions and 7 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ inputs:
pr_comments_url: pr_comments_url:
description: "PR comments URL (GitHub or Gitea)" description: "PR comments URL (GitHub or Gitea)"
required: true required: false
pr_comment_id: pr_comment_id:
description: "Existing PR comment ID if updating" description: "Existing PR comment ID if updating"
+26 -6
View File
@@ -12,7 +12,7 @@ PR_COMMENT_ID="${PR_COMMENT_ID:-}"
PR_COMMENT_URI="${PR_COMMENT_URI:-}" PR_COMMENT_URI="${PR_COMMENT_URI:-}"
GITHUB_TOKEN="${GITHUB_TOKEN:-}" GITHUB_TOKEN="${GITHUB_TOKEN:-}"
# === Validate required inputs ======================================== # === Validate inputs =================================================
if [[ -z "$COMMENTER_TYPE" ]]; then if [[ -z "$COMMENTER_TYPE" ]]; then
echo "❌ commenter_type is required." echo "❌ commenter_type is required."
exit 1 exit 1
@@ -24,7 +24,7 @@ if [[ -z "$GITHUB_TOKEN" ]]; then
fi fi
# === Move into working directory if specified ======================== # === Move into working directory if specified ========================
if [[ -n "$WORKING_DIR" && "$WORKING_DIR" != "0" ]]; then if [[ -n "$WORKING_DIR" ]]; then
TARGET_DIR="${GITHUB_WORKSPACE}/${WORKING_DIR}" TARGET_DIR="${GITHUB_WORKSPACE}/${WORKING_DIR}"
if [[ ! -d "$TARGET_DIR" ]]; then if [[ ! -d "$TARGET_DIR" ]]; then
echo "❌ Error: Cannot change to working directory '${WORKING_DIR}'" echo "❌ Error: Cannot change to working directory '${WORKING_DIR}'"
@@ -33,7 +33,6 @@ if [[ -n "$WORKING_DIR" && "$WORKING_DIR" != "0" ]]; then
echo "🔹 Changing to working directory: $WORKING_DIR" echo "🔹 Changing to working directory: $WORKING_DIR"
cd "$TARGET_DIR" cd "$TARGET_DIR"
else else
echo "⚠️ Detected empty or numeric working_dir ('${WORKING_DIR:-unset}'); treating as unset."
cd "${GITHUB_WORKSPACE:-.}" cd "${GITHUB_WORKSPACE:-.}"
fi fi
@@ -68,12 +67,33 @@ ${COMMENTER_INPUT}
${EXIT_STATUS_MSG} ${EXIT_STATUS_MSG}
" "
# === Post Comment ==================================================== # === Determine PR_COMMENTS_URL if missing ===========================
if [[ -z "$PR_COMMENTS_URL" ]]; then if [[ -z "$PR_COMMENTS_URL" ]]; then
echo "❌ Missing PR_COMMENTS_URL environment variable." echo "⚠️ PR_COMMENTS_URL not provided, attempting to generate..."
exit 1
if [[ -n "$GITEA_API_URL" && -n "$GITEA_REPOSITORY" && -n "$GITEA_PULL_REQUEST_ID" ]]; then
PR_COMMENTS_URL="${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/${GITEA_PULL_REQUEST_ID}/comments"
PR_COMMENT_URI="${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/issues/comments"
echo "✅ Generated Gitea PR_COMMENTS_URL: $PR_COMMENTS_URL"
elif [[ -n "$GITHUB_EVENT_PATH" && -f "$GITHUB_EVENT_PATH" ]]; then
PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
if [[ "$PR_NUMBER" != "null" ]]; then
PR_COMMENTS_URL=$(jq -r ".pull_request.comments_url" "$GITHUB_EVENT_PATH")
PR_COMMENT_URI=$(jq -r ".repository.issue_comment_url" "$GITHUB_EVENT_PATH" | sed "s|{/number}||g")
echo "✅ Generated GitHub PR_COMMENTS_URL: $PR_COMMENTS_URL"
else
echo "❌ Not a pull request. Cannot generate PR_COMMENTS_URL."
exit 0
fi
else
echo "❌ Cannot determine PR_COMMENTS_URL automatically. Please provide it as input."
exit 1
fi
fi fi
# === Post Comment ====================================================
if [[ -n "$PR_COMMENT_ID" && -n "$PR_COMMENT_URI" ]]; then if [[ -n "$PR_COMMENT_ID" && -n "$PR_COMMENT_URI" ]]; then
echo "🌀 Updating existing comment (ID: ${PR_COMMENT_ID})" echo "🌀 Updating existing comment (ID: ${PR_COMMENT_ID})"
curl -sS -X PATCH \ curl -sS -X PATCH \