Update main.yml #13
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: Pull Request Review Labeler | |
on: | |
pull_request: | |
types: [opened] | |
jobs: | |
check_author_team_membership: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get opsTrack team members | |
id: get_opsTrack_members | |
run: | | |
team_members=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/orgs/${{ github.event.organization.login }}/teams/opsTrack/members" | \ | |
grep -oP '"login": "\K([^"]+)') | |
echo "::set-output name=opsTrackMembers::$team_members" | |
- name: Check if author is opsTrack member | |
id: check_author | |
run: | | |
author_login=$(cat $GITHUB_EVENT_PATH | jq -r '.pull_request.user.login') | |
opsTrack_members=$(echo "${{ steps.get_opsTrack_members.outputs.opsTrackMembers }}" | tr '\n' ' ') | |
is_member=0 | |
for member in $opsTrack_members; do | |
if [ "$member" == "$author_login" ]; then | |
is_member=1 | |
break | |
fi | |
done | |
echo "::set-output name=isMember::$is_member" | |
label_pr_needing_reviews: | |
needs: check_author_team_membership | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if opsTrack member | |
id: opsTrack_member_check | |
run: echo "Author is opsTrack member:${{ needs.check_author_team_membership.outputs.isMember }}" | |
- name: Add label if opsTrack member | |
if: steps.opsTrack_member_check.outputs.isMember == '1' | |
run: | | |
echo "Author is a member of opsTrack team, adding label..." | |
curl -X POST \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/labels" \ | |
-d '{"labels":["codeowner reviews required"]}' |