diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2019-08-27 16:13:13 +1000 |
---|---|---|
committer | Daniel Axtens <dja@axtens.net> | 2019-08-30 17:39:06 +1000 |
commit | f94bb4eb3693d581c0658eba6ab4aa7723eca955 (patch) | |
tree | 22dae6af1ae2ca8da03898ddf9dc98a853efac30 | |
parent | dde885c6c2f5e03388630320bc03a4cbe1040c64 (diff) | |
download | patchwork-f94bb4eb3693d581c0658eba6ab4aa7723eca955.tar patchwork-f94bb4eb3693d581c0658eba6ab4aa7723eca955.tar.gz |
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 <mpe@ellerman.id.au>
Signed-off-by: Daniel Axtens <dja@axtens.net>
-rw-r--r-- | docs/api/schemas/latest/patchwork.yaml | 7 | ||||
-rw-r--r-- | docs/api/schemas/patchwork.j2 | 7 | ||||
-rw-r--r-- | docs/api/schemas/v1.2/patchwork.yaml | 7 | ||||
-rw-r--r-- | patchwork/api/embedded.py | 6 | ||||
-rw-r--r-- | patchwork/api/project.py | 7 | ||||
-rw-r--r-- | patchwork/fixtures/default_projects.xml | 1 | ||||
-rw-r--r-- | patchwork/migrations/0036_project_commit_url_format.py | 20 | ||||
-rw-r--r-- | patchwork/models.py | 5 | ||||
-rw-r--r-- | patchwork/templates/patchwork/submission.html | 2 | ||||
-rw-r--r-- | patchwork/templatetags/patch.py | 12 |
10 files changed, 68 insertions, 6 deletions
diff --git a/docs/api/schemas/latest/patchwork.yaml b/docs/api/schemas/latest/patchwork.yaml index 394655d..45a6118 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 55e4c3b..843981f 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 ab351e9..3a96aa3 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 968cb7f..de4f311 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 62a8c3e..294d90b 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 a0877d9..e6b26bb 100644 --- a/patchwork/fixtures/default_projects.xml +++ b/patchwork/fixtures/default_projects.xml @@ -7,5 +7,6 @@ <field type="CharField" name="listemail">patchwork@lists.ozlabs.org</field> <field type="CharField" name="list_archive_url">https://lists.ozlabs.org/pipermail/patchwork/</field> <field type="CharField" name="list_archive_url_format">http://mid.mail-archive.com/{}</field> + <field type="CharField" name="commit_url_format">https://github.com/torvalds/linux/commit/{}</field> </object> </django-objects> 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 0000000..ab296d2 --- /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 4d23396..32d1b3c 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 9cebbbe..e79dd92 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 %} <tr> <th>Commit</th> - <td>{{ submission.commit_ref }}</td> + <td>{{ submission|patch_commit_display }}</td> </tr> {% endif %} {% if submission.delegate %} diff --git a/patchwork/templatetags/patch.py b/patchwork/templatetags/patch.py index 757f873..d2537ba 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('<a href="%s">%s</a>' % (escape(fmt.format(commit)), + escape(commit))) |