-
-
Notifications
You must be signed in to change notification settings - Fork 24
179 lines (155 loc) · 7.53 KB
/
extension-issue-handling.yml
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
name: Extension Issue Handling
on:
issues:
types: [opened]
jobs:
check-extension-issue:
runs-on: ubuntu-latest
steps:
- name: Fetch Extension Data
id: fetch-extensions
uses: actions/github-script@v6
with:
script: |
const repos = [
"https://kodjodevf.github.io/mangayomi-extensions/index.json",
"https://kodjodevf.github.io/mangayomi-extensions/anime_index.json"
];
const extensionNames = new Set();
for (const repo of repos) {
try {
const response = await fetch(repo);
const data = await response.json();
data.forEach(extension => {
if (extension.name) {
extensionNames.add(extension.name.toLowerCase());
}
});
console.log(`✅ Successfully fetched extensions from ${repo}`);
} catch (error) {
console.error(`❌ Error fetching ${repo}:`, error);
}
}
console.log('📝 Found extensions:', Array.from(extensionNames).join(', '));
core.setOutput('extension_names', Array.from(extensionNames).join(','));
- name: Check Issue Content
id: check-issue
uses: actions/github-script@v6
with:
script: |
function normalizeExtensionName(name) {
const original = name;
const normalized = name
.toLowerCase()
.replace(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>/?]/g, ' ')
.replace(/\s+/g, ' ')
.trim();
console.log(`🔍 Normalizing: "${original}" -> "${normalized}"`);
return normalized;
}
function findExtensionMatch(content, extensionNames) {
console.log('\n📖 Checking content:', content);
for (const extension of extensionNames) {
const normalizedExtension = normalizeExtensionName(extension);
console.log(`\n⚡ Checking against extension: ${extension}`);
// Check if extension name appears as a complete word or phrase
if (content.toLowerCase().includes(` ${normalizedExtension} `) ||
content.toLowerCase().startsWith(`${normalizedExtension} `) ||
content.toLowerCase().endsWith(` ${normalizedExtension}`)) {
console.log(`✅ Complete word/phrase match found! "${extension}"`);
return extension;
}
console.log(`❌ No match found for "${extension}"`);
}
console.log('❌ No extension match found in content');
return null;
}
function isExtensionRelatedIssue(title, body) {
const commonProblemWords = [
'doesnt', 'doesn\'t', 'not', 'error', 'broken', 'issue', 'problem',
'crash', 'fail', 'failed', 'failing', 'down', 'work', 'working',
'loading', 'load', 'dead', 'fix', 'broken', 'bug', 'bugs', 'problems',
'issues', 'errors', 'cant', 'can\'t', 'cannot', 'wrong', 'help',
'stuck', 'freezing', 'freeze', 'frozen', 'stopped', 'stopping',
'blank', 'empty', 'missing', 'unavailable', 'slow'
];
const content = (title + ' ' + body).toLowerCase();
const foundWords = commonProblemWords.filter(word => content.includes(word));
if (foundWords.length > 0) {
console.log('✅ Found problem-indicating words:', foundWords.join(', '));
return true;
}
console.log('❌ No problem-indicating words found');
return false;
}
const extensionNames = process.env.EXTENSION_NAMES.split(',');
const issueTitle = context.payload.issue.title;
const issueBody = context.payload.issue.body || '';
console.log('\n🎯 Checking Issue:');
console.log('Title:', issueTitle);
console.log('Body:', issueBody);
let isExtensionIssue = false;
let detectedExtension = null;
console.log('\n🔍 Step 1: Checking for extension matches...');
detectedExtension = findExtensionMatch(issueTitle, extensionNames) ||
findExtensionMatch(issueBody, extensionNames);
console.log('\n🔍 Step 2: Checking if issue is extension-related...');
if (detectedExtension) {
isExtensionIssue = isExtensionRelatedIssue(issueTitle, issueBody);
console.log(`Extension found: ${detectedExtension}`);
console.log(`Is problem-related: ${isExtensionIssue}`);
} else {
console.log('❌ No extension found, skipping problem check');
}
console.log('\n📊 Final Results:');
console.log('Is Extension Issue:', isExtensionIssue);
console.log('Detected Extension:', detectedExtension || 'None');
core.setOutput('is_extension_issue', isExtensionIssue.toString());
core.setOutput('detected_extension', detectedExtension || 'Unknown Extension');
env:
EXTENSION_NAMES: ${{ steps.fetch-extensions.outputs.extension_names }}
- name: Comment and Close Extension Issue
if: steps.check-issue.outputs.is_extension_issue == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issueNumber = context.issue.number;
const reportedExtension = "${{ steps.check-issue.outputs.detected_extension || 'Unknown Extension' }}";
console.log('🔒 Closing issue:', issueNumber);
console.log('Extension reported:', reportedExtension);
const currentLabels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
for (const label of currentLabels.data) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: label.name
});
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['wontfix']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `# Not Our Business!
AnymeX doesn't maintain extensions.
If the extension doesn't work, we cannot help you.
Contact the owner of the respective repository for extension-related problems.`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed'
});
console.log('✅ Issue processed and closed successfully');