]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: Add commit_url_format to Project
authorMichael Ellerman <mpe@ellerman.id.au>
Tue, 27 Aug 2019 06:13:13 +0000 (16:13 +1000)
committerDaniel Axtens <dja@axtens.net>
Fri, 30 Aug 2019 07:39:06 +0000 (17:39 +1000)
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>
docs/api/schemas/latest/patchwork.yaml
docs/api/schemas/patchwork.j2
docs/api/schemas/v1.2/patchwork.yaml
patchwork/api/embedded.py
patchwork/api/project.py
patchwork/fixtures/default_projects.xml
patchwork/migrations/0036_project_commit_url_format.py [new file with mode: 0644]
patchwork/models.py
patchwork/templates/patchwork/submission.html
patchwork/templatetags/patch.py

index 394655de46e7dd106ccfd4723d18a2f7a60a0d94..45a6118092059e6a9a267c69067de8b377cbafc9 100644 (file)
@@ -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:
index 55e4c3b50c38423a484266c5e12a015c6fa0c44c..843981f80cc18a2453f71314b7f1130e597da91c 100644 (file)
@@ -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
index ab351e972a6d2aa31f94e1c166255d7c2593e0d6..3a96aa3a4fbbd3098f5e22f1e8eddede7d8e63c3 100644 (file)
@@ -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:
index 968cb7f91f10565ffee5991e2f36f312fc598d05..de4f31165ee7c999697368da9db671535c229ee8 100644 (file)
@@ -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'),
             }
 
 
index 62a8c3e73efe330f6b09752320b090b2624ccc76..294d90b53ab3b74b3992a4b734fb1da779d10915 100644 (file)
@@ -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'
 
index a0877d986333bf300c869425048d527a137a43b9..e6b26bba4ad1e8efaed92c36f0cc31574c8b9cea 100644 (file)
@@ -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 (file)
index 0000000..ab296d2
--- /dev/null
@@ -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),
+        ),
+    ]
index 4d23396033cfa8dd24227ec6a046cd1f93755434..32d1b3c2adc5678144addf75d5245df6606744a3 100644 (file)
@@ -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
 
index 9cebbbeb89aaa34ad7ecd897ade3962f32302b7d..e79dd92497a4a6ea45de3286149eed777bbb02a3 100644 (file)
@@ -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 %}
index 757f873b6043b495a044810eb89527821eb9fd94..d2537baafc1974521e580422b89475d1840b602f 100644 (file)
@@ -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)))