forked from fga-eps-mds/2023.1-Amis-Front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonar_metrics.py
46 lines (36 loc) · 1023 Bytes
/
sonar_metrics.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
import requests
from datetime import datetime
import sys
import os
SONAR_API='https://sonarcloud.io/api/measures/component'
COMPONENT_KEY='fga-eps-mds_2022.2-Amis-Front'
TODAY=datetime.now()
REPOSITORY=sys.argv[1]
RELEASE_VERSION=sys.argv[2]
FILE_PATH = f'./analytics-raw-data/fga-eps-mds-{REPOSITORY}-{TODAY.strftime("%m-%d-%Y-%H-%M-%S")}-{RELEASE_VERSION}.json'
metric_list = [
'files',
'functions',
'complexity',
'comment_lines_density',
'duplicated_lines_density',
'coverage',
'ncloc',
'tests',
'test_errors',
'test_failures',
'test_execution_time',
'security_rating'
]
body = {
'metricKeys': ','.join(metric_list),
'componentKey': COMPONENT_KEY
}
if __name__ == '__main__':
response = requests.get(SONAR_API, params=body)
text_response = response.text
if not os.path.exists('./analytics-raw-data'):
os.makedirs('./analytics-raw-data')
with open(FILE_PATH, 'w') as file:
file.write(text_response)
file.close()