Skip to content

Commit 9a60ab6

Browse files
committed
ci(deduplicator): address CodeRabbit review findings
- Drop unused contents: read permission (no checkout in this workflow) - Add per-issue concurrency group to serialize opened/labeled runs for the same issue and prevent duplicate bot comments from racing - Fetch existing bot comment before the no-matches early return so a stale duplicate comment from a prior scan is cleaned up on rescan - Replace blanket || true on label removal with targeted error matching that only swallows 404 label-not-found and propagates real failures
1 parent 0782a6d commit 9a60ab6

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎.github/workflows/issue-deduplicator.yml‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ on:
77
- labeled
88

99
permissions:
10-
contents: read
1110
issues: write
1211
models: read
1312

1413
jobs:
1514
find-similar:
1615
name: Find similar open issues
16+
concurrency:
17+
group: issue-deduplicator-${{ github.event.issue.number }}
18+
cancel-in-progress: false
1719
if: |
1820
github.event.action == 'opened' ||
1921
(github.event.action == 'labeled' && github.event.label.name == 'codex-deduplicate')
@@ -89,6 +91,14 @@ PROMPT
8991
const issue = context.payload.issue;
9092
const BOT_MARKER = "<!-- opencodex-dedup-bot -->";
9193
94+
// Always fetch existing bot comment first — needed for both match and no-match paths
95+
const comments = await github.paginate(github.rest.issues.listComments, {
96+
owner, repo, issue_number: issue.number, per_page: 100,
97+
});
98+
const existing = comments.find(
99+
c => c.user?.type === 'Bot' && c.body?.includes(BOT_MARKER),
100+
);
101+
92102
const raw = process.env.AI_RESPONSE ?? '';
93103
let parsed;
94104
try {
@@ -108,18 +118,18 @@ PROMPT
108118
)].slice(0, 5);
109119
110120
if (matches.length === 0) {
111-
core.info('No similar issues found.');
121+
// Clean up a stale duplicate comment from a prior run if present
122+
if (existing) {
123+
await github.rest.issues.deleteComment({
124+
owner, repo, comment_id: existing.id,
125+
});
126+
core.info(`Removed stale dedup comment on #${issue.number} — no matches on rescan.`);
127+
} else {
128+
core.info('No similar issues found.');
129+
}
112130
return;
113131
}
114132
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-
123133
const list = matches.map(n => `- #${n}`).join('\n');
124134
const body = [
125135
BOT_MARKER,
@@ -147,4 +157,9 @@ PROMPT
147157
env:
148158
GH_TOKEN: ${{ github.token }}
149159
run: |
150-
gh issue edit "${{ github.event.issue.number }}" --remove-label "codex-deduplicate" || true
160+
# Only swallow 404 "label not found"; propagate auth/API/runner failures
161+
output=$(gh issue edit "${{ github.event.issue.number }}" --remove-label "codex-deduplicate" 2>&1) && exit 0 || {
162+
echo "$output" | grep -qi "could not remove label\|label.*not found\|Label.*not exist" && exit 0
163+
echo "$output" >&2
164+
exit 1
165+
}

0 commit comments

Comments
 (0)