|
| 1 | +name: "Detect AI-Generated Issues" |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened, edited] |
| 6 | + |
| 7 | +jobs: |
| 8 | + detect-ai-content: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + issues: write |
| 12 | + contents: read |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Analyze issue for AI-generated content |
| 18 | + id: analyze |
| 19 | + uses: actions/github-script@v7 |
| 20 | + with: |
| 21 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + script: | |
| 23 | + const issue = context.payload.issue; |
| 24 | + const issueBody = issue.body || ''; |
| 25 | + const issueTitle = issue.title || ''; |
| 26 | + |
| 27 | + // AI detection patterns |
| 28 | + const aiPatterns = { |
| 29 | + // Overly structured markdown with extensive tables |
| 30 | + excessiveTables: (issueBody.match(/\|.*\|/g) || []).length > 5, |
| 31 | + |
| 32 | + // Multiple consecutive headers with consistent formatting |
| 33 | + excessiveHeaders: (issueBody.match(/^#{1,6}\s+/gm) || []).length > 8, |
| 34 | + |
| 35 | + // Overly formal language patterns common in AI |
| 36 | + formalPhrases: [ |
| 37 | + 'Root Cause Analysis', |
| 38 | + 'Operational Impact', |
| 39 | + 'Expected Permanent Solution', |
| 40 | + 'Questions for Maintainers', |
| 41 | + 'Labels and Metadata', |
| 42 | + 'Reference Files', |
| 43 | + 'Steps to Reproduce' |
| 44 | + ].filter(phrase => issueBody.includes(phrase)).length > 4, |
| 45 | + |
| 46 | + // Excessive use of emojis or special characters |
| 47 | + excessiveFormatting: issueBody.includes('---\n \n---') || |
| 48 | + (issueBody.match(/---/g) || []).length > 4, |
| 49 | + |
| 50 | + // Unrealistic version numbers or dates in the future |
| 51 | + futureDates: /202[6-9]|203\d/.test(issueBody), |
| 52 | + |
| 53 | + // Overly detailed technical specs with perfect formatting |
| 54 | + perfectFormatting: issueBody.includes('| Parameter | Value |') && |
| 55 | + issueBody.includes('| Aspect | Status | Impact |'), |
| 56 | + |
| 57 | + // Generic AI-style section headers |
| 58 | + aiSectionHeaders: [ |
| 59 | + '## Description', |
| 60 | + '## Critical Problem', |
| 61 | + '## Affected Environment', |
| 62 | + '## Full Helm Configuration', |
| 63 | + '## Resolution Attempts', |
| 64 | + '## Related Information' |
| 65 | + ].filter(header => issueBody.includes(header)).length > 4, |
| 66 | + |
| 67 | + // Unusual specificity combined with generic solutions |
| 68 | + genericSolutions: issueBody.includes('auto-detect') && |
| 69 | + issueBody.includes('configuration:') && |
| 70 | + (issueBody.match(/```yaml/g) || []).length > 2 |
| 71 | + }; |
| 72 | + |
| 73 | + // Calculate AI score |
| 74 | + let aiScore = 0; |
| 75 | + let detectedPatterns = []; |
| 76 | + |
| 77 | + for (const [pattern, detected] of Object.entries(aiPatterns)) { |
| 78 | + if (detected) { |
| 79 | + aiScore++; |
| 80 | + detectedPatterns.push(pattern); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + console.log(`AI Score: ${aiScore}/8`); |
| 85 | + console.log(`Detected patterns: ${detectedPatterns.join(', ')}`); |
| 86 | + |
| 87 | + // If AI score is high, add label and comment |
| 88 | + if (aiScore >= 3) { |
| 89 | + // Add label |
| 90 | + try { |
| 91 | + await github.rest.issues.addLabels({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + issue_number: issue.number, |
| 95 | + labels: ['needs-triage', 'potential-ai-generated'] |
| 96 | + }); |
| 97 | + |
| 98 | + // Add comment |
| 99 | + const comment = `👋 Thank you for opening this issue! |
| 100 | +
|
| 101 | +This issue has been flagged for review as it may contain AI-generated content (confidence: ${Math.round(aiScore/8 * 100)}%). |
| 102 | + |
| 103 | +**Detected patterns:** ${detectedPatterns.join(', ')} |
| 104 | + |
| 105 | +If this issue was created with AI assistance, please review our [AI contribution guidelines](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#ai-generated-content). |
| 106 | + |
| 107 | +**Important:** |
| 108 | +- Please verify all technical details are accurate |
| 109 | +- Ensure version numbers, dates, and configurations reflect your actual environment |
| 110 | +- Remove any placeholder or example content |
| 111 | +- Confirm the issue is reproducible in your environment |
| 112 | + |
| 113 | +A maintainer will review this issue shortly. If this was flagged in error, please let us know!`; |
| 114 | + |
| 115 | + await github.rest.issues.createComment({ |
| 116 | + owner: context.repo.owner, |
| 117 | + repo: context.repo.repo, |
| 118 | + issue_number: issue.number, |
| 119 | + body: comment |
| 120 | + }); |
| 121 | + |
| 122 | + core.setOutput('ai-detected', 'true'); |
| 123 | + core.setOutput('ai-score', aiScore); |
| 124 | + } catch (error) { |
| 125 | + console.log('Error adding label or comment:', error); |
| 126 | + } |
| 127 | + } else { |
| 128 | + core.setOutput('ai-detected', 'false'); |
| 129 | + core.setOutput('ai-score', aiScore); |
| 130 | + } |
| 131 | + |
| 132 | + return { |
| 133 | + aiDetected: aiScore >= 3, |
| 134 | + score: aiScore, |
| 135 | + patterns: detectedPatterns |
| 136 | + }; |
0 commit comments