Repo sync for protected branch #437
Workflow file for this run
This file contains hidden or 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: Bypass Code Owner Approval | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
jobs: | |
bypass_approval: | |
runs-on: ubuntu-latest | |
env: | |
ACTION_TOKEN_SS: ${{ secrets.ACTIONTOKEN_SS }} | |
ACTION_TOKEN_YS: ${{ secrets.ACTIONTOKEN_YS }} | |
steps: | |
- name: Approve PR if author is a code owner | |
id: check-author | |
run: | | |
echo "Check if PR author is a code owner" | |
# Fetch team members from both teams | |
TEAM_MEMBERS=$(curl -s -H "Authorization: token $ACTION_TOKEN_SS" https://api.github.com/orgs/MicrosoftDocs/teams/kusto-doc-writers/members) | |
TEAM_MEMBERS="$TEAM_MEMBERS $(curl -s -H "Authorization: token $ACTION_TOKEN_SS" https://api.github.com/orgs/MicrosoftDocs/teams/apex-docs-pr-reviewers/members)" | |
TEAM_MEMBERS="$TEAM_MEMBERS $(curl -s -H "Authorization: token $ACTION_TOKEN_SS" https://api.github.com/orgs/MicrosoftDocs/teams/pubdesk/members)" | |
echo "Team members: $TEAM_MEMBERS" | |
# Check if the PR author is a code owner | |
echo "Checking if login is codeowner in team -- ${{ github.actor }}" | |
IS_CODEOWNER=false | |
if echo "$TEAM_MEMBERS" | grep -q "\"login\": \"${{ github.actor }}\""; then | |
echo "Login Found" | |
IS_CODEOWNER=true | |
fi | |
echo "is_codeowner == $IS_CODEOWNER" | |
# Bypass approval if the author is a code owner | |
if $IS_CODEOWNER; then | |
echo "Bypassing approval for code owner" | |
if [ "${{ github.actor }}" == "shsagir" ]; then | |
ACTION_TOKEN=$ACTION_TOKEN_YS | |
else | |
ACTION_TOKEN=$ACTION_TOKEN_SS | |
fi | |
curl -s -X POST -H "Authorization: token $ACTION_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews \ | |
-d '{"event":"APPROVE"}' | |
fi |