Commit d781ebff authored by Pietro Albini's avatar Pietro Albini

Add a nice frontend to managetests

parent f9a55984
...@@ -25,7 +25,7 @@ file di configurazione `config.json` presente in essa, in questo modo: ...@@ -25,7 +25,7 @@ file di configurazione `config.json` presente in essa, in questo modo:
{ {
"gitlab-token": "YOUR-API-KEY", "gitlab-token": "YOUR-API-KEY",
"gitlab-url": "http://code.ubuntu-it.org", "gitlab-url": "http://code.ubuntu-it.org",
"gitlab-project": 22, "gitlab-project": "ubuntu-it-web/www",
"keep-branches": [ "keep-branches": [
"master" "master"
] ]
......
...@@ -22,7 +22,7 @@ import pkg_resources ...@@ -22,7 +22,7 @@ import pkg_resources
from . import utils from . import utils
from . import branches from . import branches
from . import instances from . import instances
from . import webhooks from . import frontend
from . import gitlab from . import gitlab
...@@ -35,9 +35,9 @@ class TestsManager: ...@@ -35,9 +35,9 @@ class TestsManager:
self.gitlab = gitlab.GitLabAPI(self) self.gitlab = gitlab.GitLabAPI(self)
hooks_processor = webhooks.HooksProcessor(self) hooks_processor = frontend.HooksProcessor(self)
self.webhook = webhooks.create_app(self, hooks_processor) self.frontend = frontend.create_app(self, hooks_processor)
self.instances = instances.InstancesManager(self, self.webhook, self.instances = instances.InstancesManager(self, self.frontend,
hooks_processor) hooks_processor)
if not utils.is_root_valid(root): if not utils.is_root_valid(root):
...@@ -71,7 +71,7 @@ class TestsManager: ...@@ -71,7 +71,7 @@ class TestsManager:
for branch_name in self.config["keep-branches"]: for branch_name in self.config["keep-branches"]:
if branch_name in self.branches: if branch_name in self.branches:
continue continue
self.load_branch(branch_name, -1) self.load_branch(branch_name, None)
# Load also new branches from merge requests # Load also new branches from merge requests
new = self.gitlab.merge_requests() new = self.gitlab.merge_requests()
......
...@@ -27,23 +27,42 @@ class Branch: ...@@ -27,23 +27,42 @@ class Branch:
self.manager = manager self.manager = manager
self.name = name self.name = name
self.merge_request = merge_request self.mr = merge_request
self.mr_id = None
self.mr_url = None
self.author = None
self.author_url = None
self.assignee = None
self.assignee_url = None
self.pinned = name in manager.config["keep-branches"]
self.check_remote_status() self.check_remote_status()
self.check_local_status() self.check_local_status()
def check_remote_status(self): def check_remote_status(self):
"""Check the branch merging status on GitLab""" """Check the branch merging status on GitLab"""
if self.name in self.manager.config["keep-branches"]: if self.pinned:
self.active = True self.active = True
return return
result = self.manager.gitlab.merge_request(self.merge_request) result = self.manager.gitlab.merge_request(self.mr)
if result: if result:
active = result["state"] == "opened" active = result["state"] == "opened"
else: else:
active = False active = False
self.active = active self.active = active
self.mr_id = result["iid"]
self.mr_url = (self.manager.config["gitlab-url"]+"/"+
self.manager.config["gitlab-project"]+
"/merge_requests/"+str(self.mr_id))
self.author = result["author"]["username"]
self.author_url = result["author"]["web_url"]
if result["assignee"] is not None:
self.assignee = result["assignee"]["username"]
self.assignee_url = result["assignee"]["web_url"]
def check_local_status(self): def check_local_status(self):
"""Check if the branch is present locally""" """Check if the branch is present locally"""
...@@ -87,7 +106,7 @@ class Branch: ...@@ -87,7 +106,7 @@ class Branch:
for command in commands: for command in commands:
subprocess.call(command, shell=True) subprocess.call(command, shell=True)
self.manager.details["branches"][self.name] = self.merge_request self.manager.details["branches"][self.name] = self.mr
self.manager.save_details() self.manager.save_details()
def destroy(self): def destroy(self):
......
...@@ -46,8 +46,20 @@ class HooksProcessor(threading.Thread): ...@@ -46,8 +46,20 @@ class HooksProcessor(threading.Thread):
def create_app(manager, processor): def create_app(manager, processor):
"""Create an instance of the app which captures webhooks""" """Create an instance of the frontend app"""
app = flask.Flask(__name__) app = flask.Flask(__name__, static_url_path="/+assets")
@app.errorhandler(404)
def on_404(*_):
return flask.render_template("404.html"), 404
@app.route("/")
def list_branches():
branches = list(manager.branches.values())
branches.sort(key=lambda branch: branch.name)
branches.sort(key=lambda branch: branch.pinned, reverse=True)
return flask.render_template("index.html", branches=branches)
@app.route("/+hook", methods=["POST"]) @app.route("/+hook", methods=["POST"])
def hook(): def hook():
......
/* A program which manages Ubuntu-it's web test server
* Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; witout even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/>.
*/
@charset "utf-8";
body {
font-family: sans-serif;
color: #333;
margin: 0;
text-align: center;
line-height: 1.3em;
}
a {
display: inline-block;
border-bottom: 0.1em dotted currentColor;
text-decoration: none;
color: #dd4814;
}
a:hover {
border-bottom-style: solid;
}
h1 {
font-size: 1.6em;
font-weight: 400;
margin: 0.9em 0;
}
hr {
border: none;
border-bottom: 0.1em dotted #ccc;
margin: 1.4em 0;
}
ul {
padding: 0 0 0 1.5em;
}
ul li {
list-style: square;
margin: 0.4em 0;
}
div.wrapper {
width: 50em;
margin: auto;
}
ul.branches {
text-align: left;
}
ul.branches li small {
display: inline-block;
margin-left: 0.5em;
}
ul.footer {
color: #aaa;
font-size: 0.9em;
margin: 0;
padding: 0;
}
ul.footer li {
display: inline-block;
margin: 0 0 0 1em;
}
ul.footer li:first-child {
margin-left: 0;
}
@media all and (max-width: 52em) {
div.wrapper {
width: 96%;
}
ul.footer li {
display: block;
margin: 0.5em 0;
}
}
@media all and (max-width: 30em) {
span.extra {
margin-top: 0.1em;
display: block;
}
span.extra small:first-child {
margin-left: 0;
}
}
{# A program which manages Ubuntu-it's web test server
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/>.
#}
{% extends "layout.html" %}
{% set title = "Pagina non trovata" %}
{% block content %}
<p>
Prova a cercare meglio... oppure vai alla
<a href="{{ url_for("list_branches") }}">lista dei branch</a>.
</p>
{% endblock %}
{# A program which manages Ubuntu-it's web test server
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/>.
#}
{% extends "layout.html" %}
{% set title = "Branch disponibili" %}
{% block content %}
{% if not branches %}
{% else %}
<ul class="branches">
{% for branch in branches %}
<li>
<a href="/{{ branch.name }}/">{{ branch.name }}</a>
<span class="extra">
{% if branch.pinned %}
<small>branch fisso</small>
{% else %}
<small>
branch di <a href="{{ branch.author_url }}">{{ branch.author }}</a>
{% if branch.assignee and branch.assignee != branch.author %}
e <a href="{{ branch.assignee_url }}">{{ branch.assignee }}</a>
{% endif %}
</small>
<small>
<a href="{{ branch.mr_url }}">Merge request #{{ branch.mr_id }}</a>
</small>
{% endif %}
</span>
</li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
{# A program which manages Ubuntu-it's web test server
# Copyright (C) 2015 Pietro Albini <pietroalbini@ubuntu.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/>.
#}
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<link rel="stylesheet" href="{{ url_for("static", filename="style.css") }}">
</head>
<body>
<div class="wrapper">
<h1>{{ title }}</h1>
<hr>
{% block content %}{% endblock %}
<hr>
<ul class="footer">
<li>
Questo è managetests, realizzato con &#9829; dal Gruppo Web
di Ubuntu-it.
</li>
<li><a href="http://code.ubuntu-it.org/ubuntu-it-web/managetests">
Codice sorgente</a> (AGPLv3+)</li>
</ul>
</div>
</body>
</html>
...@@ -24,7 +24,7 @@ class GitLabAPI: ...@@ -24,7 +24,7 @@ class GitLabAPI:
self.manager = manager self.manager = manager
self.url = manager.config["gitlab-url"] self.url = manager.config["gitlab-url"]
self.token = manager.config["gitlab-token"] self.token = manager.config["gitlab-token"]
self.project = manager.config["gitlab-project"] self.project = manager.config["gitlab-project"].replace("/", "%2F")
def call(self, method, endpoint, params=None, data=None): def call(self, method, endpoint, params=None, data=None):
"""Make a raw call to the GitLab API""" """Make a raw call to the GitLab API"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment