Add automatic approval action #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Your Workflow Name | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
jobs: | |
your_job_name: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check PR author | |
run: | | |
PR_AUTHOR=$(curl -sSL https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r '.user.login') | |
if [[ "${{ github.actor }}" == "${PR_AUTHOR}" ]]; then | |
echo "PR author is the owner of the repository." | |
# Your steps for the case where the author is the owner | |
# Approve the pull request using GitHub API | |
TOKEN=${{ secrets.GITHUB_TOKEN }} | |
API_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews" | |
APPROVAL_RESPONSE=$(curl -X POST -H "Authorization: Bearer ${TOKEN}" -H "Accept: application/vnd.github.v3+json" -d '{"event": "APPROVE"}' ${API_URL}) | |
APPROVAL_STATUS=$(echo ${APPROVAL_RESPONSE} | jq -r '.state') | |
if [[ "${APPROVAL_STATUS}" == "APPROVED" ]]; then | |
echo "Pull request approved." | |
else | |
echo "Failed to approve pull request. Check workflow logs for details." | |
exit 1 | |
fi | |
else | |
echo "PR author is not the owner of the repository. Skipping this step." | |
# Your steps for the case where the author is not the owner | |
fi |