Skip to content
Snippets Groups Projects
Commit 5ff9d46b authored by Massimiliano Adamo's avatar Massimiliano Adamo
Browse files

Add sq_projects_list.py

parent d7c2ee93
Branches
Tags
No related merge requests found
#!/usr/bin/env python3
"""
This script will list all projects in SonarQube
and sort them by last analysis date
"""
import os
import json
import configparser
import requests
sq_ini = os.path.expanduser('~/.config/sonarqube.ini')
if not os.path.isfile(sq_ini):
print(f'''
Config file not found
Please create the config file {sq_ini}
with the following content:
[sq]
token = <your token>
You can generate a token in SonarQube under My Account > Security
''')
os.sys.exit(1)
CONFIG = configparser.RawConfigParser(allow_no_value=True)
CONFIG.read(sq_ini)
sq_token = CONFIG.get('sq', 'token')
session = requests.Session()
session.auth = (sq_token, '')
req = session.get('https://sonarqube.software.geant.org/api/projects/search')
proj_list = req.json()['components']
final_list = []
for project in proj_list:
if 'lastAnalysisDate' in project:
final_list.append({
'project_name': project['name'],
'last_analysis_date': project['lastAnalysisDate']
})
else:
final_list.append({
'project_name': project['name'],
'last_analysis_date': '1970-01-01T01:00:00+0200'
})
sorted_projects = sorted(final_list, key=lambda d: d['last_analysis_date'])
pretty = json.dumps(sorted_projects, indent=4)
print(pretty)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment