|
| 1 | +name: Issue Deduplicator |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - labeled |
| 8 | + |
| 9 | +jobs: |
| 10 | + gather-duplicates: |
| 11 | + name: Identify potential duplicates |
| 12 | + if: ${{ github.event.action == 'opened' || (github.event.action == 'labeled' && github.event.label.name == 'codex-deduplicate') }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + outputs: |
| 17 | + codex_output: ${{ steps.codex.outputs.final-message }} |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Prepare Codex inputs |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ github.token }} |
| 24 | + run: | |
| 25 | + set -eo pipefail |
| 26 | +
|
| 27 | + CURRENT_ISSUE_FILE=codex-current-issue.json |
| 28 | + EXISTING_ISSUES_FILE=codex-existing-issues.json |
| 29 | +
|
| 30 | + gh issue list --repo "${{ github.repository }}" \ |
| 31 | + --json number,title,body,createdAt \ |
| 32 | + --limit 1000 \ |
| 33 | + --state all \ |
| 34 | + --search "sort:created-desc" \ |
| 35 | + | jq '.' \ |
| 36 | + > "$EXISTING_ISSUES_FILE" |
| 37 | +
|
| 38 | + gh issue view "${{ github.event.issue.number }}" \ |
| 39 | + --repo "${{ github.repository }}" \ |
| 40 | + --json number,title,body \ |
| 41 | + | jq '.' \ |
| 42 | + > "$CURRENT_ISSUE_FILE" |
| 43 | +
|
| 44 | + - id: codex |
| 45 | + uses: openai/codex-action@main |
| 46 | + with: |
| 47 | + openai-api-key: ${{ secrets.CODEX_OPENAI_API_KEY }} |
| 48 | + allow-users: "*" |
| 49 | + model: gpt-5 |
| 50 | + prompt: | |
| 51 | + You are an assistant that triages new GitHub issues by identifying potential duplicates. |
| 52 | +
|
| 53 | + You will receive the following JSON files located in the current working directory: |
| 54 | + - `codex-current-issue.json`: JSON object describing the newly created issue (fields: number, title, body). |
| 55 | + - `codex-existing-issues.json`: JSON array of recent issues (each element includes number, title, body, createdAt). |
| 56 | +
|
| 57 | + Instructions: |
| 58 | + - Compare the current issue against the existing issues to find up to five that appear to describe the same underlying problem or request. |
| 59 | + - Focus on the underlying intent and context of each issue—such as reported symptoms, feature requests, reproduction steps, or error messages—rather than relying solely on string similarity or synthetic metrics. |
| 60 | + - After your analysis, validate your results in 1-2 lines explaining your decision to return the selected matches. |
| 61 | + - When unsure, prefer returning fewer matches. |
| 62 | + - Include at most five numbers. |
| 63 | +
|
| 64 | + output-schema: | |
| 65 | + { |
| 66 | + "type": "object", |
| 67 | + "properties": { |
| 68 | + "issues": { |
| 69 | + "type": "array", |
| 70 | + "items": { |
| 71 | + "type": "string" |
| 72 | + } |
| 73 | + }, |
| 74 | + "reason": { "type": "string" } |
| 75 | + }, |
| 76 | + "required": ["issues", "reason"], |
| 77 | + "additionalProperties": false |
| 78 | + } |
| 79 | +
|
| 80 | + comment-on-issue: |
| 81 | + name: Comment with potential duplicates |
| 82 | + needs: gather-duplicates |
| 83 | + if: ${{ needs.gather-duplicates.result != 'skipped' }} |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + issues: write |
| 88 | + steps: |
| 89 | + - name: Comment on issue |
| 90 | + uses: actions/github-script@v7 |
| 91 | + env: |
| 92 | + CODEX_OUTPUT: ${{ needs.gather-duplicates.outputs.codex_output }} |
| 93 | + with: |
| 94 | + github-token: ${{ github.token }} |
| 95 | + script: | |
| 96 | + const raw = process.env.CODEX_OUTPUT ?? ''; |
| 97 | + let parsed; |
| 98 | + try { |
| 99 | + parsed = JSON.parse(raw); |
| 100 | + } catch (error) { |
| 101 | + core.info(`Codex output was not valid JSON. Raw output: ${raw}`); |
| 102 | + core.info(`Parse error: ${error.message}`); |
| 103 | + return; |
| 104 | + } |
| 105 | +
|
| 106 | + const issues = Array.isArray(parsed?.issues) ? parsed.issues : []; |
| 107 | + const currentIssueNumber = String(context.payload.issue.number); |
| 108 | +
|
| 109 | + console.log(`Current issue number: ${currentIssueNumber}`); |
| 110 | + console.log(issues); |
| 111 | +
|
| 112 | + const filteredIssues = issues.filter((value) => String(value) !== currentIssueNumber); |
| 113 | +
|
| 114 | + if (filteredIssues.length === 0) { |
| 115 | + core.info('Codex reported no potential duplicates.'); |
| 116 | + return; |
| 117 | + } |
| 118 | +
|
| 119 | + const lines = [ |
| 120 | + 'Potential duplicates detected. Please review them and close your issue if it is a duplicate.', |
| 121 | + '', |
| 122 | + ...filteredIssues.map((value) => `- #${String(value)}`), |
| 123 | + '', |
| 124 | + '*Powered by [Codex Action](https://github.com/openai/codex-action)*']; |
| 125 | +
|
| 126 | + await github.rest.issues.createComment({ |
| 127 | + owner: context.repo.owner, |
| 128 | + repo: context.repo.repo, |
| 129 | + issue_number: context.payload.issue.number, |
| 130 | + body: lines.join("\n"), |
| 131 | + }); |
| 132 | +
|
| 133 | + - name: Remove codex-deduplicate label |
| 134 | + if: ${{ always() && github.event.action == 'labeled' && github.event.label.name == 'codex-deduplicate' }} |
| 135 | + env: |
| 136 | + GH_TOKEN: ${{ github.token }} |
| 137 | + GH_REPO: ${{ github.repository }} |
| 138 | + run: | |
| 139 | + gh issue edit "${{ github.event.issue.number }}" --remove-label codex-deduplicate || true |
| 140 | + echo "Attempted to remove label: codex-deduplicate" |
0 commit comments