forked from AOSSIE-Org/PictoPy
-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (157 loc) · 5.7 KB
/
Copy pathduplicate_issue_detector.yaml
File metadata and controls
189 lines (157 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Smart Duplicate Issue Detector (Semantic)
on:
issues:
types: [opened]
permissions:
issues: write
jobs:
detect-duplicates:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
pip install --no-cache-dir sentence-transformers scikit-learn
- name: Fetch upstream issues (AOSSIE-Org/PictoPy)
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const issue = context.payload.issue;
const upstreamIssues = await github.paginate(
github.rest.issues.listForRepo,
{
owner: "AOSSIE-Org",
repo: "PictoPy",
state: "all",
per_page: 100
}
);
const data = {
current: {
number: issue.number,
title: issue.title,
body: issue.body || ""
},
others: upstreamIssues
.filter(i => !i.pull_request && i.number !== issue.number)
.map(i => ({
number: i.number,
title: i.title,
body: i.body || "",
url: i.html_url,
state: i.state
}))
};
fs.writeFileSync("issues.json", JSON.stringify(data));
- name: Run semantic similarity analysis
run: |
python << 'EOF'
import json
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
THRESHOLD = 0.82
MAX_RESULTS = 3
print(f"Threshold = {THRESHOLD}")
with open("issues.json") as f:
data = json.load(f)
model = SentenceTransformer("all-MiniLM-L6-v2")
def text(issue):
return f"{issue['title']} {issue['body']}".strip()
current_text = text(data["current"])
others = data["others"]
print(f"Current issue: #{data['current']['number']}")
print(f"Candidate issues: {len(others)}")
if not others:
with open("matches.json", "w") as f:
json.dump([], f)
exit()
embeddings = model.encode(
[current_text] + [text(i) for i in others],
normalize_embeddings=True
)
current_vec = embeddings[0]
other_vecs = embeddings[1:]
sims = cosine_similarity([current_vec], other_vecs)[0]
matches = []
for issue, score in zip(others, sims):
print(
f"Issue #{issue['number']} | "
f"Score={score:.4f} | "
f"Title={issue['title']}"
)
if score >= THRESHOLD:
matches.append({
"number": issue["number"],
"title": issue["title"],
"url": issue["url"],
"state": issue["state"],
"score": round(float(score) * 100, 1)
})
matches = sorted(matches, key=lambda x: x["score"], reverse=True)[:MAX_RESULTS]
with open("matches.json", "w") as f:
json.dump(matches, f)
EOF
- name: Comment and soft-label in fork (non-blocking)
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const matches = JSON.parse(fs.readFileSync("matches.json", "utf8"));
if (matches.length === 0) {
core.notice("No semantic duplicates found.");
return;
}
const list = matches.map(
(m, i) =>
`${i + 1}. **${m.title}** (#${m.number}, ${m.state})\n` +
` ${m.url}\n` +
` Similarity: ${m.score}%`
).join("\n\n");
const safe = async (fn) => {
try { await fn(); }
catch (e) { core.notice(`Skipped write action: ${e.message}`); }
};
await safe(() =>
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
body:
`⚠️ **Potential Duplicate Issue (Semantic Match)**\n\n` +
`This issue appears semantically similar to the following issues in AOSSIE-Org/PictoPy:\n\n` +
`${list}\n\n` +
`Please review before proceeding.`
})
);
const labelName = "possible-duplicate";
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName
});
} catch (e) {
if (e.status === 404) {
await safe(() =>
github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName,
color: "FBCA04",
description: "Potential semantic duplicate (upstream comparison)"
})
);
}
}
await safe(() =>
github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
labels: [labelName]
})
);