-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (35 loc) · 1.5 KB
/
main.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
import argparse
import utils
import tempfile
import shutil
from datetime import datetime
parser = argparse.ArgumentParser(prog='Verify commits and tags in github')
parser.add_argument("-days", action="store", default=15)
args = parser.parse_args()
days = int(args.days)
with open('repos.txt') as f:
lines = [line.rstrip() for line in f]
print(f"Execution in {len(lines)} repositories")
for line in lines:
tmp_folder = tempfile.mkdtemp()
project_name = line.split("/")[4].replace(".git", "")
owner = line.split("/")[3]
print(f"Execution in {project_name}")
try:
utils.checkout_repo(folder=tmp_folder, repo=line)
utils.fetch_repo(folder=tmp_folder)
last_date_commit = utils.get_last_date_commit(folder=tmp_folder)
last_date_tag = utils.get_last_date_tag(folder=tmp_folder)
if not last_date_tag:
print(f"\033[33m Project {project_name} has no tags")
continue
timestamp_tag = float(last_date_tag)
timestamp_commit = float(last_date_commit)
date_latest_commit = datetime.fromtimestamp(timestamp_commit)
date_latest_tag = datetime.fromtimestamp(timestamp_tag)
difference_of_days = (datetime.now() - date_latest_commit).days
if date_latest_commit > date_latest_tag and difference_of_days > days:
utils.send_message(project_name=project_name, difference_of_days=str(difference_of_days),
owner=owner)
finally:
shutil.rmtree(tmp_folder)