diff --git a/config.py b/config.py new file mode 100644 index 0000000000000000000000000000000000000000..4d05694b1899fadbef68cf638c668587fe6cd953 --- /dev/null +++ b/config.py @@ -0,0 +1,9 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) +print(f"DEBUG: config {basedir}") + +class Config(object): + SQLALCHEMY_TRACK_MODIFICATIONS = False + + +# this is a test diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..42836009da80a55aafcccf39a4596c606c0d897c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +blinker==1.6.2 +certifi==2023.5.7 +charset-normalizer==3.1.0 +click==8.1.3 +docopt==0.6.2 +Flask==2.3.2 +idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +requests==2.31.0 +urllib3==2.0.2 +Werkzeug==2.3.4 diff --git a/sq_projects_list.py b/sq_projects_list.py index 327e45e662d49b4ae022e1967f0cf498df7db8e9..ab9d7eb86c6f11ff36ac8046fe5bb797e2eccfd4 100755 --- a/sq_projects_list.py +++ b/sq_projects_list.py @@ -31,43 +31,20 @@ def filter_data(data, months_nr): filtered_data.append(item) return filtered_data - -if __name__ == '__main__': - # parse the command line arguments using docopt - args = docopt(__doc__) - months = args['--months'] - 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> -host = sonarqube.example.org - -You can generate a token in SonarQube under My Account > Security -''') - os.sys.exit(1) - +def fetch_data(sq_ini = os.path.expanduser('~/.config/sonarqube.ini')): config = configparser.RawConfigParser() config.read(sq_ini) sq_token = config.get('sq', 'token') sq_host = config.get('sq', 'host') - session = requests.Session() session.auth = (sq_token, '') req = session.get(f'https://{sq_host}/api/projects/search') if req.status_code == 401: - print('Error: Invalid token') - os.sys.exit(1) + raise Exception('Error: Invalid token') if req.status_code != 200: - print(f'Error: HTTP status code is {req.status_code}') - os.sys.exit(1) + raise Exception(f'Error: HTTP status code is {req.status_code}') proj_list = req.json()['components'] final_list = [] @@ -83,8 +60,33 @@ You can generate a token in SonarQube under My Account > Security 'project_name': project['name'], 'last_analysis_date': '1970-01-01T01:00:00+0200' }) + return final_list + + + +if __name__ == '__main__': + # parse the command line arguments using docopt + args = docopt(__doc__) + months = args['--months'] + 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> +host = sonarqube.example.org + +You can generate a token in SonarQube under My Account > Security +''') + os.sys.exit(1) + # filter the data based on the last_analysis_date + final_list = fetch_data() filtered_list = filter_data(final_list, int(months)) sorted_projects = sorted( diff --git a/sq_webapp.py b/sq_webapp.py new file mode 100644 index 0000000000000000000000000000000000000000..1230decc9b5a5158dfc7e8e86eb9d1edadacd99c --- /dev/null +++ b/sq_webapp.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +from webapp import app +#from app.models import User, Post + +@app.shell_context_processor +def make_shell_context(): + return {'db': db, 'User': User, 'Post': Post} + + + +if __name__ == "__main__": + app.run(debug=True,port=10001, host="127.0.0.1") \ No newline at end of file diff --git a/webapp/__init__.py b/webapp/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..90ad198e3f7c2bd302edd0324d3d0370961339c4 --- /dev/null +++ b/webapp/__init__.py @@ -0,0 +1,8 @@ +from flask import Flask +from config import Config + +app = Flask(__name__) +app.config.from_object(Config) + +from webapp import routes#, models + diff --git a/webapp/routes.py b/webapp/routes.py new file mode 100644 index 0000000000000000000000000000000000000000..3cf83ac2e2fae07d98aa1489defcf30e32bc7550 --- /dev/null +++ b/webapp/routes.py @@ -0,0 +1,20 @@ +from flask import render_template, flash, redirect, url_for, Response, json +from flask import request +from werkzeug.urls import url_parse +from webapp import app + +from sq_projects_list import filter_data, fetch_data + +import config +conf = config.Config() + +@app.route('/') +@app.route('/index') +def index(): + try: + return Response(json.dumps(filter_data(fetch_data(),12 )), status=200 ) + except: + return Response('Wea have a problem', status=500) + return filter_data(fetch_data(),12 ) + +