Skip to content

Commit d5d145c

Browse files
authored
Merge pull request #36 from github/personal-accounts
Enable personal accounts when no org is present
2 parents 96fc3aa + 1b74d9a commit d5d145c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Output files
2+
stale_repos.md
23

34
# Byte-compiled / optimized / DLL files
45
__pycache__/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Below are the allowed configuration options:
3131
| field | required | default | description |
3232
|-----------------------|----------|---------|-------------|
3333
| `GH_TOKEN` | true | | The GitHub Token used to scan repositories. Must have read and write access to all repositories |
34-
| `ORGANIZATION` | true | | The organization to scan for stale repositories |
34+
| `ORGANIZATION` | false | | The organization to scan for stale repositories. If no organization is provided, this tool will search through repositories owned by the GH_TOKEN owner |
3535
| `INACTIVE_DAYS` | true | | The number of days used to determine if repository is stale, based on `push` events |
3636
| `GH_ENTERPRISE_URL` | false | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
3737

stale_repos.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def main(): # pragma: no cover
4343
# Set the organization
4444
organization = os.getenv("ORGANIZATION")
4545
if not organization:
46-
raise ValueError("ORGANIZATION environment variable not set")
46+
print(
47+
"ORGANIZATION environment variable not set, searching all repos owned by token owner"
48+
)
4749

4850
# Iterate over repos in the org, acquire inactive days,
4951
# and print out the repo url and days inactive if it's over the threshold (inactive_days)
@@ -70,9 +72,12 @@ def get_inactive_repos(github_connection, inactive_days_threshold, organization)
7072
7173
"""
7274
inactive_repos = []
73-
org = github_connection.organization(organization)
75+
if organization:
76+
repos = github_connection.organization(organization).repositories()
77+
else:
78+
repos = github_connection.repositories(type="owner")
7479

75-
for repo in org.repositories():
80+
for repo in repos:
7681
last_push_str = repo.pushed_at # type: ignore
7782
if last_push_str is None:
7883
continue

0 commit comments

Comments
 (0)