chore: github repository configuration #2
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: Enforce Review Rules | |
on: | |
pull_request: | |
types: [opened, edited, synchronize] | |
jobs: | |
enforce-review-rules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get list of files changed | |
id: files | |
run: | | |
echo "::set-output name=files::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | tr '\n' ' ')" | |
- name: Check if PR modifies specific path | |
id: check-path | |
run: | | |
if echo "${{ steps.files.outputs.files }}" | grep -q '^src/'; then | |
echo "::set-output name=specific_path::true" | |
else | |
echo "::set-output name=specific_path::false" | |
fi | |
- name: Ensure required reviewers | |
id: ensure-reviewers | |
run: | | |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
REPO=${{ github.repository }} | |
# Fetch reviewers of the PR | |
REVIEWERS=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | |
"https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/reviews" \ | |
| jq -r '.[].user.login') | |
NUM_REVIEWERS=$(echo "$REVIEWERS" | wc -w) | |
# Check review requirements | |
if [ "${{ steps.check-path.outputs.specific_path }}" == "true" ]; then | |
if [ "$NUM_REVIEWERS" -lt 2 ]; then | |
echo "Insufficient reviewers for src/ path. Required: 2 reviewers." | |
echo "::set-output name=review_check_passed::false" | |
exit 1 | |
fi | |
fi | |
echo "::set-output name=review_check_passed::true" | |
- name: Success message | |
if: success() | |
run: echo "Review checks passed successfully!" |