Skip to content

Periodic Code Cleanliness Review #210

Periodic Code Cleanliness Review

Periodic Code Cleanliness Review #210

name: "Periodic Code Cleanliness Review"
on:
schedule:
# Run every 12 hours (at 00:00 and 12:00 UTC)
- cron: '0 0,12 * * *'
workflow_dispatch: # Allow manual trigger
permissions:
contents: write
pull-requests: write
issues: write
jobs:
code-cleanliness-review:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@main
with:
fetch-depth: 0 # Full history for better analysis
- name: Analyze Large Files
id: analyze
run: |
echo "## Large Files Analysis" > /tmp/analysis.md
echo "" >> /tmp/analysis.md
echo "Files larger than 500 lines that may benefit from splitting:" >> /tmp/analysis.md
echo "" >> /tmp/analysis.md
# Find files larger than 500 lines (excluding common large files)
find . -type f \( -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.go" -o -name "*.cs" -o -name "*.rb" \) \
! -path "*/node_modules/*" \
! -path "*/dist/*" \
! -path "*/build/*" \
! -path "*/.venv/*" \
! -path "*/vendor/*" \
-exec wc -l {} \; | \
awk '$1 > 500 {print $1 " lines: " $2}' | \
sort -rn >> /tmp/analysis.md || echo "No large files found" >> /tmp/analysis.md
echo "" >> /tmp/analysis.md
echo "## Code Complexity Analysis" >> /tmp/analysis.md
echo "" >> /tmp/analysis.md
echo "Files with potential complexity issues:" >> /tmp/analysis.md
# Find files with many functions/classes (basic heuristic)
for ext in py js ts java go cs rb; do
if [ "$ext" = "py" ]; then
pattern="^def |^class "
elif [ "$ext" = "js" ] || [ "$ext" = "ts" ]; then
pattern="^function |^class |const.*=.*=>|function.*{$"
else
pattern="^class |^def |^func "
fi
find . -type f -name "*.$ext" \
! -path "*/node_modules/*" \
! -path "*/dist/*" \
! -path "*/build/*" \
! -path "*/.venv/*" \
! -path "*/vendor/*" \
-exec sh -c 'count=$(grep -c "$1" "$2" 2>/dev/null || echo 0); count=${count:-0}; if [ "$count" -gt 20 ]; then echo "$count definitions in $2"; fi' _ "$pattern" {} \; \
2>/dev/null || true
done | sort -rn >> /tmp/analysis.md
cat /tmp/analysis.md
# Note: GitHub Copilot CLI action is not available as a public action
# Code cleanliness analysis is already performed in the previous step
- name: Create Issue for Code Cleanliness Review
uses: actions/github-script@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const analysis = fs.readFileSync('/tmp/analysis.md', 'utf8');
const date = new Date().toISOString().split('T')[0];
const title = `Code Cleanliness Review - ${date}`;
const body = `# Periodic Code Cleanliness Review
This is an automated review conducted every 12 hours to maintain code quality.
${analysis}
## Recommendations
Please review the analysis above and:
1. Split large files (>500 lines) into smaller, focused modules
2. Refactor complex functions into smaller, testable units
3. Remove code duplication
4. Ensure consistent code style
5. Improve code organization and structure
## Next Steps
- Assign this issue to relevant team members
- Create follow-up PRs to address findings
- Document any architectural decisions
---
*This issue was automatically generated by the Code Cleanliness Review workflow.*
`;
// Check if similar issue exists (open, created in last 24 hours)
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['code-cleanliness', 'automated'],
per_page: 10
});
const recentIssue = issues.data.find(issue => {
const createdAt = new Date(issue.created_at);
const hoursSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60);
return hoursSinceCreation < 24;
});
if (recentIssue) {
console.log(`Recent issue found: #${recentIssue.number}, skipping creation`);
// Update existing issue with new analysis
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: recentIssue.number,
body: `## Updated Analysis (${date})\n\n${analysis}`
});
} else {
// Create new issue
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['code-cleanliness', 'automated', 'needs-review']
});
}