Skip to content

Commit edc3a76

Browse files
no92ArsenArsen
authored andcommitted
web: add build status badges for projects
1 parent 5ccd976 commit edc3a76

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docker/Dockerfile-devrt

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ADD xbbs /src/xbbs
3232
# of anything except managarm-bootstrap)
3333
RUN . /venv/bin/activate \
3434
&& pip install https://github.com/ArsenArsen/valideer/archive/cec1755914c21628706bb1392e0c61c6c600318e.tar.gz \
35-
&& pip install y4
35+
&& pip install y4 pybadges
3636
RUN . /venv/bin/activate && pip install -e /src/.'[history]'
3737

3838
# Download cbuildrt v0.1.3

xbbs/web/__init__.py

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import flask.json.provider
1111
import humanize
1212
import msgpack
13+
import pybadges
1314
import zmq
1415
from flask import (
1516
Flask,
@@ -199,6 +200,45 @@ def overview():
199200
)
200201

201202

203+
@app.route("/badge/<project_name>")
204+
def badge(project_name):
205+
status = msgs.StatusMessage.unpack(send_request(b"status", b""))
206+
if project_name not in status.projects:
207+
raise NotFound("unknown project")
208+
209+
project = path.join(projbase, project_name)
210+
try:
211+
_listdir = os.listdir(project)
212+
except NotADirectoryError:
213+
raise NotFound()
214+
215+
build_history = []
216+
for build in _listdir:
217+
try:
218+
build_ts = xutils.strptime(build, xutils.TIMESTAMP_FORMAT)
219+
except ValueError:
220+
continue
221+
build_info = load_build(status, project_name, build)
222+
build_info.update(timestamp=build_ts)
223+
build_history.append(build_info)
224+
build_history.sort(key=lambda x: x["timestamp"], reverse=True)
225+
226+
for item in build_history:
227+
if ("finished" not in item) or (not item["finished"]):
228+
secondary = "running"
229+
color = "yellow"
230+
else:
231+
secondary = "success" if item["success"] else "failing"
232+
color = "green" if item["success"] else "red"
233+
234+
return flask.Response(
235+
pybadges.badge(left_text=project_name, right_text=secondary, right_color=color),
236+
mimetype='image/svg+xml'
237+
)
238+
239+
raise NotFound("project has no builds yet")
240+
241+
202242
@app.route("/jobs/<proj>/<ts>")
203243
def job_view(proj, ts):
204244
status = msgs.StatusMessage.unpack(send_request(b"status", b""))

0 commit comments

Comments
 (0)