Skip to content

Commit

Permalink
Add revlink arg to WebStatus (adds links to revisions-ids) + cleanups
Browse files Browse the repository at this point in the history
 * move shortrev/revlink html from python to jinja2 macro
 * add missing revlink, shortrev filters in html templates
 * remove TODO on b.changesText() (we list any change comments already)
  • Loading branch information
marcus-sonestedt committed Jan 19, 2010
1 parent 4e6513b commit dee5b49
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 35 deletions.
80 changes: 64 additions & 16 deletions buildbot/status/web/base.py
Expand Up @@ -414,32 +414,80 @@ def userfilter(value):
return jinja2.escape(value)


def shortrevfilter(value):
''' Shorten the revisison string to 12-chars (Mercurial short-id),
allow to see full id on mouse over. '''
def shortrevfilter(replace, templates):
''' Returns a function which shortens the revisison string
to 12-chars (Mercurial short-id)
and add link if replacement string is set.
try:
value = unicode(value)
(The full id is still visible in HTML, for mouse-over events etc.)
TODO: Add a 'source' argument to SourceStamp and apply it here
@param replace: a python format string with an %s
@param templates: a jinja2 environment
'''

def filter(value):
if not value:
return u''

macros = templates.get_template("revmacros.html").module
value = unicode(value)

if replace:
id_html = macros.id_replace
short_html = macros.shorten_replace
url = replace % urllib.quote(value)
else:
id_html = macros.id
short_html = macros.shorten
url = None

value = jinja2.escape(value)
short = value[:12]
except TypeError:
return jinja2.escape(value)

if short == value:
return jinja2.Markup('<span class="revision">%s</span>') % value
if short == value:
return id_html(rev=value, url=url)
else:
return short_html(short=short, rev=value, url=url)

return filter


def revlinkfilter(replace, templates):
''' Returns a function which adds an url link to a
revision identifiers.
@param replace: a python format string with an %s
@param templates: a jinja2 environment
'''

html = jinja2.Markup('''
<div class="revision"><div class="short">%(short)s</div>
<div class="full">%(full)s</div></div>''')
return html % dict(short=short, full=value)
def filter(value):
if not value:
return u''

macros = templates.get_template("revmacros.html").module
value = unicode(value)

if replace:
html = macros.id_replace
url = replace % urllib.quote(value)
else:
html = macros.id
url = None

return html(rev=value, url=url)

return filter


def addlinkfilter(search, replace):
''' Returns function that does regex search/replace in
comments to add links to bug ids and similar.
search - a regex to match what we look for
replace - an url with \1\2 to include data from search
(I wrap with the <a href="...">...</a>.. myself)
@param search: a regex to match what we look for
@param replace: an url with \1\2 to include data from search
(I wrap with the <a href="...">...</a>.. myself)
'''

regex = re.compile(search)
Expand Down
19 changes: 16 additions & 3 deletions buildbot/status/web/baseweb.py
Expand Up @@ -348,7 +348,8 @@ class WebStatus(service.MultiService):
def __init__(self, http_port=None, distrib_port=None, allowForce=False,
public_html="public_html", site=None, numbuilds=20,
num_events=200, num_events_max=None, auth=None,
order_console_by_time=False, changecommentlink=None):
order_console_by_time=False, changecommentlink=None,
revlink=None):
"""Run a web server that provides Buildbot status.
@type http_port: int or L{twisted.application.strports} string
Expand Down Expand Up @@ -423,6 +424,13 @@ def __init__(self, http_port=None, distrib_port=None, allowForce=False,
to all change comments. The first element represents what to search
for and the second yields an url (the <a href=""></a> is added outside this)
I.e. for Trac: (r"#(\d+)", r"http://buildbot.net/trac/ticket/\1")
@type revlink: string or C{None}
@param revlink: a replacement string that is applied to all revisions and
will, if set, create a link to the result of the replacement.
Use %s to insert the revision id in the url.
I.e. for Buildbot on github: ('http://github.com/djmitche/buildbot/tree/%s')
(The revision id will be URL encoded before inserted in the replacement string)
"""

service.MultiService.__init__(self)
Expand Down Expand Up @@ -484,10 +492,15 @@ def __init__(self, http_port=None, distrib_port=None, allowForce=False,

self.templates.filters['email'] = webbase.emailfilter
self.templates.filters['user'] = webbase.userfilter
self.templates.filters['shortrev'] = webbase.shortrevfilter
self.templates.filters['shortrev'] = \
webbase.shortrevfilter(revlink, self.templates)
self.templates.filters['revlink'] = \
webbase.revlinkfilter(revlink, self.templates)

if changecommentlink:
regex, replace = changecommentlink
self.templates.filters['changecomment'] = \
webbase.addlinkfilter(*changecommentlink)
webbase.addlinkfilter(regex, replace)
else:
self.templates.filters['changecomment'] = jinja2.escape

Expand Down
14 changes: 2 additions & 12 deletions buildbot/status/web/templates/build.html
Expand Up @@ -42,7 +42,7 @@ <h2>SourceStamp:</h2>
{% endif %}

{% if ss.revision %}
<tr class="{{ ss_class.next() }}"><td class="left">Revision</td><td>{{ ss.revision|e }}</td></tr>
<tr class="{{ ss_class.next() }}"><td class="left">Revision</td><td>{{ ss.revision|revlink }}</td></tr>
{% endif %}

{% if ss.patch %}
Expand All @@ -58,7 +58,7 @@ <h2>SourceStamp:</h2>
{% endif %}

{% if got_revision %}
<tr class="{{ ss_class.next() }}"><td class="left">Got Revision</td><td>{{ got_revision }}</td></tr>
<tr class="{{ ss_class.next() }}"><td class="left">Got Revision</td><td>{{ got_revision|revlink }}</td></tr>
{% endif %}

</table>
Expand Down Expand Up @@ -197,17 +197,7 @@ <h2>All Changes:</h2>
<li>{{ change(**c.html_dict()) }}</li>
{% endfor %}
</ol>

{# TODO:
# <pre>{{ b.changesText()|e }}</pre>
#}

</div>
{% endif %}






{% endblock %}
2 changes: 1 addition & 1 deletion buildbot/status/web/templates/change_macros.html
Expand Up @@ -22,7 +22,7 @@ <h3>Change {{ number }}</h3>
<td class="left">Revision</td>
<td>
{%- if revlink -%}<a href="{{ revlink }}">{{ rev|e }}</a>
{%- else -%}{{ rev|e }}
{%- else -%}{{ rev|revlink }}
{%- endif -%}
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion buildbot/status/web/templates/change_sources.html
Expand Up @@ -9,7 +9,7 @@ <h1>Changesources</h1>
{% if sources %}
<ol>
{% for s in sources -%}
<li class={{ loop.cycle('alt', '') }}>{{ s.describe() }}</li>
<li class="{{ loop.cycle('alt', '') }}">{{ s.describe() }}</li>
{% endfor -%}
</ol>
{% else %}
Expand Down
4 changes: 2 additions & 2 deletions buildbot/status/web/templates/console.html
Expand Up @@ -178,8 +178,8 @@ <h1>Console View</h1>
<tr>
<td class='DevRev {{ alt }}' width="1%">
{% if r.link %}<a href="{{ r.link }}">{{ r.id|shortrev }}</a>
{% else %}{{ r.id|shortrev }}
{% endif %}
{%- else %}{{ r.id|shortrev }}
{%- endif %}
</td>
<td class='DevName {{ alt }}' width="1%">
{{ r.who|user }}
Expand Down
27 changes: 27 additions & 0 deletions buildbot/status/web/templates/revmacros.html
@@ -0,0 +1,27 @@
{# both macro pairs must have the same signature #}

{% macro id_replace(rev, url) -%}
<span class="revision"><a href="{{ url }}">r{{ rev }}</span>
{%- endmacro %}

{% macro shorten_replace(short, rev, url) -%}
<div class="revision">
<div class="short" title="{{ rev }}">
<a href="{{ url }}">r{{ short }}</a>
</div>
<div class="full">
<a href="{{ url }}">r{{ rev }}</a>
</div>
</div>
{% endmacro %}

{% macro id(rev, url) -%}
<span class="revision">r{{ rev }}</span>
{%- endmacro %}

{% macro shorten(short, rev, url) -%}
<div class="revision">
<div class="short" title="{{ rev }}">r{{ short }}</div>
<div class="full">r{{ rev }}</div>
</div>
{% endmacro %}

0 comments on commit dee5b49

Please sign in to comment.