-
Notifications
You must be signed in to change notification settings - Fork 2
/
inactive-r.py
82 lines (68 loc) · 2.57 KB
/
inactive-r.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import csv
import os
from datetime import datetime
from github import Github
from termcolor import colored
class OutdatedRepos:
def __init__(self):
self.g = Github(os.environ.get("API_KEY"))
self.org = self.g.get_organization(os.environ.get("ORGANIZATION_NAME"))
self.repos = self.org.get_repos()
self.current_date = datetime.now()
self.outdated_repos = []
def get_repo_data(self):
for repo in self.repos:
repo_details = {}
last_pushed = repo.pushed_at
last_pushed_str = last_pushed.strftime("%Y-%m-%dT%H:%M:%SZ")
time_since_last_push = (self.current_date - last_pushed).days
years, remainder = divmod(time_since_last_push, 365)
months, days = divmod(remainder, 30)
if time_since_last_push >= 730:
repo_details["Name"] = repo.full_name
repo_details["Desc"] = repo.description
repo_details["Language"] = ",".join(repo.get_languages().keys())
repo_details["Last_Push_date"] = last_pushed_str
repo_details["Years"] = years
repo_details["Months"] = months
repo_details["Days"] = days
self.outdated_repos.append(repo_details)
print(
colored(
f"[+] {repo.full_name}: Last Push Was --> [ {years} years, {months} months, and {days} days ago {repo_details['Language']} ]",
"yellow",
)
)
print(
colored(
f"\n\n[++] A Total of {len(self.outdated_repos)} repos had their last push at least 2 year ago to date {self.current_date} [++]",
"red",
)
)
def save_as_csv(self):
with open("inactive_repos.csv", mode="w", newline="") as file:
fieldnames = [
"Name",
"Desc",
"Language",
"Last_Push_date",
"Years",
"Months",
"Days",
]
writer = csv.DictWriter(file, fieldnames=fieldnames)
writer.writeheader()
for repo in self.outdated_repos:
writer.writerow(repo)
print(
colored(
f"\n\n[+++] Finished writing results to CSV file > outdated_repos.csv [+++]",
"green",
)
)
def main():
reposcan = OutdatedRepos()
reposcan.get_repo_data()
reposcan.save_as_csv()
if __name__ == "__main__":
main()