| |
@@ -31,7 +31,7 @@
|
| |
from blockerbugs.models.bug import Bug
|
| |
from blockerbugs.util import pagure_bot
|
| |
from . import errors
|
| |
- from .utils import get_or_404, JsonResponse, check_signature
|
| |
+ from .utils import get_or_404, JsonResponse, SVGResponse, check_signature
|
| |
|
| |
api_v0 = Blueprint('api', __name__, url_prefix='/api/v0')
|
| |
|
| |
@@ -143,3 +143,53 @@
|
| |
msg = 'Unable to parse issue id from received message'
|
| |
app.logger.debug(msg)
|
| |
return JsonResponse({'msg': msg})
|
| |
+
|
| |
+
|
| |
+ def _svg_response_text(info_all):
|
| |
+ svg_template = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="{total_height}" width="300">'\
|
| |
+ '{info_lines}'\
|
| |
+ '</svg>'
|
| |
+ info_line_template = '<text font-family="sans-serif" x="0" y="{y_offset}" font-size="14px" fill="#212529">{info}</text>'
|
| |
+
|
| |
+ # height of each line is 17px, text is rendered at y offset 13px (4px bellow as padding)
|
| |
+ # y_offset of nth line is 13 * (n + 1) + 4 * n = 13*n + 13 + 4*n = 17*n + 13
|
| |
+ info_lines = [info_line_template.format(y_offset=17 * index + 13,
|
| |
+ info=info) for index, info in enumerate(info_all)]
|
| |
+ return svg_template.format(total_height=17 * len(info_all), info_lines="".join(info_lines))
|
| |
+
|
| |
+
|
| |
+ def _get_bugtypes(bug):
|
| |
+ bugtypes = []
|
| |
+ if bug.proposed_blocker:
|
| |
+ bugtypes.append("Proposed Blocker")
|
| |
+ if bug.proposed_fe:
|
| |
+ bugtypes.append("Proposed FE")
|
| |
+ if bug.rejected_blocker:
|
| |
+ bugtypes.append("Rejected Blocker")
|
| |
+ if bug.rejected_fe:
|
| |
+ bugtypes.append("Rejected FE")
|
| |
+ if bug.accepted_blocker:
|
| |
+ bugtypes.append("Accepted Blocker")
|
| |
+ if bug.accepted_0day:
|
| |
+ bugtypes.append("Accepted 0day")
|
| |
+ if bug.accepted_prevrel:
|
| |
+ bugtypes.append("Accepted Previous release")
|
| |
+ if bug.accepted_fe:
|
| |
+ bugtypes.append("Accepted FE")
|
| |
+ return bugtypes
|
| |
+
|
| |
+ _UNKNOWN_BUG_SVG_TEXT = _svg_response_text(["unknown bug"])
|
| |
+
|
| |
+ @api_v0.route('/bugimg/<int:bug_id>')
|
| |
+ def bug_image(bug_id):
|
| |
+ bugs = Bug.query.filter_by(bugid=bug_id).all()
|
| |
+ if not bugs:
|
| |
+ return SVGResponse(_UNKNOWN_BUG_SVG_TEXT)
|
| |
+ else:
|
| |
+ info_all = []
|
| |
+ for bug in bugs:
|
| |
+ milestone_info = "%s: " % bug.milestone.name
|
| |
+ bugtypes = _get_bugtypes(bug)
|
| |
+ info_all.append(milestone_info + ", ".join(bugtypes))
|
| |
+
|
| |
+ return SVGResponse(_svg_response_text(info_all))
|
| |
I'd personally get rid of the
_UNKNOWN_BUG_SVG_TEXT
variable, and just replace this withreturn SVGResponse(_svg_response_text(["unknown bug"]))
. The variable doesn't seem to be used elsewhere anyway, and also this way the string doesn't need to be computed each time this module is loaded. But that's just a nitpick, not important.Edit: I missed that the variable is used in the unit test. ¯_(ツ)_/¯ Both approaches work fine here.