Bump codecov/codecov-action from 5.5.0 to 5.5.1 #611
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: Request Reviewers | |
on: | |
pull_request_target: | |
types: [opened, synchronize] | |
permissions: | |
contents: read | |
jobs: | |
request-reviewers: | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: read | |
issues: write | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 | |
with: | |
egress-policy: audit | |
- name: Checkout code | |
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
with: | |
fetch-depth: 20 # Ensure the last 20 commits are fetched to allow a proper diff | |
- name: Parse CODEOWNERS and request reviews | |
id: codeowners | |
run: | | |
echo "Parsing CODEOWNERS file..." | |
# Path to the CODEOWNERS file | |
CODEOWNERS_FILE=CODEOWNERS | |
# Changed files in the Pull Request | |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) | |
REVIEWERS="" | |
# Parse the CODEOWNERS file | |
while IFS= read -r line; do | |
# Ignore lines with comments or empty lines | |
[[ "$line" =~ ^#.*$ || -z "$line" ]] && continue | |
# Extract pattern and users | |
PATTERN=$(echo $line | awk '{print $1}') | |
USERS=$(echo $line | awk '{$1=""; print $0}' | tr ' ' ',') | |
# Check if changed files match the current pattern | |
for FILE in $CHANGED_FILES; do | |
if [[ "$FILE" == $PATTERN* ]]; then | |
if [[ -z "$REVIEWERS" ]]; then | |
REVIEWERS="$USERS" | |
else | |
REVIEWERS="$REVIEWERS,$USERS" | |
fi | |
fi | |
done | |
done < $CODEOWNERS_FILE | |
# Remove duplicate reviewers and leading/trailing commas | |
REVIEWERS=$(echo $REVIEWERS | tr ',' '\n' | sort | uniq | tr '\n' ',' | sed 's/^,*//;s/,*$//') | |
echo "Reviewers to be requested: $REVIEWERS" | |
echo "reviewers=$REVIEWERS" >> $GITHUB_OUTPUT | |
- name: Comment with Review Request | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
const reviewers = "${{ steps.codeowners.outputs.reviewers }}".split(','); | |
const { owner, repo } = context.repo; | |
const prNumber = context.payload.pull_request.number; | |
const prCreator = context.payload.pull_request.user.login; | |
for (const reviewer of reviewers) { | |
if (reviewer.trim().startsWith('@') && reviewer.trim() !== `@${prCreator}`) { | |
await github.rest.issues.createComment({ | |
owner, | |
repo, | |
issue_number: prNumber, | |
body: `${reviewer.trim()}, could you please review this change?` | |
}); | |
} | |
} |