Skip to content

Commit 1f76a5a

Browse files
authored
Create issue-theme-duplicate-check.yml
1 parent c7479e3 commit 1f76a5a

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Theme Issue Duplicate Checker
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
7+
jobs:
8+
check-duplicate:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out the repository
12+
uses: actions/checkout@v2
13+
14+
- name: Check for duplicate theme issues
15+
uses: actions/github-script@v6
16+
with:
17+
script: |
18+
const { owner, repo } = context.repo;
19+
const issue = context.payload.issue;
20+
21+
// Check if the issue has the [THEME] label
22+
const hasThemeLabel = issue.labels.some(label => label.name === '[THEME]');
23+
if (!hasThemeLabel) {
24+
console.log('Issue does not have [THEME] label. Exiting...');
25+
return;
26+
}
27+
28+
// Fetch all issues with the [THEME] label
29+
const issues = await github.issues.listForRepo({
30+
owner,
31+
repo,
32+
state: 'all',
33+
labels: '[THEME]'
34+
});
35+
36+
// Check for duplicate titles
37+
const duplicateIssue = issues.data.find(otherIssue => {
38+
return otherIssue.title === issue.title && otherIssue.number !== issue.number;
39+
});
40+
41+
if (duplicateIssue) {
42+
console.log(`Found duplicate issue: #${duplicateIssue.number}`);
43+
44+
// Add a comment to the issue
45+
await github.issues.createComment({
46+
owner,
47+
repo,
48+
issue_number: issue.number,
49+
body: `This issue is marked as a duplicate of #${duplicateIssue.number}. Please refer to the previous issue for more details.`
50+
});
51+
52+
// Add the duplicate label to the issue
53+
await github.issues.addLabels({
54+
owner,
55+
repo,
56+
issue_number: issue.number,
57+
labels: ['duplicate']
58+
});
59+
60+
// Close the issue as a duplicate using GitHub's native feature
61+
await github.issues.update({
62+
owner,
63+
repo,
64+
issue_number: issue.number,
65+
state: 'closed',
66+
duplicate_of: duplicateIssue.number
67+
});
68+
} else {
69+
console.log('No duplicate issue found.');
70+
}

0 commit comments

Comments
 (0)