forked from gardenlinux/gardenlinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-pkgs-pipelines.py
executable file
·73 lines (53 loc) · 2.14 KB
/
check-pkgs-pipelines.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
#!/usr/bin/env python3
import argparse
import re
import requests
import re
import glob
from pprint import pprint
import yaml
def check_pkgs_pipelines(full=False):
gitlab_url = 'https://gitlab.com'
group_name = 'gardenlinux'
response = requests.get(f'{gitlab_url}/api/v4/groups/{group_name}', headers="")
group_id = response.json()['id']
response = requests.get(f'{gitlab_url}/api/v4/groups/{group_id}/projects?visibility=public', headers="")
projects = response.json()
report = {}
for project in projects:
if project['archived']:
continue
project_id = project['id']
last_activity_at = project['last_activity_at']
project_web_url = project['web_url']
response = requests.get(f'{gitlab_url}/api/v4/projects/{project_id}/pipelines?ref=main', headers="")
pipelines = response.json()
if pipelines:
pipeline_status = pipelines[0]['status']
else:
pipeline_status = None
if not full and pipeline_status == 'success':
continue
# Get open issues
response = requests.get(f'{gitlab_url}/api/v4/projects/{project_id}/issues?state=opened', headers="")
open_issues = len(response.json())
# Use the project name as the key, and the value is another dict containing the information for that project
report[project['name']] = {
'last_activity_at': last_activity_at,
'pipeline_status': pipeline_status,
'web_url': project_web_url,
'open_issues': open_issues,
}
sorted_report = sorted(report.items(), key=lambda x: x[1]['pipeline_status'] != 'failed', )
return sorted_report
def main(full):
report = check_pkgs_pipelines(full)
if report:
print("Failed Gitlab Pipelines:")
print(yaml.dump(dict(report)))
exit(1)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check package availability')
parser.add_argument("--full", help="include all projects, not just those with non-successful pipeline status", action="store_true")
args = parser.parse_args()
main(args.full)