Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 |