aboutsummaryrefslogtreecommitdiffstats
path: root/layerindex/migrations/0012_layeritem_vcs_commit_url.py
diff options
context:
space:
mode:
Diffstat (limited to 'layerindex/migrations/0012_layeritem_vcs_commit_url.py')
-rw-r--r--layerindex/migrations/0012_layeritem_vcs_commit_url.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/layerindex/migrations/0012_layeritem_vcs_commit_url.py b/layerindex/migrations/0012_layeritem_vcs_commit_url.py
new file mode 100644
index 0000000000..1836abac01
--- /dev/null
+++ b/layerindex/migrations/0012_layeritem_vcs_commit_url.py
@@ -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),
+ ]