|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """ Find stale repositories in a GitHub organization. """ |
3 | 3 |
|
| 4 | +import json |
4 | 5 | import os |
5 | 6 | from datetime import datetime, timezone |
6 | 7 | from os.path import dirname, join |
@@ -50,6 +51,7 @@ def main(): |
50 | 51 | github_connection, inactive_days_threshold, organization |
51 | 52 | ) |
52 | 53 |
|
| 54 | + output_to_json(inactive_repos) |
53 | 55 | # Write the list of inactive repos to a csv file |
54 | 56 | write_to_markdown(inactive_repos, inactive_days_threshold) |
55 | 57 |
|
@@ -104,6 +106,26 @@ def write_to_markdown(inactive_repos, inactive_days_threshold, file=None): |
104 | 106 | file.write(f"| {repo_url} | {days_inactive} |\n") |
105 | 107 | print("Wrote stale repos to stale_repos.md") |
106 | 108 |
|
| 109 | +def output_to_json(inactive_repos): |
| 110 | + """Convert the list of inactive repos to a json string. |
| 111 | +
|
| 112 | + Args: |
| 113 | + inactive_repos: A list of tuples containing the repo and days inactive. |
| 114 | +
|
| 115 | + """ |
| 116 | + # json structure is like following |
| 117 | + # [ |
| 118 | + # { |
| 119 | + # "url": "https://github.com/owner/repo", |
| 120 | + # "daysInactive": 366 |
| 121 | + # } |
| 122 | + # ] |
| 123 | + inactive_repos_json = [] |
| 124 | + for repo_url, days_inactive in inactive_repos: |
| 125 | + inactive_repos_json.append({"url": repo_url, "daysInactive": days_inactive}) |
| 126 | + inactive_repos_json = json.dumps(inactive_repos_json) |
| 127 | + |
| 128 | + print(f"::set-output name=inactiveRepos::{inactive_repos_json}") |
107 | 129 |
|
108 | 130 | def auth_to_github(): |
109 | 131 | """Connect to GitHub.com or GitHub Enterprise, depending on env variables.""" |
|
0 commit comments