Improve logic for generating changelog links for upgrade package diffs

This commit is contained in:
Lance Edgar 2017-08-13 16:30:31 -05:00
parent 55f96c4730
commit 852bafdfa0

View file

@ -217,19 +217,36 @@ class UpgradeView(MasterView):
except: except:
return "(not available for this upgrade)" 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): def render_diff_field(self, field, diff):
if field == 'rattail': old_version = diff.old_value(field)
# TODO: use changelog from latest docs *unless* running from src new_version = diff.new_value(field)
# url = 'https://rattailproject.org/buildbot/docs/rattail/changelog.html' url = self.get_changelog_url(field, old_version, new_version)
url = 'https://rattailproject.org/trac/log/rattail/?rev={}&stop_rev={}&limit=100'.format( if url:
diff.new_value(field), diff.old_value(field)) return self.changelog_link(field, url)
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')
return field return field
def render_diff_value(self, field, value): def render_diff_value(self, field, value):