Skip to content

Commit

Permalink
fix: fix nits
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed May 19, 2023
1 parent 952617c commit 8f494ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.8-slim-buster
LABEL org.opencontainers.image.source https://github.com/github/stale_repos

WORKDIR /action/workspace
COPY requirements.txt stale_repos.py /action/workspace/
Expand Down
14 changes: 9 additions & 5 deletions stale_repos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
""" Find stale repositories in a GitHub organization. """

import os
from datetime import datetime
Expand Down Expand Up @@ -31,12 +32,15 @@ def main():
ghe = os.getenv("GH_ENTERPRISE_URL", default="").strip()
token = os.getenv("GH_TOKEN")
if ghe and token:
gh = github3.github.GitHubEnterprise(ghe, token=token)
github_connection = github3.github.GitHubEnterprise(ghe, token=token)
elif token:
gh = github3.login(token=os.getenv("GH_TOKEN"))
github_connection = github3.login(token=os.getenv("GH_TOKEN"))
else:
raise ValueError("GH_TOKEN environment variable not set")

if not github_connection:
raise ValueError("Unable to authenticate to GitHub")

# Set the threshold for inactive days
inactive_days_threshold = os.getenv("INACTIVE_DAYS")
if not inactive_days_threshold:
Expand All @@ -49,14 +53,14 @@ def main():

# Iterate over repos in the org, acquire inactive days,
# and print out the repo url and days inactive if it's over the threshold (inactive_days)
for repo in gh.repositories_by(organization):
last_push_str = repo.pushed_at
for repo in github_connection.repositories_by(organization):
last_push_str = repo.pushed_at # type: ignore
if last_push_str is None:
continue
last_push = datetime.fromisoformat(last_push_str[:-1])
days_inactive = (datetime.now() - last_push).days
if days_inactive > int(inactive_days_threshold):
print(f"{repo.html_url}: {days_inactive} days inactive")
print(f"{repo.html_url}: {days_inactive} days inactive") # type: ignore


if __name__ == "__main__":
Expand Down

0 comments on commit 8f494ba

Please sign in to comment.