|
1 | 1 | name: "Periodic Code Cleanliness Review" |
2 | | -uto-amazonq-review.properties.json |
3 | 2 |
|
4 | | -uto-amazonq-review.properties.json |
| 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 |
| 6 | + |
5 | 7 | on: |
6 | | -uto-amazonq-review.properties.json |
7 | 8 | schedule: |
8 | | -uto-amazonq-review.properties.json |
9 | 9 | # Run every 12 hours (at 00:00 and 12:00 UTC) |
10 | | -uto-amazonq-review.properties.json |
11 | 10 | - cron: '0 0,12 * * *' |
12 | | -uto-amazonq-review.properties.json |
13 | 11 | workflow_dispatch: # Allow manual trigger |
14 | | -uto-amazonq-review.properties.json |
15 | 12 |
|
16 | | -uto-amazonq-review.properties.json |
17 | 13 | permissions: |
18 | | -uto-amazonq-review.properties.json |
19 | 14 | contents: write |
20 | | -uto-amazonq-review.properties.json |
21 | 15 | pull-requests: write |
22 | | -uto-amazonq-review.properties.json |
23 | 16 | issues: write |
24 | | -uto-amazonq-review.properties.json |
25 | 17 |
|
26 | | -uto-amazonq-review.properties.json |
27 | 18 | jobs: |
28 | | -uto-amazonq-review.properties.json |
29 | 19 | code-cleanliness-review: |
30 | | -uto-amazonq-review.properties.json |
31 | | - runs-on: self-hosted |
32 | | -uto-amazonq-review.properties.json |
| 20 | + runs-on: ubuntu-latest |
33 | 21 | steps: |
34 | | -uto-amazonq-review.properties.json |
35 | 22 | - name: Checkout code |
36 | | -uto-amazonq-review.properties.json |
37 | 23 | uses: actions/checkout@main |
38 | | -uto-amazonq-review.properties.json |
39 | 24 | with: |
40 | | -uto-amazonq-review.properties.json |
41 | 25 | fetch-depth: 0 # Full history for better analysis |
42 | | -uto-amazonq-review.properties.json |
43 | 26 |
|
44 | | -uto-amazonq-review.properties.json |
45 | 27 | - name: Analyze Large Files |
46 | | -uto-amazonq-review.properties.json |
47 | 28 | id: analyze |
48 | | -uto-amazonq-review.properties.json |
49 | 29 | run: | |
50 | | -uto-amazonq-review.properties.json |
51 | 30 | echo "## Large Files Analysis" > /tmp/analysis.md |
52 | | -uto-amazonq-review.properties.json |
53 | 31 | echo "" >> /tmp/analysis.md |
54 | | -uto-amazonq-review.properties.json |
55 | 32 | echo "Files larger than 500 lines that may benefit from splitting:" >> /tmp/analysis.md |
56 | | -uto-amazonq-review.properties.json |
57 | 33 | echo "" >> /tmp/analysis.md |
58 | | -uto-amazonq-review.properties.json |
59 | 34 | |
60 | | -uto-amazonq-review.properties.json |
61 | 35 | # Find files larger than 500 lines (excluding common large files) |
62 | | -uto-amazonq-review.properties.json |
63 | 36 | find . -type f \( -name "*.py" -o -name "*.js" -o -name "*.ts" -o -name "*.java" -o -name "*.go" -o -name "*.cs" -o -name "*.rb" \) \ |
64 | | -uto-amazonq-review.properties.json |
65 | 37 | ! -path "*/node_modules/*" \ |
66 | | -uto-amazonq-review.properties.json |
67 | 38 | ! -path "*/dist/*" \ |
68 | | -uto-amazonq-review.properties.json |
69 | 39 | ! -path "*/build/*" \ |
70 | | -uto-amazonq-review.properties.json |
71 | 40 | ! -path "*/.venv/*" \ |
72 | | -uto-amazonq-review.properties.json |
73 | 41 | ! -path "*/vendor/*" \ |
74 | | -uto-amazonq-review.properties.json |
75 | 42 | -exec wc -l {} \; | \ |
76 | | -uto-amazonq-review.properties.json |
77 | 43 | awk '$1 > 500 {print $1 " lines: " $2}' | \ |
78 | | -uto-amazonq-review.properties.json |
79 | 44 | sort -rn >> /tmp/analysis.md || echo "No large files found" >> /tmp/analysis.md |
80 | | -uto-amazonq-review.properties.json |
81 | 45 | |
82 | | -uto-amazonq-review.properties.json |
83 | 46 | echo "" >> /tmp/analysis.md |
84 | | -uto-amazonq-review.properties.json |
85 | 47 | echo "## Code Complexity Analysis" >> /tmp/analysis.md |
86 | | -uto-amazonq-review.properties.json |
87 | 48 | echo "" >> /tmp/analysis.md |
88 | | -uto-amazonq-review.properties.json |
89 | 49 | echo "Files with potential complexity issues:" >> /tmp/analysis.md |
90 | | -uto-amazonq-review.properties.json |
91 | 50 | |
92 | | -uto-amazonq-review.properties.json |
93 | 51 | # Find files with many functions/classes (basic heuristic) |
94 | | -uto-amazonq-review.properties.json |
95 | 52 | for ext in py js ts java go cs rb; do |
96 | | -uto-amazonq-review.properties.json |
97 | 53 | if [ "$ext" = "py" ]; then |
98 | | -uto-amazonq-review.properties.json |
99 | 54 | pattern="^def |^class " |
100 | | -uto-amazonq-review.properties.json |
101 | 55 | elif [ "$ext" = "js" ] || [ "$ext" = "ts" ]; then |
102 | | -uto-amazonq-review.properties.json |
103 | 56 | pattern="^function |^class |const.*=.*=>|function.*{$" |
104 | | -uto-amazonq-review.properties.json |
105 | 57 | else |
106 | | -uto-amazonq-review.properties.json |
107 | 58 | pattern="^class |^def |^func " |
108 | | -uto-amazonq-review.properties.json |
109 | 59 | fi |
110 | | -uto-amazonq-review.properties.json |
111 | 60 | |
112 | | -uto-amazonq-review.properties.json |
113 | 61 | find . -type f -name "*.$ext" \ |
114 | | -uto-amazonq-review.properties.json |
115 | 62 | ! -path "*/node_modules/*" \ |
116 | | -uto-amazonq-review.properties.json |
117 | 63 | ! -path "*/dist/*" \ |
118 | | -uto-amazonq-review.properties.json |
119 | 64 | ! -path "*/build/*" \ |
120 | | -uto-amazonq-review.properties.json |
121 | 65 | ! -path "*/.venv/*" \ |
122 | | -uto-amazonq-review.properties.json |
123 | 66 | ! -path "*/vendor/*" \ |
124 | | -uto-amazonq-review.properties.json |
125 | 67 | -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" {} \; \ |
126 | | -uto-amazonq-review.properties.json |
127 | 68 | 2>/dev/null || true |
128 | | -uto-amazonq-review.properties.json |
129 | 69 | done | sort -rn >> /tmp/analysis.md |
130 | | -uto-amazonq-review.properties.json |
131 | 70 | |
132 | | -uto-amazonq-review.properties.json |
133 | 71 | cat /tmp/analysis.md |
134 | | -uto-amazonq-review.properties.json |
135 | 72 |
|
136 | | -uto-amazonq-review.properties.json |
137 | 73 | - name: GitHub Copilot Code Review |
138 | | -uto-amazonq-review.properties.json |
139 | | - uses: github/copilot-cli-action@main |
140 | | -uto-amazonq-review.properties.json |
| 74 | + uses: austenstone/copilot-cli-action@v2 |
141 | 75 | with: |
142 | | -uto-amazonq-review.properties.json |
143 | | - query: | |
144 | | -uto-amazonq-review.properties.json |
| 76 | + copilot-token: ${{ secrets.COPILOT_TOKEN }} |
| 77 | + prompt: | |
145 | 78 | Review the codebase for code cleanliness issues: |
146 | | -uto-amazonq-review.properties.json |
147 | 79 | 1. Identify files that are too large (>500 lines) and suggest how to split them into smaller, focused modules |
148 | | -uto-amazonq-review.properties.json |
149 | 80 | 2. Look for code duplication and suggest refactoring opportunities |
150 | | -uto-amazonq-review.properties.json |
151 | 81 | 3. Check for consistent code style and formatting |
152 | | -uto-amazonq-review.properties.json |
153 | 82 | 4. Identify complex functions that could be simplified |
154 | | -uto-amazonq-review.properties.json |
155 | 83 | 5. Suggest improvements for code organization and structure |
156 | | -uto-amazonq-review.properties.json |
157 | 84 | 6. Check for proper separation of concerns |
158 | | -uto-amazonq-review.properties.json |
159 | 85 | |
160 | | -uto-amazonq-review.properties.json |
161 | 86 | Provide actionable recommendations with specific file names and line numbers. |
162 | | -uto-amazonq-review.properties.json |
163 | | - env: |
164 | | -uto-amazonq-review.properties.json |
165 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
166 | | -uto-amazonq-review.properties.json |
167 | 87 | continue-on-error: true |
168 | | -uto-amazonq-review.properties.json |
169 | 88 |
|
170 | | -uto-amazonq-review.properties.json |
171 | 89 | - name: Create Issue for Code Cleanliness Review |
172 | | -uto-amazonq-review.properties.json |
173 | 90 | uses: actions/github-script@main |
174 | | -uto-amazonq-review.properties.json |
175 | 91 | with: |
176 | | -uto-amazonq-review.properties.json |
177 | 92 | github-token: ${{ secrets.GITHUB_TOKEN }} |
178 | | -uto-amazonq-review.properties.json |
179 | 93 | script: | |
180 | | -uto-amazonq-review.properties.json |
181 | 94 | const fs = require('fs'); |
182 | | -uto-amazonq-review.properties.json |
183 | 95 | const analysis = fs.readFileSync('/tmp/analysis.md', 'utf8'); |
184 | | -uto-amazonq-review.properties.json |
185 | 96 | |
186 | | -uto-amazonq-review.properties.json |
187 | 97 | const date = new Date().toISOString().split('T')[0]; |
188 | | -uto-amazonq-review.properties.json |
189 | 98 | const title = `Code Cleanliness Review - ${date}`; |
190 | | -uto-amazonq-review.properties.json |
191 | 99 | |
192 | | -uto-amazonq-review.properties.json |
193 | 100 | const body = `# Periodic Code Cleanliness Review |
194 | | -uto-amazonq-review.properties.json |
195 | 101 | |
196 | | -uto-amazonq-review.properties.json |
197 | 102 | This is an automated review conducted every 12 hours to maintain code quality. |
198 | | -uto-amazonq-review.properties.json |
199 | 103 | |
200 | | -uto-amazonq-review.properties.json |
201 | 104 | ${analysis} |
202 | | -uto-amazonq-review.properties.json |
203 | 105 | |
204 | | -uto-amazonq-review.properties.json |
205 | 106 | ## Recommendations |
206 | | -uto-amazonq-review.properties.json |
207 | 107 | |
208 | | -uto-amazonq-review.properties.json |
209 | 108 | Please review the analysis above and: |
210 | | -uto-amazonq-review.properties.json |
211 | 109 | 1. Split large files (>500 lines) into smaller, focused modules |
212 | | -uto-amazonq-review.properties.json |
213 | 110 | 2. Refactor complex functions into smaller, testable units |
214 | | -uto-amazonq-review.properties.json |
215 | 111 | 3. Remove code duplication |
216 | | -uto-amazonq-review.properties.json |
217 | 112 | 4. Ensure consistent code style |
218 | | -uto-amazonq-review.properties.json |
219 | 113 | 5. Improve code organization and structure |
220 | | -uto-amazonq-review.properties.json |
221 | 114 | |
222 | | -uto-amazonq-review.properties.json |
223 | 115 | ## Next Steps |
224 | | -uto-amazonq-review.properties.json |
225 | 116 | |
226 | | -uto-amazonq-review.properties.json |
227 | 117 | - Assign this issue to relevant team members |
228 | | -uto-amazonq-review.properties.json |
229 | 118 | - Create follow-up PRs to address findings |
230 | | -uto-amazonq-review.properties.json |
231 | 119 | - Document any architectural decisions |
232 | | -uto-amazonq-review.properties.json |
233 | 120 | |
234 | | -uto-amazonq-review.properties.json |
235 | 121 | --- |
236 | | -uto-amazonq-review.properties.json |
237 | 122 | *This issue was automatically generated by the Code Cleanliness Review workflow.* |
238 | | -uto-amazonq-review.properties.json |
239 | 123 | `; |
240 | | -uto-amazonq-review.properties.json |
241 | 124 | |
242 | | -uto-amazonq-review.properties.json |
243 | 125 | // Check if similar issue exists (open, created in last 24 hours) |
244 | | -uto-amazonq-review.properties.json |
245 | 126 | const issues = await github.rest.issues.listForRepo({ |
246 | | -uto-amazonq-review.properties.json |
247 | 127 | owner: context.repo.owner, |
248 | | -uto-amazonq-review.properties.json |
249 | 128 | repo: context.repo.repo, |
250 | | -uto-amazonq-review.properties.json |
251 | 129 | state: 'open', |
252 | | -uto-amazonq-review.properties.json |
253 | 130 | labels: ['code-cleanliness', 'automated'], |
254 | | -uto-amazonq-review.properties.json |
255 | 131 | per_page: 10 |
256 | | -uto-amazonq-review.properties.json |
257 | 132 | }); |
258 | | -uto-amazonq-review.properties.json |
259 | 133 | |
260 | | -uto-amazonq-review.properties.json |
261 | 134 | const recentIssue = issues.data.find(issue => { |
262 | | -uto-amazonq-review.properties.json |
263 | 135 | const createdAt = new Date(issue.created_at); |
264 | | -uto-amazonq-review.properties.json |
265 | 136 | const hoursSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60); |
266 | | -uto-amazonq-review.properties.json |
267 | 137 | return hoursSinceCreation < 24; |
268 | | -uto-amazonq-review.properties.json |
269 | 138 | }); |
270 | | -uto-amazonq-review.properties.json |
271 | 139 | |
272 | | -uto-amazonq-review.properties.json |
273 | 140 | if (recentIssue) { |
274 | | -uto-amazonq-review.properties.json |
275 | 141 | console.log(`Recent issue found: #${recentIssue.number}, skipping creation`); |
276 | | -uto-amazonq-review.properties.json |
277 | 142 | // Update existing issue with new analysis |
278 | | -uto-amazonq-review.properties.json |
279 | 143 | await github.rest.issues.createComment({ |
280 | | -uto-amazonq-review.properties.json |
281 | 144 | owner: context.repo.owner, |
282 | | -uto-amazonq-review.properties.json |
283 | 145 | repo: context.repo.repo, |
284 | | -uto-amazonq-review.properties.json |
285 | 146 | issue_number: recentIssue.number, |
286 | | -uto-amazonq-review.properties.json |
287 | 147 | body: `## Updated Analysis (${date})\n\n${analysis}` |
288 | | -uto-amazonq-review.properties.json |
289 | 148 | }); |
290 | | -uto-amazonq-review.properties.json |
291 | 149 | } else { |
292 | | -uto-amazonq-review.properties.json |
293 | 150 | // Create new issue |
294 | | -uto-amazonq-review.properties.json |
295 | 151 | await github.rest.issues.create({ |
296 | | -uto-amazonq-review.properties.json |
297 | 152 | owner: context.repo.owner, |
298 | | -uto-amazonq-review.properties.json |
299 | 153 | repo: context.repo.repo, |
300 | | -uto-amazonq-review.properties.json |
301 | 154 | title: title, |
302 | | -uto-amazonq-review.properties.json |
303 | 155 | body: body, |
304 | | -uto-amazonq-review.properties.json |
305 | 156 | labels: ['code-cleanliness', 'automated', 'needs-review'] |
306 | | -uto-amazonq-review.properties.json |
307 | 157 | }); |
308 | | -uto-amazonq-review.properties.json |
309 | 158 | } |
310 | | -uto-amazonq-review.properties.json |
0 commit comments