Skip to content

Commit 0782a6d

Browse files
committed
ci: add issue deduplicator workflow
Adds a new GitHub Actions workflow that fires on every new issue (and on manual re-trigger via the codex-deduplicate label) and posts a bot comment listing up to five similar open issues. Uses GitHub's built-in search API only -- no secrets, no external services, no per-token cost. Keyword extraction weights the title 2x over the body to keep queries focused. The bot comment is idempotent (upserted via BOT_MARKER), so re-labelling updates rather than duplicates the comment. Inspired by openai/codex issue-deduplicator.yml but replaces the LLM/codex-action layer with native github.rest.search calls.
1 parent 2e9442a commit 0782a6d

1 file changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Issue Deduplicator
2+
3+
on:
4+
issues:
5+
types:
6+
- opened
7+
- labeled
8+
9+
permissions:
10+
contents: read
11+
issues: write
12+
models: read
13+
14+
jobs:
15+
find-similar:
16+
name: Find similar open issues
17+
if: |
18+
github.event.action == 'opened' ||
19+
(github.event.action == 'labeled' && github.event.label.name == 'codex-deduplicate')
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Fetch issues and build prompt
24+
id: build-prompt
25+
env:
26+
GH_TOKEN: ${{ github.token }}
27+
REPO: ${{ github.repository }}
28+
ISSUE_NUMBER: ${{ github.event.issue.number }}
29+
run: |
30+
set -eo pipefail
31+
32+
gh issue list --repo "$REPO" \
33+
--json number,title,body \
34+
--limit 500 \
35+
--state open \
36+
--search "sort:created-desc" \
37+
| jq --arg cur "$ISSUE_NUMBER" '[
38+
.[] | select(.number != ($cur | tonumber)) |
39+
{ number, title, body: ((.body // "")[0:800]) }
40+
]' \
41+
> existing-issues.json
42+
43+
gh issue view "$ISSUE_NUMBER" --repo "$REPO" \
44+
--json number,title,body \
45+
| jq '{ number, title, body: ((.body // "")[0:2000]) }' \
46+
> current-issue.json
47+
48+
echo "open_count=$(jq 'length' existing-issues.json)"
49+
50+
# Write the full prompt to a file so actions/ai-inference can read it
51+
cat > dedup-prompt.txt <<'PROMPT'
52+
New issue (JSON):
53+
PROMPT
54+
cat current-issue.json >> dedup-prompt.txt
55+
cat >> dedup-prompt.txt <<'PROMPT'
56+
57+
Existing open issues (JSON array):
58+
PROMPT
59+
cat existing-issues.json >> dedup-prompt.txt
60+
cat >> dedup-prompt.txt <<'PROMPT'
61+
62+
Return a JSON object with this exact shape and nothing else:
63+
{"issues": ["<number>", ...], "reason": "<one sentence>"}
64+
65+
List only issue numbers (as strings) that are clear duplicates of the new
66+
issue. At most five. Empty array if none are convincing matches.
67+
PROMPT
68+
69+
- name: Run semantic duplicate detection
70+
id: ai
71+
uses: actions/ai-inference@v1
72+
with:
73+
model: openai/gpt-4o-mini
74+
max-completion-tokens: 200
75+
system-prompt: >
76+
You are a GitHub issue triage assistant. Identify duplicate issues
77+
based on semantic similarity — same underlying problem, error, or
78+
feature request — not just shared keywords. Respond only with the
79+
requested JSON. No markdown, no explanation outside the JSON.
80+
prompt-file: dedup-prompt.txt
81+
82+
- name: Post duplicate comment
83+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
84+
env:
85+
AI_RESPONSE: ${{ steps.ai.outputs.response }}
86+
with:
87+
script: |
88+
const { owner, repo } = context.repo;
89+
const issue = context.payload.issue;
90+
const BOT_MARKER = "<!-- opencodex-dedup-bot -->";
91+
92+
const raw = process.env.AI_RESPONSE ?? '';
93+
let parsed;
94+
try {
95+
// Strip potential markdown code fences
96+
const cleaned = raw.replace(/^```(?:json)?\s*/m, '').replace(/\s*```\s*$/m, '').trim();
97+
parsed = JSON.parse(cleaned);
98+
} catch (err) {
99+
core.warning(`AI response was not valid JSON: ${raw}`);
100+
return;
101+
}
102+
103+
const currentNum = String(issue.number);
104+
const matches = [...new Set(
105+
(Array.isArray(parsed?.issues) ? parsed.issues : [])
106+
.map(String)
107+
.filter(n => n !== currentNum)
108+
)].slice(0, 5);
109+
110+
if (matches.length === 0) {
111+
core.info('No similar issues found.');
112+
return;
113+
}
114+
115+
// Upsert: update existing bot comment if present
116+
const comments = await github.paginate(github.rest.issues.listComments, {
117+
owner, repo, issue_number: issue.number, per_page: 100,
118+
});
119+
const existing = comments.find(
120+
c => c.user?.type === 'Bot' && c.body?.includes(BOT_MARKER),
121+
);
122+
123+
const list = matches.map(n => `- #${n}`).join('\n');
124+
const body = [
125+
BOT_MARKER,
126+
'Potential duplicates found — please check whether your issue is already covered:',
127+
'',
128+
list,
129+
'',
130+
'_Detected automatically via GitHub Models. Matches may not be exact._',
131+
].join('\n');
132+
133+
if (existing) {
134+
await github.rest.issues.updateComment({
135+
owner, repo, comment_id: existing.id, body,
136+
});
137+
core.info(`Updated dedup comment on #${issue.number}.`);
138+
} else {
139+
await github.rest.issues.createComment({
140+
owner, repo, issue_number: issue.number, body,
141+
});
142+
core.info(`Posted dedup comment on #${issue.number} with ${matches.length} match(es).`);
143+
}
144+
145+
- name: Remove codex-deduplicate label
146+
if: github.event.action == 'labeled' && github.event.label.name == 'codex-deduplicate'
147+
env:
148+
GH_TOKEN: ${{ github.token }}
149+
run: |
150+
gh issue edit "${{ github.event.issue.number }}" --remove-label "codex-deduplicate" || true

0 commit comments

Comments
 (0)