2017-12-19 19:20:27 +01:00
|
|
|
from flask import render_template, Blueprint
|
2018-01-29 03:39:04 +01:00
|
|
|
from .models.pr import PullRequest
|
|
|
|
from .models.appci import App, AppCI, AppCIBranch
|
2017-12-19 19:20:27 +01:00
|
|
|
from .settings import SITE_ROOT
|
|
|
|
|
|
|
|
main = Blueprint('main', __name__, url_prefix=SITE_ROOT)
|
2017-12-19 17:03:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
def sort_test_results(results):
|
|
|
|
|
|
|
|
results = list(results)
|
|
|
|
|
|
|
|
for r in results:
|
|
|
|
r.level = -1 if r.level is None else r.level
|
|
|
|
|
|
|
|
return sorted(results,
|
2017-12-19 19:20:27 +01:00
|
|
|
key=lambda r: (-r.level, -r.score(), r.app.name))
|
|
|
|
|
2017-12-19 17:03:51 +01:00
|
|
|
|
2017-12-19 19:20:27 +01:00
|
|
|
@main.route('/')
|
2017-12-19 17:03:51 +01:00
|
|
|
def index():
|
|
|
|
return render_template('index.html')
|
|
|
|
|
2017-12-19 19:20:27 +01:00
|
|
|
|
2018-01-29 03:39:04 +01:00
|
|
|
@main.route('/pullrequests')
|
|
|
|
def pullrequests():
|
|
|
|
|
|
|
|
prs = PullRequest.query.all()
|
|
|
|
|
|
|
|
prs = sorted(prs, key=lambda pr: (pr.review_priority, pr.created), reverse=True)
|
|
|
|
|
|
|
|
active_prs = [ pr for pr in prs if pr.review_priority >= 0]
|
|
|
|
count_by_team = { "all": len(active_prs),
|
|
|
|
"core": len([pr for pr in active_prs if pr.repo.team == "core"]),
|
|
|
|
"apps": len([pr for pr in active_prs if pr.repo.team == "apps"]),
|
|
|
|
"infra": len([pr for pr in active_prs if pr.repo.team == "infra"]),
|
|
|
|
"doc": len([pr for pr in active_prs if pr.repo.team == "doc"]) }
|
|
|
|
|
|
|
|
return render_template("pullrequests.html", prs=prs, count_by_team=count_by_team)
|
|
|
|
|
|
|
|
|
2017-12-19 19:20:27 +01:00
|
|
|
@main.route('/appci/branch/<branch>')
|
2017-12-19 17:03:51 +01:00
|
|
|
def appci_branch(branch):
|
|
|
|
|
|
|
|
branch = AppCIBranch.query.filter_by(name=branch).first_or_404()
|
|
|
|
|
|
|
|
app_results = sort_test_results(branch.most_recent_tests_per_app())
|
|
|
|
|
|
|
|
return render_template("appci_branch.html", tests=AppCI.tests,
|
|
|
|
branch=branch,
|
|
|
|
app_results=app_results)
|
|
|
|
|
2017-12-19 19:20:27 +01:00
|
|
|
|
|
|
|
@main.route('/appci/app/<app>')
|
2017-12-19 17:03:51 +01:00
|
|
|
def appci_app(app):
|
|
|
|
|
|
|
|
app = App.query.filter_by(name=app).first_or_404()
|
|
|
|
|
|
|
|
branch_results = list(app.most_recent_tests_per_branch())
|
|
|
|
|
|
|
|
for r in branch_results:
|
|
|
|
r.level = -1 if r.level is None else r.level
|
|
|
|
|
|
|
|
return render_template("appci_app.html", tests=AppCI.tests,
|
|
|
|
app=app,
|
|
|
|
branch_results=branch_results)
|
|
|
|
|
2017-12-19 19:20:27 +01:00
|
|
|
|
|
|
|
@main.route('/appci/compare/<ref>...<target>')
|
2017-12-19 17:03:51 +01:00
|
|
|
def appci_compare(ref, target):
|
|
|
|
|
|
|
|
assert ref != target, "Can't compare the same branches, bruh"
|
|
|
|
|
|
|
|
ref = AppCIBranch.query.filter_by(name=ref).first_or_404()
|
|
|
|
target = AppCIBranch.query.filter_by(name=target).first_or_404()
|
|
|
|
|
|
|
|
ref_results = sort_test_results(ref.most_recent_tests_per_app())
|
|
|
|
target_results = sort_test_results(target.most_recent_tests_per_app())
|
|
|
|
|
|
|
|
for ref_r in ref_results:
|
|
|
|
ref_r.level_compare = next((r.level for r in target_results
|
|
|
|
if r.app == ref_r.app),
|
|
|
|
-1)
|
|
|
|
|
|
|
|
return render_template("appci_compare.html", ref=ref,
|
|
|
|
target=target,
|
|
|
|
results=ref_results)
|
|
|
|
|