Skip to content
Snippets Groups Projects
Commit fa8f6f66 authored by Pete Pedersen's avatar Pete Pedersen
Browse files

DEV-153 FIRST version of the web app version :-)

parent 8078844c
No related branches found
No related tags found
No related merge requests found
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
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
......@@ -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(
......
#!/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
from flask import Flask
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
from webapp import routes#, models
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 )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment