Skip to content

Commit

Permalink
Buildlog added simple highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
lovec741 committed Oct 13, 2024
1 parent 914671f commit d066196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import tomllib
from functools import wraps
import magic
import re
from html import escape

from repository import Repository
from auth import isLoggedIn, registerAuthRoutes, requireLogin
Expand Down Expand Up @@ -95,7 +97,15 @@ def info(repo: Repository):
@requireLogin
@repo_required
def buildlog(repo: Repository):
return render_template('buildlog.html.jinja', repo_name=repo.name, log=repo.logger.getBuildLog())
build_log = repo.logger.getBuildLog()
if build_log is None:
highlighted_log = None
else:
warning_pattern = re.compile(r'(warn(ing)*)', re.IGNORECASE)
error_pattern = re.compile(r'(error)', re.IGNORECASE)
highlighted_log = warning_pattern.sub(r'<span class="fw-bold text-warning">\1</span>', escape(build_log))
highlighted_log = error_pattern.sub(r'<span class="fw-bold text-danger">\1</span>', highlighted_log)
return render_template('buildlog.html.jinja', repo_name=repo.name, log=highlighted_log)

@app.route('/build/<string:repo_name>')
@requireLogin
Expand Down
2 changes: 1 addition & 1 deletion src/templates/buildlog.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<i class="bi bi-arrow-down"></i> Go to Bottom
</a>

<pre class="p-4 bg-dark text-light border border-secondary rounded"><code>{{ log | e }}</code></pre>
<pre class="p-4 bg-dark text-light border border-secondary rounded"><code>{{ log }}</code></pre>
<a href="#" class="btn btn-outline-secondary mb-5">
<i class="bi bi-arrow-up"></i> Go to Top
</a>
Expand Down

0 comments on commit d066196

Please sign in to comment.