Elffuss BraidHub

kikocis/continue public

chore: Add action to comment on duplicate issues
Changeset1d679a95330a20d62466d4fc5cb0bb10b14c48c1060ba80361c2b1db8bbeed32
AuthorBrian Douglas <bdougie@users.noreply.github.com> · 2025-08-08 07:48 -07:00
CommitterGitHub <noreply@github.com> · 2025-08-08 07:48 -07:00
Parents76e6219ef348

Browse the files at this changeset

1 file changed

added .github/workflows/similar-issues.yml +289 −0
@@ -0,0 +1,289 @@
1+name: Similar Issue Search & Discussion Suggestion
2+on:
3+ issues:
4+ types: [opened]
5+ pull_request:
6+ types: [opened]
7+
8+jobs:
9+ analyze:
10+ runs-on: ubuntu-latest
11+ permissions:
12+ issues: write
13+ pull-requests: write
14+
15+ steps:
16+ - name: Checkout deja-view
17+ uses: actions/checkout@v4
18+ with:
19+ repository: 'bdougie/deja-view'
20+ path: deja-view
21+
22+ - name: Setup Python
23+ uses: actions/setup-python@v5
24+ with:
25+ python-version: '3.11'
26+
27+ - name: Install dependencies
28+ run: |
29+ cd deja-view
30+ pip install -r requirements.txt
31+
32+ - name: Search for similar issues
33+ id: search
34+ env:
35+ CHROMA_CLOUD_API_KEY: ${{ secrets.CHROMA_CLOUD_API_KEY }}
36+ CHROMA_CLOUD_API_URL: ${{ secrets.CHROMA_CLOUD_API_URL }}
37+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+ run: |
39+ cd deja-view
40+
41+ # Determine if this is an issue or PR
42+ if [ "${{ github.event_name }}" = "pull_request" ]; then
43+ TITLE="${{ github.event.pull_request.title }}"
44+ THRESHOLD="0.85"
45+ TOP_K="5"
46+ else
47+ TITLE="${{ github.event.issue.title }}"
48+ THRESHOLD="0.7"
49+ TOP_K="3"
50+ fi
51+
52+ # Search for similar issues
53+ SIMILAR_ISSUES=$(python cli.py search "$TITLE" \
54+ --repo "${{ github.repository }}" \
55+ --top-k $TOP_K \
56+ --threshold $THRESHOLD \
57+ --format json)
58+
59+ # Save to output
60+ echo "similar_issues<<EOF" >> $GITHUB_OUTPUT
61+ echo "$SIMILAR_ISSUES" >> $GITHUB_OUTPUT
62+ echo "EOF" >> $GITHUB_OUTPUT
63+
64+ # Check if any similar issues found
65+ if [ "$(echo "$SIMILAR_ISSUES" | jq '. | length')" -gt 0 ]; then
66+ echo "has_similar=true" >> $GITHUB_OUTPUT
67+ else
68+ echo "has_similar=false" >> $GITHUB_OUTPUT
69+ fi
70+
71+ - name: Check if issue should be a discussion
72+ id: discussion_check
73+ if: github.event_name == 'issues'
74+ env:
75+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+ run: |
77+ cd deja-view
78+
79+ # Create a Python script to analyze the issue
80+ cat << 'PYTHON_SCRIPT' > check_discussion.py
81+ import os
82+ import json
83+ import re
84+ from github_similarity_service import SimilarityService
85+
86+ # Get issue details from environment
87+ issue_title = os.environ.get('ISSUE_TITLE', '')
88+ issue_body = os.environ.get('ISSUE_BODY', '')
89+ issue_labels = json.loads(os.environ.get('ISSUE_LABELS', '[]'))
90+
91+ # Mock Issue object for analysis
92+ class MockIssue:
93+ def __init__(self):
94+ self.title = issue_title
95+ self.body = issue_body
96+ self.labels = issue_labels
97+ self.state = 'open'
98+ self.number = int(os.environ.get('ISSUE_NUMBER', 0))
99+ self.created_at = ''
100+ self.updated_at = ''
101+ self.url = ''
102+
103+ service = SimilarityService()
104+ issue = MockIssue()
105+
106+ score, reasons = service._calculate_discussion_score(issue)
107+
108+ result = {
109+ 'score': score,
110+ 'reasons': reasons,
111+ 'should_be_discussion': score >= 0.5,
112+ 'confidence': 'high' if score >= 0.7 else 'medium' if score >= 0.5 else 'low'
113+ }
114+
115+ print(json.dumps(result))
116+ PYTHON_SCRIPT
117+
118+ # Run the analysis
119+ DISCUSSION_ANALYSIS=$(ISSUE_TITLE="${{ github.event.issue.title }}" \
120+ ISSUE_BODY='${{ github.event.issue.body }}' \
121+ ISSUE_LABELS='${{ toJson(github.event.issue.labels.*.name) }}' \
122+ ISSUE_NUMBER="${{ github.event.issue.number }}" \
123+ python check_discussion.py)
124+
125+ echo "analysis<<EOF" >> $GITHUB_OUTPUT
126+ echo "$DISCUSSION_ANALYSIS" >> $GITHUB_OUTPUT
127+ echo "EOF" >> $GITHUB_OUTPUT
128+
129+ # Extract whether it should be a discussion
130+ SHOULD_BE_DISCUSSION=$(echo "$DISCUSSION_ANALYSIS" | jq -r '.should_be_discussion')
131+ echo "should_be_discussion=$SHOULD_BE_DISCUSSION" >> $GITHUB_OUTPUT
132+
133+ # Extract confidence level
134+ CONFIDENCE=$(echo "$DISCUSSION_ANALYSIS" | jq -r '.confidence')
135+ echo "confidence=$CONFIDENCE" >> $GITHUB_OUTPUT
136+
137+ - name: Comment with analysis
138+ uses: actions/github-script@v7
139+ with:
140+ script: |
141+ let comment = '';
142+ const hasSimilar = '${{ steps.search.outputs.has_similar }}' === 'true';
143+ const isPR = '${{ github.event_name }}' === 'pull_request';
144+ const shouldBeDiscussion = !isPR && '${{ steps.discussion_check.outputs.should_be_discussion }}' === 'true';
145+
146+ // Add similar issues section if found
147+ if (hasSimilar) {
148+ const similarIssues = JSON.parse(`${{ steps.search.outputs.similar_issues }}`);
149+
150+ if (isPR) {
151+ // Filter only open issues for PRs
152+ const openIssues = similarIssues.filter(issue => issue.state === 'open');
153+
154+ if (openIssues.length > 0) {
155+ // Simple table format for PRs
156+ comment += '## 📋 Related Open Issues\n\n';
157+ comment += 'These open issues appear to be related to this PR (≥85% similarity):\n\n';
158+ comment += '| # | Title | Similarity |\n';
159+ comment += '|---|-------|------------|\n';
160+
161+ openIssues.forEach(issue => {
162+ const similarity = (issue.similarity * 100).toFixed(0);
163+ const title = issue.title.length > 50 ? issue.title.substring(0, 47) + '...' : issue.title;
164+ comment += `| [#${issue.number}](${issue.url}) | ${title} | ${similarity}% |\n`;
165+ });
166+
167+ comment += '\n';
168+ comment += '_Consider closing related issues if this PR addresses them._\n';
169+ } else {
170+ // Don't add any comment if no open issues found
171+ return;
172+ }
173+ } else {
174+ // Original format for issues
175+ comment += '## 🔍 Similar Issues Found\n\n';
176+ comment += 'I found some existing issues that might be related:\n\n';
177+
178+ similarIssues.forEach((issue, index) => {
179+ const similarity = (issue.similarity * 100).toFixed(1);
180+ const state = issue.state === 'open' ? '🟢' : '🔴';
181+
182+ comment += `${index + 1}. ${state} [#${issue.number}: ${issue.title}](${issue.url}) (${similarity}% similar)\n`;
183+
184+ if (issue.summary) {
185+ comment += ` > ${issue.summary.substring(0, 150)}${issue.summary.length > 150 ? '...' : ''}\n`;
186+ }
187+ comment += '\n';
188+ });
189+
190+ comment += '\n';
191+ }
192+ }
193+
194+ // Add discussion suggestion if applicable
195+ if (shouldBeDiscussion) {
196+ const analysis = JSON.parse(`${{ steps.discussion_check.outputs.analysis }}`);
197+ const confidence = '${{ steps.discussion_check.outputs.confidence }}';
198+
199+ if (hasSimilar) {
200+ comment += '---\n\n';
201+ }
202+
203+ comment += '## 💬 Discussion Suggestion\n\n';
204+
205+ const confidenceEmoji = {
206+ 'high': '🟢',
207+ 'medium': '🟡',
208+ 'low': '🔴'
209+ };
210+
211+ comment += `This issue might be better suited as a **GitHub Discussion** ${confidenceEmoji[confidence] || ''}\n\n`;
212+ comment += `**Confidence**: ${confidence.charAt(0).toUpperCase() + confidence.slice(1)} (${(analysis.score * 100).toFixed(0)}%)\n\n`;
213+
214+ if (analysis.reasons && analysis.reasons.length > 0) {
215+ comment += '**Reasons**:\n';
216+ analysis.reasons.forEach(reason => {
217+ comment += `- ${reason}\n`;
218+ });
219+ comment += '\n';
220+ }
221+
222+ comment += 'GitHub Discussions are great for:\n';
223+ comment += '- Questions and help requests\n';
224+ comment += '- Feature requests and ideas\n';
225+ comment += '- General feedback and brainstorming\n';
226+ comment += '- Community conversations\n\n';
227+
228+ comment += '_Consider converting this to a discussion if it\'s not a bug report or actionable task._\n';
229+ }
230+
231+ // Only comment if we have something to say
232+ if (comment) {
233+ comment += '\n---\n';
234+ comment += '_This analysis was automatically generated by [deja-view](https://github.com/bdougie/deja-view)._';
235+
236+ if ('${{ github.event_name }}' === 'pull_request') {
237+ await github.rest.issues.createComment({
238+ owner: context.repo.owner,
239+ repo: context.repo.repo,
240+ issue_number: context.payload.pull_request.number,
241+ body: comment
242+ });
243+ } else {
244+ await github.rest.issues.createComment({
245+ owner: context.repo.owner,
246+ repo: context.repo.repo,
247+ issue_number: context.issue.number,
248+ body: comment
249+ });
250+ }
251+ }
252+
253+ - name: Add labels
254+ if: github.event_name == 'issues'
255+ uses: actions/github-script@v7
256+ with:
257+ script: |
258+ const labels = [];
259+
260+ // Check for duplicate
261+ if ('${{ steps.search.outputs.has_similar }}' === 'true') {
262+ const similarIssues = JSON.parse(`${{ steps.search.outputs.similar_issues }}`);
263+ const hasDuplicate = similarIssues.some(issue => issue.similarity > 0.9);
264+
265+ if (hasDuplicate) {
266+ labels.push('potential-duplicate');
267+ }
268+ }
269+
270+ // Check for discussion suggestion
271+ if ('${{ steps.discussion_check.outputs.should_be_discussion }}' === 'true') {
272+ const confidence = '${{ steps.discussion_check.outputs.confidence }}';
273+
274+ if (confidence === 'high') {
275+ labels.push('should-be-discussion');
276+ } else if (confidence === 'medium') {
277+ labels.push('discussion');
278+ }
279+ }
280+
281+ // Add labels if any
282+ if (labels.length > 0) {
283+ await github.rest.issues.addLabels({
284+ owner: context.repo.owner,
285+ repo: context.repo.repo,
286+ issue_number: context.issue.number,
287+ labels: labels
288+ });
289+ }