diff --git a/tailbone/views/upgrades.py b/tailbone/views/upgrades.py index c1423678..9fbc6ac5 100644 --- a/tailbone/views/upgrades.py +++ b/tailbone/views/upgrades.py @@ -217,19 +217,36 @@ class UpgradeView(MasterView): except: return "(not available for this upgrade)" + def changelog_link(self, project, url): + return tags.link_to(project, url, target='_blank') + + commit_hash_pattern = re.compile(r'^.{40}$') + + def get_changelog_url(self, project, old_version, new_version): + projects = { + 'rattail': 'rattail', + 'Tailbone': 'tailbone', + } + if project not in projects: + return + if self.commit_hash_pattern.match(new_version): + if new_version == old_version: + return 'https://rattailproject.org/trac/log/{}/?rev={}&limit=100'.format( + projects[project], new_version) + else: + return 'https://rattailproject.org/trac/log/{}/?rev={}&stop_rev={}&limit=100'.format( + projects[project], new_version, old_version) + else: + # TODO: use changelog from latest docs + # return 'https://rattailproject.org/buildbot/docs/{}/changelog.html'.format(projects[project]) + pass + def render_diff_field(self, field, diff): - if field == 'rattail': - # TODO: use changelog from latest docs *unless* running from src - # url = 'https://rattailproject.org/buildbot/docs/rattail/changelog.html' - url = 'https://rattailproject.org/trac/log/rattail/?rev={}&stop_rev={}&limit=100'.format( - diff.new_value(field), diff.old_value(field)) - return tags.link_to(field, url, target='_blank') - if field == 'Tailbone': - # TODO: use changelog from latest docs *unless* running from src - # url = 'https://rattailproject.org/buildbot/docs/tailbone/changelog.html' - url = 'https://rattailproject.org/trac/log/tailbone/?rev={}&stop_rev={}&limit=100'.format( - diff.new_value(field), diff.old_value(field)) - return tags.link_to(field, url, target='_blank') + old_version = diff.old_value(field) + new_version = diff.new_value(field) + url = self.get_changelog_url(field, old_version, new_version) + if url: + return self.changelog_link(field, url) return field def render_diff_value(self, field, value):