Skip to content

Commit

Permalink
new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
htrgouvea committed Apr 8, 2024
1 parent 88dc0bb commit b470180
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions scripts/search_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import requests
import argparse
from datetime import datetime, timedelta

def repositories(org, token):
response = requests.get(
Expand All @@ -27,16 +28,40 @@ def search_file(repository, token):

return False

def last_commit_date(repository, token):
response = requests.get(
f'https://api.github.com/repos/{repository}/commits',
headers={'Authorization': f'Bearer {token}'}
)

if response.status_code == 200:
if len(response.json()) > 0:
last_commit_date_str = response.json()[0]['commit']['committer']['date']
last_commit_date = datetime.strptime(last_commit_date_str, "%Y-%m-%dT%H:%M:%SZ")
return last_commit_date
return None

if __name__ == '__main__':
parse = argparse.ArgumentParser(description='Search for specific files in the repositories of an organization.')
parse.add_argument('--org', help='Specify the name of the organization\n', required=True)
parse.add_argument('--token', help='Set the Github Token to use during actions.', required=True)
parse.add_argument('--maintained', help='Check last commit date of repositories.', action='store_true')
parse.add_argument('--dependency', help='Check for dependabot.yaml file in repositories.', action='store_true')
args = parse.parse_args()

if args.org:
repos = repositories(args.org, args.token)

for repository in repos:
dependabot = search_file(repository, args.token)
if args.dependency:
for repository in repos:
dependabot = search_file(repository, args.token)

if dependabot:
print(dependabot)

if args.maintained:
for repository in repos:
last_commit = last_commit_date(repository, args.token)

print (dependabot) if dependabot else None
if last_commit and datetime.utcnow() - last_commit > timedelta(days=90):
print(f'The repository {repository} has not been updated for more than 90 days.')

0 comments on commit b470180

Please sign in to comment.