Improve outdated messages

This commit is contained in:
rubenwardy 2021-01-30 16:48:11 +00:00
parent 36dc51ef4a
commit 3b213889ca
3 changed files with 23 additions and 17 deletions

@ -973,3 +973,21 @@ class PackageUpdateConfig(db.Model):
def set_outdated(self): def set_outdated(self):
self.outdated_at = datetime.datetime.utcnow() self.outdated_at = datetime.datetime.utcnow()
def get_message(self):
if self.trigger == PackageUpdateTrigger.COMMIT:
msg = "New commit {} found on the Git repo.".format(self.last_commit[0:5])
else:
msg = "New tag {} found on the Git repo.".format(self.last_tag)
last_release = self.package.releases.first()
if last_release and last_release.commit_hash:
msg += " The last release was commit {}".format(last_release.commit_hash[0:5])
return msg
def get_create_release_url(self):
title = self.last_tag or self.outdated_at.strftime("%Y-%m-%d")
ref = self.last_tag or self.last_commit
return self.package.getCreateReleaseURL(title=title, ref=ref)

@ -22,12 +22,8 @@
{% set action = "Make release" if config.make_release else "Notification" %} {% set action = "Make release" if config.make_release else "Notification" %}
{{ _("On %(trigger)s, do %(action)s", trigger=config.trigger.value, action=action) }} {{ _("On %(trigger)s, do %(action)s", trigger=config.trigger.value, action=action) }}
{% else %} {% else %}
{% if config.trigger == config.trigger.TAG and config.last_tag %} {{ config.get_message() }}<br />
{{ _("New tag: %(tag)s", tag=config.last_tag) }} <span class="text-muted">
{% else %}
{{ _("Git repo has commit %(ref)s", ref=config.last_commit[0:5]) }}
{% endif %}
<span class="text-muted ml-3">
{{ config.outdated_at | datetime }} {{ config.outdated_at | datetime }}
</span> </span>
{% endif %} {% endif %}
@ -35,10 +31,8 @@
<div class="col-sm-auto"> <div class="col-sm-auto">
{% if not show_config %} {% if not show_config %}
{% set release_title = config.last_tag or (config.outdated_at | isodate) %}
{% if package.checkPerm(current_player, "MAKE_RELEASE") %} {% if package.checkPerm(current_player, "MAKE_RELEASE") %}
<a class="btn btn-sm btn-primary mr-2" <a class="btn btn-sm btn-primary mr-2" href="{{ config.get_create_release_url() }}">
href="{{ package.getCreateReleaseURL(title=release_title, ref=config.last_tag or config.last_commit) }}">
<i class="fas fa-plus mr-1"></i> <i class="fas fa-plus mr-1"></i>
{{ _("Release") }} {{ _("Release") }}
</a> </a>

@ -181,20 +181,14 @@
<b>Package may be outdated</b> <b>Package may be outdated</b>
</p> </p>
<p class="mt-0 my-1"> <p class="mt-0 my-1">
{% if config.trigger == config.trigger.TAG and config.last_tag %} {{ config.get_message() }}
{{ _("New tag: %(tag)s.", tag=config.last_tag) }}
{% else %}
{{ _("Git repo has commit %(ref)s.", ref=config.last_commit[0:5]) }}
{% endif %}
</p> </p>
<p class="mt-0 my-1" style="font-size: 80%; opacity: 85%;"> <p class="mt-0 my-1" style="font-size: 80%; opacity: 85%;">
<i class="fas fa-lock mr-1"></i> <i class="fas fa-lock mr-1"></i>
{{ _("Only visible to the author and Editors.") }} {{ _("Only visible to the author and Editors.") }}
</p> </p>
<div class="btn-group btn-group-sm my-0"> <div class="btn-group btn-group-sm my-0">
{% set release_title = config.last_tag or (config.outdated_at | isodate) %} <a class="btn btn-warning" href="{{ config.get_create_release_url() }}">
<a class="btn btn-warning"
href="{{ package.getCreateReleaseURL(title=release_title, ref=config.last_tag or config.last_commit) }}">
<i class="fas fa-plus mr-1"></i> <i class="fas fa-plus mr-1"></i>
{{ _("Release") }} {{ _("Release") }}
</a> </a>