Skip to content

Commit

Permalink
Merge pull request #4 from 1Password/pull-request-target-support
Browse files Browse the repository at this point in the history
Use commits URL from PR event data
  • Loading branch information
SimonBarendse authored Sep 22, 2023
2 parents 435daf5 + b7e71bf commit 8b94ee1
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,16 @@ runs:
GITHUB_TOKEN: ${{ inputs.token }}
COMMENT_TEXT: ${{ inputs.comment }}
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
COMMITS_URL: ${{ github.event.pull_request.commits_url }}
run: |
# Escape double quotes and newlines
COMMENT_TEXT="$(echo "$COMMENT_TEXT" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')"
GITHUB_PR=$(echo $GITHUB_REF | sed -n 's/refs\/pull\/\([0-9]*\)\/merge/\1/p')
if [[ -z "$GITHUB_PR" ]]; then
echo "No PR found to scan for commits."
exit 0
fi
unsigned_commits="$(curl -s -H "Authorization: token $GITHUB_TOKEN" "${GITHUB_API_URL:-https://api.github.com}/repos/$GITHUB_REPOSITORY/pulls/$GITHUB_PR/commits" | jq '.[] | select(.commit.verification.verified == false) | .commit.message')"
unsigned_commits="$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$COMMITS_URL" | jq '.[] | select(.commit.verification.verified == false) | .commit.message')"
if [[ -n "$unsigned_commits" ]]; then
echo "Found unsigned commits:"
echo "$unsigned_commits"
# Escape double quotes and newlines in comment
COMMENT_TEXT="$(echo "$COMMENT_TEXT" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}')"
curl -X POST $COMMENTS_URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
Expand Down

0 comments on commit 8b94ee1

Please sign in to comment.