|
| 1 | +name: AI Triage - Process All Open Issues |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + dry_run: |
| 6 | + description: 'Dry run mode - only list issues without processing' |
| 7 | + required: false |
| 8 | + default: false |
| 9 | + type: boolean |
| 10 | + max_issues: |
| 11 | + description: 'Maximum number of issues to process (0 = all)' |
| 12 | + required: false |
| 13 | + default: '0' |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + issues: write |
| 18 | + contents: read |
| 19 | + actions: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + get_open_issues: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + issue_numbers: ${{ steps.get_issues.outputs.issue_numbers }} |
| 26 | + total_count: ${{ steps.get_issues.outputs.total_count }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Get all open issues |
| 30 | + id: get_issues |
| 31 | + uses: actions/github-script@v6 |
| 32 | + with: |
| 33 | + script: | |
| 34 | + // Use Search API to filter issues at API level |
| 35 | + const { data } = await github.rest.search.issuesAndPullRequests({ |
| 36 | + q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open -label:ai-triaged -label:invalid`, |
| 37 | + sort: 'created', |
| 38 | + order: 'asc', |
| 39 | + per_page: 100 |
| 40 | + }); |
| 41 | + |
| 42 | + const actualIssues = data.items; |
| 43 | + |
| 44 | + let issuesToProcess = actualIssues; |
| 45 | + const maxIssues = parseInt('${{ inputs.max_issues }}' || '0'); |
| 46 | + |
| 47 | + if (maxIssues > 0 && actualIssues.length > maxIssues) { |
| 48 | + issuesToProcess = actualIssues.slice(0, maxIssues); |
| 49 | + console.log(`Limiting to first ${maxIssues} issues out of ${actualIssues.length} total`); |
| 50 | + } |
| 51 | + |
| 52 | + const issueNumbers = issuesToProcess.map(issue => issue.number); |
| 53 | + const totalCount = issuesToProcess.length; |
| 54 | + |
| 55 | + console.log(`Found ${actualIssues.length} open issues, processing ${totalCount}:`); |
| 56 | + issuesToProcess.forEach(issue => { |
| 57 | + console.log(` #${issue.number}: ${issue.title}`); |
| 58 | + }); |
| 59 | + |
| 60 | + core.setOutput('issue_numbers', JSON.stringify(issueNumbers)); |
| 61 | + core.setOutput('total_count', totalCount); |
| 62 | +
|
| 63 | + process_issues: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: get_open_issues |
| 66 | + if: needs.get_open_issues.outputs.total_count > 0 |
| 67 | + |
| 68 | + strategy: |
| 69 | + # Process issues one by one (max-parallel: 1) |
| 70 | + max-parallel: 1 |
| 71 | + matrix: |
| 72 | + issue_number: ${{ fromJSON(needs.get_open_issues.outputs.issue_numbers) }} |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Log current issue being processed |
| 76 | + run: | |
| 77 | + echo "🔄 Processing issue #${{ matrix.issue_number }}" |
| 78 | + echo "Total issues to process: ${{ needs.get_open_issues.outputs.total_count }}" |
| 79 | + |
| 80 | + - name: Check if dry run mode |
| 81 | + if: inputs.dry_run == true |
| 82 | + run: | |
| 83 | + echo "🔍 DRY RUN MODE: Would process issue #${{ matrix.issue_number }}" |
| 84 | + echo "Skipping actual triage processing" |
| 85 | + |
| 86 | + - name: Trigger triage workflow for issue |
| 87 | + if: inputs.dry_run != true |
| 88 | + uses: actions/github-script@v6 |
| 89 | + with: |
| 90 | + script: | |
| 91 | + const issueNumber = '${{ matrix.issue_number }}'; |
| 92 | + |
| 93 | + try { |
| 94 | + console.log(`Triggering triage workflow for issue #${issueNumber}`); |
| 95 | + |
| 96 | + const response = await github.rest.actions.createWorkflowDispatch({ |
| 97 | + owner: context.repo.owner, |
| 98 | + repo: context.repo.repo, |
| 99 | + workflow_id: 'triage-agent.yml', |
| 100 | + ref: 'main', |
| 101 | + inputs: { |
| 102 | + issue_number: issueNumber |
| 103 | + } |
| 104 | + }); |
| 105 | + |
| 106 | + console.log(`✅ Successfully triggered triage workflow for issue #${issueNumber}`); |
| 107 | + |
| 108 | + } catch (error) { |
| 109 | + console.error(`❌ Failed to trigger triage workflow for issue #${issueNumber}:`, error); |
| 110 | + core.setFailed(`Failed to process issue #${issueNumber}: ${error.message}`); |
| 111 | + } |
| 112 | + |
| 113 | + - name: Wait for workflow completion |
| 114 | + if: inputs.dry_run != true |
| 115 | + run: | |
| 116 | + echo "⏳ Waiting for triage workflow to complete for issue #${{ matrix.issue_number }}..." |
| 117 | + echo "Timeout: ${{ vars.TRIAGE_AGENT_TIMEOUT }} seconds" |
| 118 | + sleep ${{ vars.TRIAGE_AGENT_TIMEOUT }} # Wait for triage workflow completion |
| 119 | +
|
| 120 | + summary: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + needs: [get_open_issues, process_issues] |
| 123 | + if: always() |
| 124 | + |
| 125 | + steps: |
| 126 | + - name: Print summary |
| 127 | + run: | |
| 128 | + echo "## Triage Processing Summary" |
| 129 | + echo "Total open issues found: ${{ needs.get_open_issues.outputs.total_count }}" |
| 130 | + |
| 131 | + if [ "${{ inputs.dry_run }}" == "true" ]; then |
| 132 | + echo "Mode: DRY RUN (no actual processing performed)" |
| 133 | + else |
| 134 | + echo "Mode: FULL PROCESSING" |
| 135 | + fi |
| 136 | + |
| 137 | + if [ "${{ needs.process_issues.result }}" == "success" ]; then |
| 138 | + echo "✅ All issues processed successfully" |
| 139 | + elif [ "${{ needs.process_issues.result }}" == "failure" ]; then |
| 140 | + echo "❌ Some issues failed to process" |
| 141 | + elif [ "${{ needs.process_issues.result }}" == "skipped" ]; then |
| 142 | + echo "⏭️ Processing was skipped (no open issues found)" |
| 143 | + else |
| 144 | + echo "⚠️ Processing completed with status: ${{ needs.process_issues.result }}" |
| 145 | + fi |
0 commit comments