Skip to content

Commit

Permalink
Merge pull request #3 from github/nits
Browse files Browse the repository at this point in the history
fix: fix nits
  • Loading branch information
zkoppert committed May 19, 2023
2 parents 952617c + c09bd4f commit 05d4478
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
github3.py==4.0.1
python-dotenv==1.0.0
python_dateutil==2.8.2
17 changes: 11 additions & 6 deletions stale_repos.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python
""" Find stale repositories in a GitHub organization. """

import os
from datetime import datetime
from os.path import dirname, join

import github3
from dateutil.parser import parse
from dotenv import load_dotenv


Expand All @@ -31,12 +33,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 +54,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])
last_push = parse(last_push_str)
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 05d4478

Please sign in to comment.