Implement layer web repo commit URL

The Recipe Reporting System needs to be able to provide links to commits
in the web interface for the repository, but we can only do this if we
have a custom template URL just like we do for file/tree links, since
it's different for different git web interfaces. Add support in all the
various places for such a URL and make use of it in the RRS.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-04-03 23:19:46 +12:00
parent c78fbde643
commit a6aaa5c8ef
8 changed files with 81 additions and 17 deletions

View File

@ -54,7 +54,7 @@ class EditLayerForm(forms.ModelForm):
class Meta:
model = LayerItem
fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'usage_url', 'mailing_list_url')
fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'vcs_web_commit_url', 'usage_url', 'mailing_list_url')
def __init__(self, user, layerbranch, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
@ -130,6 +130,13 @@ class EditLayerForm(forms.ModelForm):
val(url)
return url
def clean_vcs_web_commit_url(self):
url = self.cleaned_data['vcs_web_commit_url'].strip()
if url:
val = URLValidator()
val(url)
return url
def clean_usage_url(self):
usage = self.cleaned_data['usage_url'].strip()
if usage.startswith('http'):

View File

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def set_commit_url(apps, schema_editor):
import re
LayerItem = apps.get_model('layerindex', 'LayerItem')
for layer in LayerItem.objects.all():
if layer.vcs_web_url:
if 'git.yoctoproject.org' in layer.vcs_web_url or 'git.openembedded.org' in layer.vcs_web_url or 'cgit.' in layer.vcs_web_url:
layer.vcs_web_commit_url = layer.vcs_web_url + '/commit/?id=%hash%'
elif 'github.com/' in layer.vcs_web_url:
layer.vcs_web_commit_url = layer.vcs_web_url + '/commit/%hash%'
elif 'bitbucket.org/' in layer.vcs_web_url:
layer.vcs_web_commit_url = layer.vcs_web_url + '/commits/%hash%'
elif 'gitlab.' in layer.vcs_web_url:
layer.vcs_web_commit_url = layer.vcs_web_url + '/commit/%hash%'
elif 'a=tree;' in layer.vcs_web_tree_base_url:
layer.vcs_web_commit_url = re.sub(r'\.git.*', '.git;a=commit;h=%hash%', layer.vcs_web_url)
layer.save()
class Migration(migrations.Migration):
dependencies = [
('layerindex', '0011_source'),
]
operations = [
migrations.AddField(
model_name='layeritem',
name='vcs_web_commit_url',
field=models.CharField(verbose_name='Repository web interface commit URL', max_length=255, blank=True, help_text='Base URL for the web interface for viewing a single commit within the repository, if any'),
),
migrations.RunPython(set_commit_url, reverse_code=migrations.RunPython.noop),
]

View File

@ -104,6 +104,7 @@ class LayerItem(models.Model):
vcs_web_url = models.URLField('Repository web interface URL', blank=True, help_text='URL of the web interface for browsing the repository, if any')
vcs_web_tree_base_url = models.CharField('Repository web interface tree base URL', max_length=255, blank=True, help_text='Base URL for the web interface for browsing directories within the repository, if any')
vcs_web_file_base_url = models.CharField('Repository web interface file base URL', max_length=255, blank=True, help_text='Base URL for the web interface for viewing files (blobs) within the repository, if any')
vcs_web_commit_url = models.CharField('Repository web interface commit URL', max_length=255, blank=True, help_text='Base URL for the web interface for viewing a single commit within the repository, if any')
usage_url = models.CharField('Usage web page URL', max_length=255, blank=True, help_text='URL of a web page with more information about the layer and how to use it, if any (or path to file within repository)')
mailing_list_url = models.URLField('Mailing list URL', blank=True, help_text='URL of the info page for a mailing list for discussing the layer, if any')
index_preference = models.IntegerField('Preference', default=0, help_text='Number used to find preferred recipes in recipe search results (higher number is greater preference)')
@ -242,6 +243,16 @@ class LayerBranch(models.Model):
def file_url(self, path = ''):
return self._handle_url_path(self.layer.vcs_web_file_base_url, path)
def commit_url(self, commit_hash):
url = self.layer.vcs_web_commit_url
url = url.replace('%hash%', commit_hash)
if self.actual_branch:
branchname = self.actual_branch
else:
branchname = self.branch.name
url = url.replace('%branch%', branchname)
return url
def test_tree_url(self):
return self.tree_url('conf')

View File

@ -35,29 +35,27 @@ def set_vcs_fields(layer, repoval):
layer.vcs_web_url = 'http://cgit.openembedded.org/' + reponame
layer.vcs_web_tree_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_file_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_commit_url = 'http://cgit.openembedded.org/' + reponame + '/commit/?id=%hash%'
elif 'git.yoctoproject.org/' in repoval:
reponame = re.sub('^.*/', '', repoval)
layer.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
layer.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_file_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_commit_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/commit/?id=%hash%'
elif 'github.com/' in repoval:
reponame = re.sub('^.*github.com/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://github.com/' + reponame
layer.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
layer.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
elif 'gitorious.org/' in repoval:
reponame = re.sub('^.*gitorious.org/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://gitorious.org/' + reponame
layer.vcs_web_tree_base_url = 'http://gitorious.org/' + reponame + '/trees/%branch%/'
layer.vcs_web_file_base_url = 'http://gitorious.org/' + reponame + '/blobs/%branch%/'
layer.vcs_web_commit_url = 'http://github.com/' + reponame + '/commit/%hash%'
elif 'bitbucket.org/' in repoval:
reponame = re.sub('^.*bitbucket.org/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://bitbucket.org/' + reponame
layer.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
layer.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
layer.vcs_web_commit_url = 'http://bitbucket.org/' + reponame + '/commits/%hash%'
def readme_extract(readmefn):

View File

@ -99,34 +99,33 @@ def main():
layer.vcs_web_url = 'http://cgit.openembedded.org/' + reponame
layer.vcs_web_tree_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_file_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_commit_url = 'http://cgit.openembedded.org/' + reponame + '/commit/?id=%hash%'
elif 'git.yoctoproject.org/' in repoval:
reponame = re.sub('^.*/', '', repoval)
layer.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
layer.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_file_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
layer.vcs_web_commit_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/commit/?id=%hash%'
elif 'github.com/' in repoval:
reponame = re.sub('^.*github.com/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://github.com/' + reponame
layer.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
layer.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
elif 'gitorious.org/' in repoval:
reponame = re.sub('^.*gitorious.org/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://gitorious.org/' + reponame
layer.vcs_web_tree_base_url = 'http://gitorious.org/' + reponame + '/trees/%branch%/'
layer.vcs_web_file_base_url = 'http://gitorious.org/' + reponame + '/blobs/%branch%/'
layer.vcs_web_commit_url = 'http://github.com/' + reponame + '/commit/%hash%'
elif 'bitbucket.org/' in repoval:
reponame = re.sub('^.*bitbucket.org/', '', repoval)
reponame = re.sub('.git$', '', reponame)
layer.vcs_web_url = 'http://bitbucket.org/' + reponame
layer.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
layer.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
layer.vcs_web_commit_url = 'http://bitbucket.org/' + reponame + '/commits/%hash%'
elif '.git' in repoval:
res = link_re.match(fields[5].strip())
layer.vcs_web_url = res.groups(1)[0]
layer.vcs_web_tree_base_url = re.sub(r'\.git.*', '.git;a=tree;f=%path%;hb=%branch%', layer.vcs_web_url)
layer.vcs_web_file_base_url = re.sub(r'\.git.*', '.git;a=blob;f=%path%;hb=%branch%', layer.vcs_web_url)
layer.vcs_web_file_base_url = re.sub(r'\.git.*', '.git;a=commit;h=%hash%', layer.vcs_web_url)
layer.save()
layerbranch = LayerBranch()

View File

@ -401,8 +401,7 @@ class RecipeUpgrade(models.Model):
return self.sha1[0:6]
def commit_url(self):
web_interface_url = self.recipe.layerbranch.layer.vcs_web_url
return web_interface_url + "/commit/?id=" + self.sha1
return self.recipe.layerbranch.commit_url(self.sha1)
def __str__(self):
return '%s: (%s, %s)' % (self.recipe.pn, self.version,

View File

@ -641,8 +641,7 @@ def _get_recipe_upgrade_detail(maintplan, recipe_upgrade):
commit_date = recipe_upgrade.commit_date.date().isoformat()
commit = recipe_upgrade.sha1[:10]
commit_url = recipe_upgrade.recipe.layerbranch.layer.vcs_web_url + \
'/commit/?id=' + recipe_upgrade.sha1
commit_url = recipe_upgrade.recipe.layerbranch.commit_url(recipe_upgrade.sha1)
rud = RecipeUpgradeDetail(recipe_upgrade.title, recipe_upgrade.version, \
maintplan.name, release_name, milestone_name, commit_date, maintainer_name, \

View File

@ -196,6 +196,7 @@
this.vcs_web_url = 'http://cgit.openembedded.org/' + reponame
this.vcs_web_tree_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_file_base_url = 'http://cgit.openembedded.org/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_commit_url = 'http://cgit.openembedded.org/' + reponame + '/commit/?id=%hash%'
this.vcs_web_type = 'cgit'
}
else if( repoval.indexOf('git.yoctoproject.org/') > -1 ) {
@ -203,6 +204,7 @@
this.vcs_web_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame
this.vcs_web_tree_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_file_base_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/tree/%path%?h=%branch%'
this.vcs_web_commit_url = 'http://git.yoctoproject.org/cgit/cgit.cgi/' + reponame + '/commit/?id=%hash%'
this.vcs_web_type = 'cgit'
}
else if( repoval.indexOf('github.com/') > -1 ) {
@ -211,6 +213,7 @@
this.vcs_web_url = 'http://github.com/' + reponame
this.vcs_web_tree_base_url = 'http://github.com/' + reponame + '/tree/%branch%/'
this.vcs_web_file_base_url = 'http://github.com/' + reponame + '/blob/%branch%/'
this.vcs_web_commit_url = 'http://github.com/' + reponame + '/commit/%hash%/'
this.vcs_web_type = '(custom)'
}
else if( repoval.indexOf('bitbucket.org/') > -1 ) {
@ -219,12 +222,14 @@
this.vcs_web_url = 'http://bitbucket.org/' + reponame
this.vcs_web_tree_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
this.vcs_web_file_base_url = 'http://bitbucket.org/' + reponame + '/src/%branch%/%path%?at=%branch%'
this.vcs_web_commit_url = 'http://bitbucket.org/' + reponame + '/commits/%hash%'
this.vcs_web_type = '(custom)'
}
else {
this.vcs_web_url = ''
this.vcs_web_tree_base_url = ''
this.vcs_web_file_base_url = ''
this.vcs_web_commit_url = ''
this.vcs_web_type = '(custom)'
}
};
@ -249,10 +254,12 @@
readonly = $('#idx_vcs_web_type').prop('disabled')
$('#id_vcs_web_tree_base_url').prop('readonly', readonly)
$('#id_vcs_web_file_base_url').prop('readonly', readonly)
$('#id_vcs_web_commit_url').prop('readonly', readonly)
}
else {
$('#id_vcs_web_tree_base_url').prop('readonly', true)
$('#id_vcs_web_file_base_url').prop('readonly', true)
$('#id_vcs_web_commit_url').prop('readonly', true)
vcs_web_url = $('#id_vcs_web_url').val()
if (vcs_web_url) {
if (vcs_web_url.endsWith('/')) {
@ -261,14 +268,17 @@
if (type == 'cgit') {
$('#id_vcs_web_tree_base_url').val('readonly', true)
$('#id_vcs_web_file_base_url').prop('readonly', true)
$('#id_vcs_web_commit_url').prop('readonly', true)
if (e) {
$('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
$('#id_vcs_web_file_base_url').val(vcs_web_url + '/tree/%path%?h=%branch%')
$('#id_vcs_web_commit_url').val(vcs_web_url + '/commit/id=%hash%')
}
}
else if (type == 'gitweb') {
$('#id_vcs_web_tree_base_url').val('readonly', true)
$('#id_vcs_web_file_base_url').prop('readonly', true)
$('#id_vcs_web_commit_url').prop('readonly', true)
if (e) {
spliturl = vcs_web_url.split('?')
if (spliturl.length > 1) {
@ -290,14 +300,17 @@
}
$('#id_vcs_web_tree_base_url').val(vcs_web_url + 'a=tree;f=%path%;hb=refs/heads/%branch%')
$('#id_vcs_web_file_base_url').val(vcs_web_url + 'a=blob;f=%path%;hb=refs/heads/%branch%')
$('#id_vcs_web_commit_url').val(vcs_web_url + 'a=commit;h=%hash%')
}
}
else if (type == 'gitlab') {
$('#id_vcs_web_tree_base_url').val('readonly', true)
$('#id_vcs_web_file_base_url').prop('readonly', true)
$('#id_vcs_web_commit_url').prop('readonly', true)
if (e) {
$('#id_vcs_web_tree_base_url').val(vcs_web_url + '/tree/%branch%/%path%')
$('#id_vcs_web_file_base_url').val(vcs_web_url + '/blob/%branch%/%path%')
$('#id_vcs_web_commit_url').val(vcs_web_url + '/commit/%hash%')
}
}
}
@ -312,6 +325,7 @@
$('#id_vcs_web_url').val(awf.vcs_web_url)
$('#id_vcs_web_tree_base_url').val(awf.vcs_web_tree_base_url)
$('#id_vcs_web_file_base_url').val(awf.vcs_web_file_base_url)
$('#id_vcs_web_commit_url').val(awf.vcs_web_commit_url)
$('#idx_vcs_web_type').val(awf.vcs_web_type)
}
$('#id_vcs_web_url').prop('readonly', true);