From patchwork Tue Aug 27 06:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 1153588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Hds75j1Qz9s7T for ; Tue, 27 Aug 2019 16:15:23 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46Hds70G1fzDqn1 for ; Tue, 27 Aug 2019 16:15:23 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46Hdpk3kXxzDqX0 for ; Tue, 27 Aug 2019 16:13:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au Received: by ozlabs.org (Postfix, from userid 1034) id 46Hdpk2wYzz9sBF; Tue, 27 Aug 2019 16:13:18 +1000 (AEST) From: Michael Ellerman To: patchwork@lists.ozlabs.org Subject: [PATCH v2] models: Add commit_url_format to Project Date: Tue, 27 Aug 2019 16:13:13 +1000 Message-Id: <20190827061313.9202-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- docs/api/schemas/latest/patchwork.yaml | 7 +++++++ docs/api/schemas/patchwork.j2 | 7 +++++++ docs/api/schemas/v1.2/patchwork.yaml | 7 +++++++ patchwork/api/embedded.py | 6 ++++-- patchwork/api/project.py | 7 ++++--- patchwork/fixtures/default_projects.xml | 1 + .../0036_project_commit_url_format.py | 20 +++++++++++++++++++ patchwork/models.py | 5 +++++ patchwork/templates/patchwork/submission.html | 2 +- patchwork/templatetags/patch.py | 12 +++++++++++ 10 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 patchwork/migrations/0036_project_commit_url_format.py v2: Rebase on top of list archive changes. Added to the default projects fixture. Reworked the escaping to be more paranoid, it now escapes the result of applying the format string. Meaning even an admin shouldn't be able to do anything other than making the link point somewhere weird. 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 @@ openapi: '3.0.0' 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 @@ openapi: '3.0.0' 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 @@ openapi: '3.0.0' 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 @@ openapi: '3.0.0' 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 @@ openapi: '3.0.0' 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 @@ openapi: '3.0.0' 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 @@ from patchwork import models 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 @@ from patchwork.models import Project 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 @@ from patchwork.models import Project 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 @@ 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 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 @@ from patchwork.hasher import hash_diff 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 %} 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 757f873..d2537ba 100644 --- a/patchwork/templatetags/patch.py +++ b/patchwork/templatetags/patch.py @@ -66,3 +66,15 @@ register = template.Library() @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)))