Skip to content

Commit 3f0ee3d

Browse files
committed
Sync auto-copilot-code-cleanliness-review.yml from .github repo
1 parent b45719d commit 3f0ee3d

File tree

1 file changed

+8
-148
lines changed

1 file changed

+8
-148
lines changed
Lines changed: 8 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,298 +1,158 @@
11
name: "Periodic Code Cleanliness Review"
22

3-
on:
3+
# REQUIREMENTS:
4+
# - A GitHub Personal Access Token with Copilot access must be created and stored as a repository secret named COPILOT_TOKEN
5+
# - See COPILOT_TOKEN_SETUP.md for detailed setup instructions
46

7+
on:
58
schedule:
6-
79
# Run every 12 hours (at 00:00 and 12:00 UTC)
8-
910
- cron: '0 0,12 * * *'
10-
1111
workflow_dispatch: # Allow manual trigger
1212

1313
permissions:
14-
1514
contents: write
16-
1715
pull-requests: write
18-
1916
issues: write
2017

2118
jobs:
22-
2319
code-cleanliness-review:
24-
25-
runs-on: self-hosted
26-
20+
runs-on: [self-hosted, linux, x64, big]
2721
steps:
28-
2922
- name: Checkout code
30-
3123
uses: actions/checkout@main
32-
3324
with:
34-
3525
fetch-depth: 0 # Full history for better analysis
3626

3727
- name: Analyze Large Files
38-
3928
id: analyze
40-
4129
run: |
42-
4330
echo "## Large Files Analysis" > /tmp/analysis.md
44-
4531
echo "" >> /tmp/analysis.md
46-
4732
echo "Files larger than 500 lines that may benefit from splitting:" >> /tmp/analysis.md
48-
4933
echo "" >> /tmp/analysis.md
50-
5134
52-
5335
# Find files larger than 500 lines (excluding common large files)
54-
5536
find . -type f \( -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.go" -o -name "*.cs" -o -name "*.rb" \) \
56-
5737
! -path "*/node_modules/*" \
58-
5938
! -path "*/dist/*" \
60-
6139
! -path "*/build/*" \
62-
6340
! -path "*/.venv/*" \
64-
6541
! -path "*/vendor/*" \
66-
6742
-exec wc -l {} \; | \
68-
6943
awk '$1 > 500 {print $1 " lines: " $2}' | \
70-
7144
sort -rn >> /tmp/analysis.md || echo "No large files found" >> /tmp/analysis.md
72-
7345
74-
7546
echo "" >> /tmp/analysis.md
76-
7747
echo "## Code Complexity Analysis" >> /tmp/analysis.md
78-
7948
echo "" >> /tmp/analysis.md
80-
8149
echo "Files with potential complexity issues:" >> /tmp/analysis.md
82-
8350
84-
8551
# Find files with many functions/classes (basic heuristic)
86-
8752
for ext in py js ts java go cs rb; do
88-
8953
if [ "$ext" = "py" ]; then
90-
9154
pattern="^def |^class "
92-
9355
elif [ "$ext" = "js" ] || [ "$ext" = "ts" ]; then
94-
9556
pattern="^function |^class |const.*=.*=>|function.*{$"
96-
9757
else
98-
9958
pattern="^class |^def |^func "
100-
10159
fi
102-
10360
104-
10561
find . -type f -name "*.$ext" \
106-
10762
! -path "*/node_modules/*" \
108-
10963
! -path "*/dist/*" \
110-
11164
! -path "*/build/*" \
112-
11365
! -path "*/.venv/*" \
114-
11566
! -path "*/vendor/*" \
116-
11767
-exec sh -c 'count=$(grep -c "$1" "$2" 2>/dev/null || echo 0); if [ "$count" -gt 20 ]; then echo "$count definitions in $2"; fi' _ "$pattern" {} \; \
118-
11968
2>/dev/null || true
120-
12169
done | sort -rn >> /tmp/analysis.md
122-
12370
124-
12571
cat /tmp/analysis.md
12672
12773
- name: GitHub Copilot Code Review
128-
129-
uses: github/copilot-cli-action@main
130-
74+
uses: austenstone/copilot-cli-action@v2
13175
with:
132-
133-
query: |
134-
76+
copilot-token: ${{ secrets.COPILOT_TOKEN }}
77+
prompt: |
13578
Review the codebase for code cleanliness issues:
136-
13779
1. Identify files that are too large (>500 lines) and suggest how to split them into smaller, focused modules
138-
13980
2. Look for code duplication and suggest refactoring opportunities
140-
14181
3. Check for consistent code style and formatting
142-
14382
4. Identify complex functions that could be simplified
144-
14583
5. Suggest improvements for code organization and structure
146-
14784
6. Check for proper separation of concerns
148-
14985
150-
15186
Provide actionable recommendations with specific file names and line numbers.
152-
153-
env:
154-
155-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156-
15787
continue-on-error: true
15888

15989
- name: Create Issue for Code Cleanliness Review
160-
16190
uses: actions/github-script@main
162-
16391
with:
164-
16592
github-token: ${{ secrets.GITHUB_TOKEN }}
166-
16793
script: |
168-
16994
const fs = require('fs');
170-
17195
const analysis = fs.readFileSync('/tmp/analysis.md', 'utf8');
172-
17396
174-
17597
const date = new Date().toISOString().split('T')[0];
176-
17798
const title = `Code Cleanliness Review - ${date}`;
178-
17999
180-
181100
const body = `# Periodic Code Cleanliness Review
182-
183101
184-
185102
This is an automated review conducted every 12 hours to maintain code quality.
186-
187103
188-
189104
${analysis}
190-
191105
192-
193106
## Recommendations
194-
195107
196-
197108
Please review the analysis above and:
198-
199109
1. Split large files (>500 lines) into smaller, focused modules
200-
201110
2. Refactor complex functions into smaller, testable units
202-
203111
3. Remove code duplication
204-
205112
4. Ensure consistent code style
206-
207113
5. Improve code organization and structure
208-
209114
210-
211115
## Next Steps
212-
213116
214-
215117
- Assign this issue to relevant team members
216-
217118
- Create follow-up PRs to address findings
218-
219119
- Document any architectural decisions
220-
221120
222-
223121
---
224-
225122
*This issue was automatically generated by the Code Cleanliness Review workflow.*
226-
227123
`;
228-
229124
230-
231125
// Check if similar issue exists (open, created in last 24 hours)
232-
233126
const issues = await github.rest.issues.listForRepo({
234-
235127
owner: context.repo.owner,
236-
237128
repo: context.repo.repo,
238-
239129
state: 'open',
240-
241130
labels: ['code-cleanliness', 'automated'],
242-
243131
per_page: 10
244-
245132
});
246-
247133
248-
249134
const recentIssue = issues.data.find(issue => {
250-
251135
const createdAt = new Date(issue.created_at);
252-
253136
const hoursSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60);
254-
255137
return hoursSinceCreation < 24;
256-
257138
});
258-
259139
260-
261140
if (recentIssue) {
262-
263141
console.log(`Recent issue found: #${recentIssue.number}, skipping creation`);
264-
265142
// Update existing issue with new analysis
266-
267143
await github.rest.issues.createComment({
268-
269144
owner: context.repo.owner,
270-
271145
repo: context.repo.repo,
272-
273146
issue_number: recentIssue.number,
274-
275147
body: `## Updated Analysis (${date})\n\n${analysis}`
276-
277148
});
278-
279149
} else {
280-
281150
// Create new issue
282-
283151
await github.rest.issues.create({
284-
285152
owner: context.repo.owner,
286-
287153
repo: context.repo.repo,
288-
289154
title: title,
290-
291155
body: body,
292-
293156
labels: ['code-cleanliness', 'automated', 'needs-review']
294-
295157
});
296-
297158
}
298-

0 commit comments

Comments
 (0)