Created
September 23, 2015 14:09
-
-
Save rcapraro/0a56993488ce58a933c0 to your computer and use it in GitHub Desktop.
Deletes old sonar projects (last analysis date older than 60 days)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import iso8601 | |
import pytz | |
from datetime import datetime, timedelta | |
url_projects = 'http://srvpic.intra.sada.fr:9000/sonar/api/resources' | |
url_delete = 'http://srvpic.intra.sada.fr:9000/sonar/api/projects/destroy' | |
params = dict( | |
qualifiers='TRK', | |
format='json' | |
) | |
resp = requests.get(url=url_projects, params=params) | |
data = json.loads(resp.text) | |
project_keep_date = datetime.now(pytz.UTC) - timedelta(days=60) | |
for project in data: | |
last_analysis_date = iso8601.parse_date(project['date']) | |
if ((last_analysis_date < project_keep_date) and (project['branch'] != 'master')): | |
delete_params = dict( | |
id=project['id'] | |
) | |
result = requests.post(url=url_delete, params=delete_params, auth=('admin', 'admin')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment