Skip to content

feat: add GitHub Actions workflow for automatic review requests #14

feat: add GitHub Actions workflow for automatic review requests

feat: add GitHub Actions workflow for automatic review requests #14

Workflow file for this run

name: Auto Request Review
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches-ignore:
- main
- master
jobs:
request-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Handle PR and Review
env:
GH_TOKEN: ${{ secrets.REVIEW_TOKEN }}
REVIEWER: review-deriv
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Requesting review for PR #${{ github.event.pull_request.number }}"
gh pr edit ${{ github.event.pull_request.number }} --add-reviewer $REVIEWER
else
current_branch="${{ github.ref_name }}"
default_branch=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)
echo "Current branch: $current_branch"
echo "Default branch: $default_branch"
# Check for existing PR
existing_pr=$(gh pr list --head "$current_branch" --state open --json number --jq '.[0].number')
if [ -z "$existing_pr" ]; then
echo "Creating new PR..."
pr_number=$(gh pr create --title "Review requested for $current_branch" \
--body "Automated pull request for review" \
--base "$default_branch" \
--head "$current_branch" \
--json number --jq .number)
echo "Created PR #$pr_number"
# Request review for the new PR
gh pr edit "$pr_number" --add-reviewer $REVIEWER
else
echo "PR already exists: #$existing_pr"
gh pr edit "$existing_pr" --add-reviewer $REVIEWER
fi
fi