|
10 | 10 | import flask.json.provider
|
11 | 11 | import humanize
|
12 | 12 | import msgpack
|
| 13 | +import pybadges |
13 | 14 | import zmq
|
14 | 15 | from flask import (
|
15 | 16 | Flask,
|
@@ -199,6 +200,45 @@ def overview():
|
199 | 200 | )
|
200 | 201 |
|
201 | 202 |
|
| 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 | + |
202 | 242 | @app.route("/jobs/<proj>/<ts>")
|
203 | 243 | def job_view(proj, ts):
|
204 | 244 | status = msgs.StatusMessage.unpack(send_request(b"status", b""))
|
|
0 commit comments