Skip to content

Respond to Review Comments #18

Respond to Review Comments

Respond to Review Comments #18

Workflow file for this run

name: Respond to Review Comments
on:
pull_request_review_comment:
types: [created]
jobs:
respond-to-comment:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Respond to Comment
env:
COMMENT_ID: ${{ github.event.comment.id }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch details about the original comment
COMMENT_DATA=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/pulls/comments/$COMMENT_ID)
# Extract necessary details using bash string manipulation
COMMIT_ID=$(echo "$COMMENT_DATA" | tr ',' '\n' | grep '"commit_id"' | cut -d '"' -f 4)
PATH=$(echo "$COMMENT_DATA" | tr ',' '\n' | grep '"path"' | cut -d '"' -f 4)
POSITION=$(echo "$COMMENT_DATA" | tr ',' '\n' | grep '"position"' | cut -d ':' -f 2 | tr -d ' ')
# Post a new comment in the same context as the original comment
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/pulls/$PULL_REQUEST_NUMBER/comments \
-d "{\"body\": \"Thanks for your reply!\", \"commit_id\": \"$COMMIT_ID\", \"path\": \"$PATH\", \"position\": $POSITION}"