|
11 | 11 | from env import get_env_vars
|
12 | 12 |
|
13 | 13 | import auth
|
| 14 | +from markdown import write_to_markdown |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def main(): # pragma: no cover
|
@@ -241,101 +242,6 @@ def get_active_date(repo):
|
241 | 242 | return active_date
|
242 | 243 |
|
243 | 244 |
|
244 |
| -def write_to_markdown( |
245 |
| - inactive_repos, |
246 |
| - inactive_days_threshold, |
247 |
| - additional_metrics=None, |
248 |
| - workflow_summary_enabled=False, |
249 |
| - file=None, |
250 |
| -): |
251 |
| - """Write the list of inactive repos to a markdown file. |
252 |
| -
|
253 |
| - Args: |
254 |
| - inactive_repos: A list of dictionaries containing the repo, days inactive, |
255 |
| - the date of the last push, repository visibility (public/private), |
256 |
| - days since the last release, and days since the last pr |
257 |
| - inactive_days_threshold: The threshold (in days) for considering a repo as inactive. |
258 |
| - additional_metrics: A list of additional metrics to include in the report. |
259 |
| - workflow_summary_enabled: If True, adds the report to GitHub Actions workflow summary. |
260 |
| - file: A file object to write to. If None, a new file will be created. |
261 |
| -
|
262 |
| - """ |
263 |
| - inactive_repos = sorted( |
264 |
| - inactive_repos, key=lambda x: x["days_inactive"], reverse=True |
265 |
| - ) |
266 |
| - |
267 |
| - # Generate markdown content |
268 |
| - content = generate_markdown_content( |
269 |
| - inactive_repos, inactive_days_threshold, additional_metrics |
270 |
| - ) |
271 |
| - |
272 |
| - # Write to file |
273 |
| - with file or open("stale_repos.md", "w", encoding="utf-8") as markdown_file: |
274 |
| - markdown_file.write(content) |
275 |
| - print("Wrote stale repos to stale_repos.md") |
276 |
| - |
277 |
| - # Write to GitHub step summary if enabled |
278 |
| - if workflow_summary_enabled and os.environ.get("GITHUB_STEP_SUMMARY"): |
279 |
| - with open( |
280 |
| - os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8" |
281 |
| - ) as summary_file: |
282 |
| - summary_file.write(content) |
283 |
| - print("Added stale repos to workflow summary") |
284 |
| - |
285 |
| - |
286 |
| -def generate_markdown_content( |
287 |
| - inactive_repos, inactive_days_threshold, additional_metrics=None |
288 |
| -): |
289 |
| - """Generate markdown content for the inactive repos report. |
290 |
| -
|
291 |
| - Args: |
292 |
| - inactive_repos: A list of dictionaries containing the repo, days inactive, |
293 |
| - the date of the last push, repository visibility (public/private), |
294 |
| - days since the last release, and days since the last pr |
295 |
| - inactive_days_threshold: The threshold (in days) for considering a repo as inactive. |
296 |
| - additional_metrics: A list of additional metrics to include in the report. |
297 |
| -
|
298 |
| - Returns: |
299 |
| - str: The generated markdown content. |
300 |
| - """ |
301 |
| - content = "# Inactive Repositories\n\n" |
302 |
| - content += ( |
303 |
| - f"The following repos have not had a push event for more than " |
304 |
| - f"{inactive_days_threshold} days:\n\n" |
305 |
| - ) |
306 |
| - content += "| Repository URL | Days Inactive | Last Push Date | Visibility |" |
307 |
| - |
308 |
| - # Include additional metrics columns if configured |
309 |
| - if additional_metrics: |
310 |
| - if "release" in additional_metrics: |
311 |
| - content += " Days Since Last Release |" |
312 |
| - if "pr" in additional_metrics: |
313 |
| - content += " Days Since Last PR |" |
314 |
| - content += "\n| --- | --- | --- | --- |" |
315 |
| - if additional_metrics: |
316 |
| - if "release" in additional_metrics: |
317 |
| - content += " --- |" |
318 |
| - if "pr" in additional_metrics: |
319 |
| - content += " --- |" |
320 |
| - content += "\n" |
321 |
| - |
322 |
| - for repo_data in inactive_repos: |
323 |
| - content += ( |
324 |
| - f"| {repo_data['url']} " |
325 |
| - f"| {repo_data['days_inactive']} " |
326 |
| - f"| {repo_data['last_push_date']} " |
327 |
| - f"| {repo_data['visibility']} |" |
328 |
| - ) |
329 |
| - if additional_metrics: |
330 |
| - if "release" in additional_metrics: |
331 |
| - content += f" {repo_data['days_since_last_release']} |" |
332 |
| - if "pr" in additional_metrics: |
333 |
| - content += f" {repo_data['days_since_last_pr']} |" |
334 |
| - content += "\n" |
335 |
| - |
336 |
| - return content |
337 |
| - |
338 |
| - |
339 | 245 | def output_to_json(inactive_repos, file=None):
|
340 | 246 | """Convert the list of inactive repos to a json string.
|
341 | 247 |
|
|
0 commit comments