From: Michael Ellerman Date: Tue, 27 Aug 2019 06:13:13 +0000 (+1000) Subject: models: Add commit_url_format to Project X-Git-Tag: v2.2.0-rc1~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f94bb4eb3693d581c0658eba6ab4aa7723eca955;p=thirdparty%2Fpatchwork.git models: Add commit_url_format to Project Add a new field to Project, commit_url_format, which specifies a format string that can be used to generate a link to a particular commit for a project. This is used in the display of a patch, to render the patch's commit as a clickable link back to the commit on the SCM website. Signed-off-by: Michael Ellerman Signed-off-by: Daniel Axtens --- diff --git a/docs/api/schemas/latest/patchwork.yaml b/docs/api/schemas/latest/patchwork.yaml index 394655de..45a61180 100644 --- a/docs/api/schemas/latest/patchwork.yaml +++ b/docs/api/schemas/latest/patchwork.yaml @@ -1893,6 +1893,9 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string Series: type: object properties: @@ -2217,6 +2220,10 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string + readOnly: true SeriesEmbedded: type: object properties: diff --git a/docs/api/schemas/patchwork.j2 b/docs/api/schemas/patchwork.j2 index 55e4c3b5..843981f8 100644 --- a/docs/api/schemas/patchwork.j2 +++ b/docs/api/schemas/patchwork.j2 @@ -1917,6 +1917,9 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string {% endif %} Series: type: object @@ -2253,6 +2256,10 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string + readOnly: true {% endif %} SeriesEmbedded: type: object diff --git a/docs/api/schemas/v1.2/patchwork.yaml b/docs/api/schemas/v1.2/patchwork.yaml index ab351e97..3a96aa3a 100644 --- a/docs/api/schemas/v1.2/patchwork.yaml +++ b/docs/api/schemas/v1.2/patchwork.yaml @@ -1893,6 +1893,9 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string Series: type: object properties: @@ -2217,6 +2220,10 @@ components: description: > URL format for the list archive's Message-ID redirector. {} will be replaced by the Message-ID. + commit_url_format: + title: Web SCM URL format for a particular commit + type: string + readOnly: true SeriesEmbedded: type: object properties: diff --git a/patchwork/api/embedded.py b/patchwork/api/embedded.py index 968cb7f9..de4f3116 100644 --- a/patchwork/api/embedded.py +++ b/patchwork/api/embedded.py @@ -163,13 +163,15 @@ class ProjectSerializer(SerializedRelatedField): model = models.Project fields = ('id', 'url', 'name', 'link_name', 'list_id', 'list_email', 'web_url', 'scm_url', 'webscm_url', - 'list_archive_url', 'list_archive_url_format') + 'list_archive_url', 'list_archive_url_format', + 'commit_url_format') read_only_fields = fields extra_kwargs = { 'url': {'view_name': 'api-project-detail'}, } versioned_fields = { - '1.2': ('list_archive_url', 'list_archive_url_format'), + '1.2': ('list_archive_url', 'list_archive_url_format', + 'commit_url_format'), } diff --git a/patchwork/api/project.py b/patchwork/api/project.py index 62a8c3e7..294d90b5 100644 --- a/patchwork/api/project.py +++ b/patchwork/api/project.py @@ -27,12 +27,13 @@ class ProjectSerializer(BaseHyperlinkedModelSerializer): fields = ('id', 'url', 'name', 'link_name', 'list_id', 'list_email', 'web_url', 'scm_url', 'webscm_url', 'maintainers', 'subject_match', 'list_archive_url', - 'list_archive_url_format') + 'list_archive_url_format', 'commit_url_format') read_only_fields = ('name', 'link_name', 'list_id', 'list_email', 'maintainers', 'subject_match') versioned_fields = { '1.1': ('subject_match', ), - '1.2': ('list_archive_url', 'list_archive_url_format'), + '1.2': ('list_archive_url', 'list_archive_url_format', + 'commit_url_format'), } extra_kwargs = { 'url': {'view_name': 'api-project-detail'}, @@ -71,7 +72,7 @@ class ProjectList(ProjectMixin, ListAPIView): search_fields = ('link_name', 'list_id', 'list_email', 'web_url', 'scm_url', 'webscm_url', 'list_archive_url', - 'list_archive_url_format') + 'list_archive_url_format', 'commit_url_format') ordering_fields = ('id', 'name', 'link_name', 'list_id') ordering = 'id' diff --git a/patchwork/fixtures/default_projects.xml b/patchwork/fixtures/default_projects.xml index a0877d98..e6b26bba 100644 --- a/patchwork/fixtures/default_projects.xml +++ b/patchwork/fixtures/default_projects.xml @@ -7,5 +7,6 @@ patchwork@lists.ozlabs.org https://lists.ozlabs.org/pipermail/patchwork/ http://mid.mail-archive.com/{} + https://github.com/torvalds/linux/commit/{} diff --git a/patchwork/migrations/0036_project_commit_url_format.py b/patchwork/migrations/0036_project_commit_url_format.py new file mode 100644 index 00000000..ab296d2c --- /dev/null +++ b/patchwork/migrations/0036_project_commit_url_format.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.22 on 2019-08-23 17:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0035_project_list_archive_url_format'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='commit_url_format', + field=models.CharField(blank=True, help_text=b'URL format for a particular commit. {} will be replaced by the commit SHA.', max_length=2000), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index 4d233960..32d1b3c2 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -82,6 +82,11 @@ class Project(models.Model): max_length=2000, blank=True, help_text="URL format for the list archive's Message-ID redirector. " "{} will be replaced by the Message-ID.") + commit_url_format = models.CharField( + max_length=2000, + blank=True, + help_text='URL format for a particular commit. ' + '{} will be replaced by the commit SHA.') # configuration options diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index 9cebbbeb..e79dd924 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -49,7 +49,7 @@ function toggle_div(link_id, headers_id) {% if submission.commit_ref %} Commit - {{ submission.commit_ref }} + {{ submission|patch_commit_display }} {% endif %} {% if submission.delegate %} diff --git a/patchwork/templatetags/patch.py b/patchwork/templatetags/patch.py index 757f873b..d2537baa 100644 --- a/patchwork/templatetags/patch.py +++ b/patchwork/templatetags/patch.py @@ -66,3 +66,15 @@ def patch_checks(patch): @stringfilter def msgid(value): return escape(value.strip('<>')) + + +@register.filter(name='patch_commit_display') +def patch_commit_display(patch): + commit = patch.commit_ref + fmt = patch.project.commit_url_format + + if not fmt: + return escape(commit) + + return mark_safe('%s' % (escape(fmt.format(commit)), + escape(commit)))