[Bug] Unable to update feed for niconico channels #21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: IssueBot | |
| on: | |
| issues: | |
| types: [opened] | |
| workflow_dispatch: | |
| inputs: | |
| issue_number: | |
| description: 'Issue number to process' | |
| required: true | |
| type: string | |
| permissions: | |
| issues: write | |
| contents: read | |
| jobs: | |
| process_issue: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Process issue | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| let issueNumber; | |
| let issueBody; | |
| let currentTitle; | |
| let issueCreatedAt; | |
| let isManualTrigger = false; | |
| // Check if this is a manual trigger or automatic | |
| if (context.eventName === 'workflow_dispatch') { | |
| isManualTrigger = true; | |
| issueNumber = parseInt(context.payload.inputs.issue_number); | |
| // Fetch issue details for manual trigger | |
| const issue = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber | |
| }); | |
| issueBody = issue.data.body; | |
| currentTitle = issue.data.title; | |
| issueCreatedAt = new Date(issue.data.created_at); | |
| } else { | |
| // Automatic trigger from issue creation | |
| issueBody = context.payload.issue.body; | |
| issueNumber = context.payload.issue.number; | |
| currentTitle = context.payload.issue.title; | |
| issueCreatedAt = new Date(context.payload.issue.created_at); | |
| } | |
| const templateKeyword = "**Checklist "; // Change this to a unique part of your template | |
| // Define the cutoff date (year, month - 1, day) | |
| const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index) | |
| // For manual trigger, only regenerate title | |
| if (isManualTrigger) { | |
| try { | |
| const titleResponse = await fetch('https://api.26163212.xyz:5001/generate-title', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| issue_number: issueNumber, | |
| repo: "InfinityLoop1308/PipePipe" | |
| }) | |
| }); | |
| if (!titleResponse.ok) { | |
| throw new Error(`Title generation failed: ${titleResponse.status}`); | |
| } | |
| const titleResult = await titleResponse.json(); | |
| console.log(titleResult); | |
| const generatedTitle = titleResult.generated_result; | |
| // Update title if different | |
| if (generatedTitle !== currentTitle) { | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| title: generatedTitle | |
| }); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: `🔄 Title updated from manual trigger:\nOld: "${currentTitle}"\nNew: "${generatedTitle}"` | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "✅ Manual title regeneration completed. No changes needed." | |
| }); | |
| } | |
| } catch (error) { | |
| console.error('Error processing manual trigger:', error); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "⚠️ There was an error processing the manual title regeneration." | |
| }); | |
| } | |
| return; // Exit early for manual trigger | |
| } | |
| // Check if the issue was created after the cutoff date | |
| if (issueCreatedAt > cutoffDate) { | |
| // Step 1: Check if the issue body contains the template keyword | |
| if (!issueBody.includes(templateKeyword)) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "This issue does not follow the template and will be closed. Please update the issue following the template and reopen it." | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| state: "closed", | |
| state_reason: "not_planned" | |
| }); | |
| return; // Exit early if template not followed | |
| } | |
| // Step 2: Generate title if template is followed | |
| try { | |
| const titleResponse = await fetch('https://api.26163212.xyz:5001/generate-title', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| issue_number: issueNumber, | |
| repo: "InfinityLoop1308/PipePipe" | |
| }) | |
| }); | |
| if (!titleResponse.ok) { | |
| throw new Error(`Title generation failed: ${titleResponse.status}`); | |
| } | |
| const titleResult = await titleResponse.json(); | |
| console.log(titleResult) | |
| // Check for spam and close if detected | |
| if (titleResult.is_spam) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "Closing as suspected spam. If you believe this is a mistake, please revise your content and open a new issue." | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| state: "closed", | |
| state_reason: "spam" | |
| }); | |
| return; // Stop processing here | |
| } | |
| const generatedTitle = titleResult.generated_result; | |
| // Update title if different | |
| if (generatedTitle !== currentTitle) { | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| title: generatedTitle | |
| }); | |
| } | |
| // Step 3: Analyze issue for related issues | |
| const analyzeResponse = await fetch('https://api.26163212.xyz:5001/analyze-issue', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| issue_link: `https://github.com/InfinityLoop1308/PipePipe/issues/${issueNumber}`, | |
| type: "all" | |
| }) | |
| }); | |
| if (!analyzeResponse.ok) { | |
| throw new Error(`Issue analysis failed: ${analyzeResponse.status}`); | |
| } | |
| const analyzeResult = await analyzeResponse.json(); | |
| console.log(analyzeResult) | |
| const relatedIssues = analyzeResult.related_issues; | |
| // Handle related issues response | |
| if (relatedIssues.length === 0) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "✅ No similar issues found. This appears to be a unique issue." | |
| }); | |
| } else { | |
| const issueList = relatedIssues.map(num => `- #${num}`).join('\n'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: `🔍 Found related issues:\n${issueList}\n\nPlease check these issues first before proceeding.` | |
| }); | |
| } | |
| } catch (error) { | |
| console.error('Error processing issue:', error); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: "⚠️ There was an error processing this issue automatically. Please proceed manually." | |
| }); | |
| } | |
| } |