From 0ecf02bd5210f5ea5a3802dab185d20348294125 Mon Sep 17 00:00:00 2001 From: Itsmechinmoy <167056923+itsmechinmoy@users.noreply.github.com> Date: Mon, 30 Dec 2024 18:22:12 +0530 Subject: [PATCH] Create extension-issue-handling.yml --- .../workflows/extension-issue-handling.yml | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 .github/workflows/extension-issue-handling.yml diff --git a/.github/workflows/extension-issue-handling.yml b/.github/workflows/extension-issue-handling.yml new file mode 100644 index 0000000..833eefb --- /dev/null +++ b/.github/workflows/extension-issue-handling.yml @@ -0,0 +1,197 @@ +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() + .replace(/\d+/g, ''); + console.log(`šŸ” Normalizing: "${original}" -> "${normalized}"`); + return normalized; + } + + function findExtensionMatch(content, extensionNames) { + console.log('\nšŸ“– Checking content:', content); + const normalizedContent = normalizeExtensionName(content); + for (const extension of extensionNames) { + console.log(`\nāš” Checking against extension: ${extension}`); + const normalizedExtension = normalizeExtensionName(extension); + if (normalizedContent.includes(normalizedExtension)) { + console.log(`āœ… Direct match found! "${extension}"`); + return extension; + } + const extensionParts = normalizedExtension.split(''); + let possibleSplits = ''; + for (let i = 0; i < extensionParts.length - 1; i++) { + possibleSplits += extensionParts[i] + ' '; + } + possibleSplits += extensionParts[extensionParts.length - 1]; + if (normalizedContent.includes(possibleSplits)) { + console.log(`āœ… Split match found! "${extension}" (as "${possibleSplits}")`); + return extension; + } + } + console.log('āŒ No extension match found'); + return null; + } + + 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); + + const regexPatterns = [ + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*not working.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*doesn't work.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*does not work.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*cant work.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*can't work.*", + ".*(no|can't find|cannot find|missing).*extension(s)?.*", + ".*(no|can't find|cannot find|missing).*repo(s|sitories)?.*", + ".*(no|can't find|cannot find|missing).*source(s)?.*", + ".*(no|can't find|cannot find|missing).*stream(s)?.*", + ".*(no|can't find|cannot find|missing).*server.*", + ".*(server|stream).*not available.*", + ".*(server|stream).*unavailable.*", + ".*(server|stream).*down.*", + ".*{.*}.*(extension|repo|repositories|source|sources).*not working.*", + ".*{.*}.*(extension|repo|repositories|source|sources).*issue.*", + ".*{.*}.*(extension|repo|repositories|source|sources).*problem.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*not available.*", + ".*(extension|extensions|repo|repositories|source|sources|stream|server).*missing.*", + ".*nothing came up.*source.*look elsewhere.*", + ".*no results.*source.*look somewhere else.*", + ".*no content.*source.*" + ]; + + let isExtensionIssue = false; + let detectedExtension = null; + + console.log('\nšŸ” Checking for extension matches...'); + detectedExtension = findExtensionMatch(issueTitle, extensionNames) || + findExtensionMatch(issueBody, extensionNames); + + if (detectedExtension) { + isExtensionIssue = true; + console.log('āœ… Extension detected:', detectedExtension); + } else { + console.log('\nšŸ” No specific extension found, checking regex patterns...'); + for (const pattern of regexPatterns) { + const regex = new RegExp(pattern, 'i'); + if (regex.test(issueTitle.toLowerCase())) { + console.log(`āœ… Regex pattern matched in title: "${pattern}"`); + isExtensionIssue = true; + break; + } + if (regex.test(issueBody.toLowerCase())) { + console.log(`āœ… Regex pattern matched in body: "${pattern}"`); + isExtensionIssue = true; + break; + } + } + } + + console.log('\nšŸ“Š Final Results:'); + console.log('Is Extension Issue:', isExtensionIssue); + console.log('Detected Extension:', detectedExtension || 'Unknown Extension'); + 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');