Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions bin/gh-attach
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pw_stop() {
if [[ -n "$keep_session" ]]; then
return 0
fi
"${pw_cli[@]}" session-stop >/dev/null 2>&1 || true
"${pw_cli[@]}" close >/dev/null 2>&1 || true
}

if [[ -n "$body_file" ]]; then
Expand Down Expand Up @@ -276,15 +276,8 @@ if [[ "$has_placeholder" == "false" ]]; then
fi
fi

# Create comment with placeholders (skipped in --url-only mode).
# In --url-only mode the caller posts their own comment with the returned URLs.
if [[ -z "$url_only" ]]; then
comment_info="$(gh api --hostname "$host" -X POST "repos/$repo/issues/$issue/comments" -f body="$body_with_placeholder" --jq '"\(.id)\t\(.html_url)"')"
comment_id="${comment_info%%$'\t'*}"
comment_url="${comment_info#*$'\t'}"
fi

# Upload images
# Upload images (comment creation is deferred until after successful upload
# to avoid orphan placeholder comments when uploads fail).
upload_urls=()

if [[ -n "$use_release" ]]; then
Expand Down Expand Up @@ -653,7 +646,7 @@ if [[ ${#images[@]} -ge 1 ]]; then
body_with_images="${body_with_images//$placeholder_single/$first_img_tag}"
fi

# Update the comment
gh api --hostname "$host" -X PATCH "repos/$repo/issues/comments/$comment_id" -f body="$body_with_images" >/dev/null
# Create the comment with final image tags (single POST, no orphan placeholders)
comment_url="$(gh api --hostname "$host" -X POST "repos/$repo/issues/$issue/comments" -f body="$body_with_images" --jq '.html_url')"

echo "Comment updated: $comment_url"
echo "Comment created: $comment_url"