Assign Dependabot PRs #27
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: "Assign Dependabot PRs" | |
| on: | |
| # Schedule to run 3 hours after Dependabot's weekly run on Monday | |
| schedule: | |
| # Run every Monday at 12:00 UTC (3 hours after Dependabot runs at 09:00 UTC) | |
| - cron: "0 12 * * 1" | |
| # Keep manual trigger option | |
| workflow_dispatch: | |
| inputs: | |
| process-all: | |
| description: "Process all open Dependabot PRs" | |
| type: boolean | |
| default: true | |
| specific-pr: | |
| description: "Process specific PR number (leave empty to process all)" | |
| required: false | |
| type: string | |
| jobs: | |
| process-dependabot-prs: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| issues: write # For label creation | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11.7" | |
| - name: Process specific PR if provided | |
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.specific-pr != '' | |
| uses: ./.github/actions/pr-assignment | |
| with: | |
| pr-number: ${{ github.event.inputs.specific-pr }} | |
| possible-assignees: ${{ vars.DEPENDABOT_ASSIGNEES || '' }} | |
| possible-reviewers: ${{ vars.DEPENDABOT_REVIEWERS || '' }} | |
| forced-assignees: ${{ vars.DEPENDABOT_FORCED_ASSIGNEES || '' }} | |
| forced-reviewers: ${{ vars.DEPENDABOT_FORCED_REVIEWERS || '' }} | |
| forced-labels: "" | |
| clear-existing-assignees: "true" | |
| clear-existing-reviewers: "true" | |
| clear-existing-labels: "true" | |
| - name: Process all open Dependabot PRs | |
| if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.specific-pr == '') | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| REPO: ${{ github.repository }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| POSSIBLE_ASSIGNEES: ${{ vars.DEPENDABOT_ASSIGNEES || '' }} | |
| POSSIBLE_REVIEWERS: ${{ vars.DEPENDABOT_REVIEWERS || '' }} | |
| FORCED_ASSIGNEES: ${{ vars.DEPENDABOT_FORCED_ASSIGNEES || '' }} | |
| FORCED_REVIEWERS: ${{ vars.DEPENDABOT_FORCED_REVIEWERS || '' }} | |
| # Define local variables for the clear flags and empty labels | |
| FORCED_LABELS: "" | |
| CLEAR_ASSIGNEES: "true" | |
| CLEAR_REVIEWERS: "true" | |
| CLEAR_LABELS: "true" | |
| run: | | |
| echo "Finding all open Dependabot PRs..." | |
| # Get all open PRs created by Dependabot | |
| DEPENDABOT_PRS=$(gh pr list --repo "$REPO" --author "dependabot[bot]" --state open --json number --jq '.[].number') | |
| if [ -z "$DEPENDABOT_PRS" ]; then | |
| echo "No open Dependabot PRs found." | |
| exit 0 | |
| fi | |
| echo "Found open Dependabot PRs: $DEPENDABOT_PRS" | |
| for PR_NUMBER in $DEPENDABOT_PRS; do | |
| echo "Checking assignees for PR #$PR_NUMBER" | |
| ASSIGNEE_COUNT=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json assignees --jq '.assignees | length') | |
| if [ "$ASSIGNEE_COUNT" -gt 0 ]; then | |
| echo "Skipping PR #$PR_NUMBER (already assigned)" | |
| continue | |
| fi | |
| echo "Processing Dependabot PR #$PR_NUMBER" | |
| # Make the script executable if it isn't already | |
| chmod +x ./.github/actions/pr-assignment/run.py | |
| # Run the Python script | |
| python3 ./.github/actions/pr-assignment/run.py \ | |
| "$PR_NUMBER" \ | |
| "$POSSIBLE_ASSIGNEES" \ | |
| "$POSSIBLE_REVIEWERS" \ | |
| "$FORCED_ASSIGNEES" \ | |
| "$FORCED_REVIEWERS" \ | |
| "$FORCED_LABELS" \ | |
| "$CLEAR_ASSIGNEES" \ | |
| "$CLEAR_REVIEWERS" \ | |
| "$CLEAR_LABELS" | |
| sleep 2 | |
| done | |
| echo "All eligible Dependabot PRs processed." |