Skip to content

fix: remove kustomize dependency #295

fix: remove kustomize dependency

fix: remove kustomize dependency #295

Workflow file for this run

name: Auto Assign Reviewers
on:
pull_request:
types: [opened]
pull_request_target:
types: [opened]
permissions:
contents: read
pull-requests: write
jobs:
auto-assign:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Auto assign reviewers
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
if [ ! -f "OWNERS" ]; then
echo "OWNERS file not found, skipping auto-assignment"
exit 0
fi
in_auto_assign=false
all_reviewers=""
# Helper: normalize a reviewer (strip @ and whitespace)
normalize_reviewer() {
echo "$1" | sed -E 's/^[[:space:]]*@?//; s/[[:space:]]*$//'
}
# Parse OWNERS
while IFS= read -r line; do
# Skip comments/empty
[[ -z "${line// }" || "$line" =~ ^[[:space:]]*# ]] && continue
# Enter auto-assign section
if [[ "$line" =~ ^auto-assign: ]]; then
in_auto_assign=true
continue
fi
# Exit auto-assign section when a new top-level key is encountered
if $in_auto_assign && [[ "$line" =~ ^[^[:space:]] ]]; then
in_auto_assign=false
fi
$in_auto_assign || continue
# Reviewer entry: collect the user directly
if [[ "$line" =~ ^[[:space:]]*-[[:space:]]*([^:]+)$ ]]; then
reviewer=$(normalize_reviewer "$(echo "$line" | sed -E 's/^[[:space:]]*-[[:space:]]*//')")
echo "Found reviewer: $reviewer"
all_reviewers+="$reviewer"$'\n'
fi
done < OWNERS
# De-dup, drop blanks, exclude PR author, shuffle to randomize, and take the top 2
mapfile -t reviewers < <(printf "%s" "$all_reviewers" | sed '/^$/d' | sort -u | grep -v -x "$PR_AUTHOR" | shuf -n 2 || true)
if [ "${#reviewers[@]}" -eq 0 ]; then
echo "No reviewers found for auto-assignment"
exit 0
fi
echo "Assigning ${#reviewers[@]} reviewer(s): ${reviewers[*]}"
# Convert the reviewers array to JSON
payload=$(printf '%s\n' "${reviewers[@]}" | jq -R -s -c 'split("\n") | map(select(length>0))')
# Request reviewers
curl -sS -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/requested_reviewers" \
-d "{\"reviewers\": $payload}" \
| jq -r '.message? // "ok"'