Daily PR Complexity Labeling #75
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
| # Daily PR Complexity Labeling | |
| # | |
| # This workflow analyzes closed PRs in a GitHub organization and applies | |
| # complexity labels (e.g. complexity:5) to them. It runs: | |
| # - On schedule: daily at 1am UTC, labeling PRs closed the previous day | |
| # - On demand: via workflow_dispatch with optional date range and provider | |
| # | |
| # Flow: Fetch closed PRs for org + date range → Run LLM analysis on each diff → | |
| # Parse 1–10 score → Apply/update complexity:N label on GitHub | |
| # | |
| # Required secrets: ORG_GITHUB_TOKEN, OPENAI_API_KEY (or ANTHROPIC_API_KEY for anthropic) | |
| # Optional vars: COMPLEXITY_ORG (default org), COMPLEXITY_PROVIDER (openai|anthropic|bedrock) | |
| name: Daily PR Complexity Labeling | |
| on: | |
| schedule: | |
| # Run at 1am UTC every day | |
| - cron: '0 1 * * *' | |
| workflow_dispatch: | |
| # Allow manual trigger with optional date range | |
| inputs: | |
| org: | |
| description: 'GitHub organization name (overrides COMPLEXITY_ORG variable)' | |
| required: false | |
| type: string | |
| since: | |
| description: 'Start date (YYYY-MM-DD). Defaults to yesterday.' | |
| required: false | |
| type: string | |
| until: | |
| description: 'End date (YYYY-MM-DD). Defaults to same as start date.' | |
| required: false | |
| type: string | |
| force: | |
| description: 'Re-analyze PRs even if already labeled' | |
| required: false | |
| type: boolean | |
| default: false | |
| provider: | |
| description: 'LLM provider: openai, anthropic, or bedrock' | |
| required: false | |
| type: string | |
| default: 'anthropic' | |
| jobs: | |
| label-prs: | |
| if: false # Disabled | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| pip install -e . | |
| - name: Calculate date range | |
| id: dates | |
| run: | | |
| # Set start date (since) | |
| if [ -n "${{ inputs.since }}" ]; then | |
| SINCE_DATE="${{ inputs.since }}" | |
| else | |
| # Default to yesterday | |
| SINCE_DATE=$(date -d "yesterday" +%Y-%m-%d) | |
| fi | |
| # Set end date (until) | |
| if [ -n "${{ inputs.until }}" ]; then | |
| UNTIL_DATE="${{ inputs.until }}" | |
| else | |
| # Default to same as start date | |
| UNTIL_DATE="$SINCE_DATE" | |
| fi | |
| echo "since=$SINCE_DATE" >> $GITHUB_OUTPUT | |
| echo "until=$UNTIL_DATE" >> $GITHUB_OUTPUT | |
| echo "Processing PRs from $SINCE_DATE to $UNTIL_DATE" | |
| - name: Label PRs with complexity | |
| env: | |
| # Requires a PAT with repo scope and SSO authorization for the target org | |
| # This is a personal token created by ohad to test the value of this workflow. | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
| run: | | |
| # Determine org: input takes precedence over repository variable | |
| ORG="${{ inputs.org }}" | |
| if [ -z "$ORG" ]; then | |
| ORG="${{ vars.COMPLEXITY_ORG }}" | |
| fi | |
| if [ -z "$ORG" ]; then | |
| echo "Error: No organization specified." | |
| echo "Set the COMPLEXITY_ORG repository variable or provide --org input." | |
| exit 1 | |
| fi | |
| FORCE_FLAG="" | |
| if [ "${{ inputs.force }}" = "true" ]; then | |
| FORCE_FLAG="--force" | |
| fi | |
| # Provider: input (manual run) > COMPLEXITY_PROVIDER var > anthropic | |
| PROVIDER="${{ inputs.provider }}" | |
| if [ -z "$PROVIDER" ]; then | |
| PROVIDER="${{ vars.COMPLEXITY_PROVIDER }}" | |
| fi | |
| if [ -z "$PROVIDER" ]; then | |
| PROVIDER="anthropic" | |
| fi | |
| complexity-cli batch-analyze \ | |
| --org "$ORG" \ | |
| --since "${{ steps.dates.outputs.since }}" \ | |
| --until "${{ steps.dates.outputs.until }}" \ | |
| --label \ | |
| --workers 5 \ | |
| --provider "$PROVIDER" \ | |
| $FORCE_FLAG | |
| - name: Summary | |
| if: always() | |
| run: | | |
| ORG="${{ inputs.org }}" | |
| if [ -z "$ORG" ]; then | |
| ORG="${{ vars.COMPLEXITY_ORG }}" | |
| fi | |
| PROVIDER="${{ inputs.provider }}" | |
| if [ -z "$PROVIDER" ]; then | |
| PROVIDER="${{ vars.COMPLEXITY_PROVIDER }}" | |
| fi | |
| if [ -z "$PROVIDER" ]; then | |
| PROVIDER="anthropic" | |
| fi | |
| echo "## PR Complexity Labeling Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Date range:** ${{ steps.dates.outputs.since }} to ${{ steps.dates.outputs.until }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Organization:** $ORG" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Provider:** $PROVIDER" >> $GITHUB_STEP_SUMMARY | |