[PATCH v2] docker: Specify GID for docker-compose-pg.yml too

2019-10-23 Thread Daniel Axtens
We just need to mirror the change in the MySQL/default
docker-compose.yml file.

Fixes: b4f4c8554c11 ("docker: Require GID also")
Signed-off-by: Daniel Axtens 

---

v2: an object lesson in why you should test before emailing
---
 docker-compose-pg.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git docker-compose-pg.yml docker-compose-pg.yml
index 7bb579c3279f..44c49fb6113d 100644
--- docker-compose-pg.yml
+++ docker-compose-pg.yml
@@ -13,6 +13,7 @@ services:
   dockerfile: ./tools/docker/Dockerfile
   args:
 - UID
+- GID
 depends_on:
   - db
 command: python3 manage.py runserver 0.0.0.0:8000
@@ -22,6 +23,7 @@ services:
   - "8000:8000"
 environment:
   - UID
+  - GID
   - PW_TEST_DB_HOST=db
   - PW_TEST_DB_PORT=5432
   - PW_TEST_DB_TYPE=postgres
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] docker: Specify GID for docker-compose-pg.yml too

2019-10-23 Thread Daniel Axtens
We just need to mirror the change in the MySQL/default
docker-compose.yml file.

Fixes: b4f4c8554c11 ("docker: Require GID also")
Signed-off-by: Daniel Axtens 
---
 docker-compose-pg.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git docker-compose-pg.yml docker-compose-pg.yml
index 7bb579c3279f..1cb76c255352 100644
--- docker-compose-pg.yml
+++ docker-compose-pg.yml
@@ -13,6 +13,7 @@ services:
   dockerfile: ./tools/docker/Dockerfile
   args:
 - UID
+- GID
 depends_on:
   - db
 command: python3 manage.py runserver 0.0.0.0:8000
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH v2] Python 3.8 support

2019-10-23 Thread Daniel Axtens
Applied to master, thanks.

Andrew Donnellan  writes:

> Enable Python 3.8 in our tests and list it as a supported version.
>
> Signed-off-by: Andrew Donnellan 
>
> ---
>
> v1->v2:
> - Add release note that I forgot to git add
> ---
>  README.rst  | 2 +-
>  releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml | 5 +
>  tools/docker/Dockerfile | 3 ++-
>  tox.ini | 2 +-
>  4 files changed, 9 insertions(+), 3 deletions(-)
>  create mode 100644 
> releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml
>
> diff --git a/README.rst b/README.rst
> index 01da41969168..074ded9a7db2 100644
> --- a/README.rst
> +++ b/README.rst
> @@ -41,7 +41,7 @@ of community projects.
>  Requirements
>  
>  
> -- Python (2.7, 3.5 - 3.7)
> +- Python (2.7, 3.5 - 3.8)
>  
>  - Django (1.11 - 2.2)
>  
> diff --git a/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml 
> b/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml
> new file mode 100644
> index ..935cfb91a260
> --- /dev/null
> +++ b/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml
> @@ -0,0 +1,5 @@
> +---
> +features:
> +  - |
> +`Python 3.8 `_ is 
> now
> +supported.
> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> index 61678134d418..5ef11203e850 100644
> --- a/tools/docker/Dockerfile
> +++ b/tools/docker/Dockerfile
> @@ -49,7 +49,8 @@ RUN curl -L 
> https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-instal
>  RUN pyenv latest install 2.7 && \
>  pyenv latest install 3.5 && \
>  pyenv latest install 3.6 && \
> -pyenv latest install 3.7
> +pyenv latest install 3.7 && \
> +pyenv latest install 3.8
>  RUN pyenv global $(pyenv versions --bare | tac)
>  
>  RUN pip install tox tox-pyenv
> diff --git a/tox.ini b/tox.ini
> index 617e73cdbee6..4267f47241b6 100644
> --- a/tox.ini
> +++ b/tox.ini
> @@ -1,6 +1,6 @@
>  [tox]
>  minversion = 2.0
> -envlist = pep8,docs,py27-django111,py{35,36,37}-django{111,20,21,22}
> +envlist = pep8,docs,py27-django111,py{35,36,37,38}-django{111,20,21,22}
>  skipsdist = True
>  
>  [testenv]
> -- 
> 2.20.1
>
> ___
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH v2 1/2] [PW3] tests: Fix escaping in bundle tests on Django 3.0

2019-10-23 Thread Andrew Donnellan
Django 3.0 switches to using Python 3's built-in HTML escaper, which
prefers to escape entities using hex rather than decimal.

Some of our tests check rendered HTML output against pre-escaped strings,
and fail because '' is now ''.

Fix this by using the escape function so we get consistent escaping no
matter which Django version..

Signed-off-by: Andrew Donnellan 
---
 patchwork/tests/test_bundles.py | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py
index 63f943c033d6..c5e7ee62f435 100644
--- a/patchwork/tests/test_bundles.py
+++ b/patchwork/tests/test_bundles.py
@@ -10,6 +10,7 @@ import unittest
 from django.conf import settings
 from django.test import TestCase
 from django.urls import reverse
+from django.utils.html import escape
 from django.utils.http import urlencode
 
 from patchwork.models import Bundle
@@ -548,8 +549,8 @@ class BundleAddFromListTest(BundleTestBase):
 'project_id': self.project.linkname}),
 params)
 
-self.assertContains(response, 'Patch %s already in bundle'
-% patch.name, count=1, status_code=200)
+expected = escape(f"Patch '{patch.name}' already in bundle")
+self.assertContains(response, expected, count=1, status_code=200)
 
 self.assertEqual(count, self.bundle.patches.count())
 
@@ -570,11 +571,12 @@ class BundleAddFromListTest(BundleTestBase):
 'project_id': self.project.linkname}),
 params)
 
-self.assertContains(response, 'Patch %s already in bundle'
-% patch.name, count=1, status_code=200)
-self.assertContains(response, 'Patch %s added to bundle'
-% self.patches[1].name, count=1,
+expected_already = escape(f"Patch '{patch.name}' already in bundle")
+expected_added = escape(
+f"Patch '{self.patches[1].name}' added to bundle")
+self.assertContains(response, expected_already, count=1,
 status_code=200)
+self.assertContains(response, expected_added, count=1, status_code=200)
 self.assertEqual(count + 1, self.bundle.patches.count())
 
 
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH v2 2/2] [PW3] Add Django 3.0 support

2019-10-23 Thread Andrew Donnellan
Now that we've dropped Python 2, we can get ready for Django 3.0, which is
still in beta.

Add Django 3.0b1 as a tox environment. Add a release note for Django 3.0
support, as it will be released by the time Patchwork 3.0 is out.

Closes: #311 ("Django 3.0 support")
Signed-off-by: Andrew Donnellan 

---

v1->v2:
- rebase on top of python 3.8 patch [github.com/ajdlinux/patchwork, django3 
branch]
- add release note as suggested by dja

Not adding upper bounds on the version numbers until 3.0 actually drops.

I'm considering this as closing the issue for Django 3.0 support, as now
that Django 3.0 is in beta it's unlikely to get further breaking changes
and we'll catch anything as we test it.
---
 releasenotes/notes/django-3-0-support-763b5c7b5aab0010.yaml | 5 +
 tox.ini | 5 -
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/django-3-0-support-763b5c7b5aab0010.yaml

diff --git a/releasenotes/notes/django-3-0-support-763b5c7b5aab0010.yaml 
b/releasenotes/notes/django-3-0-support-763b5c7b5aab0010.yaml
new file mode 100644
index ..a21c70540404
--- /dev/null
+++ b/releasenotes/notes/django-3-0-support-763b5c7b5aab0010.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+`Django 3.0 `_ is now
+supported. This requires Python 3.6 or higher.
diff --git a/tox.ini b/tox.ini
index 6be8141e7c66..693d02de3c40 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 minversion = 2.0
-envlist = pep8,docs,py{36,37,38}-django{20,21,22}
+envlist = pep8,docs,py{36,37,38}-django{20,21,22,30b1}
 skipsdist = True
 
 [testenv]
@@ -13,6 +13,9 @@ deps =
 django22: django>=2.2,<2.3
 django22: djangorestframework>=3.10,<3.11
 django22: django-filter>=2.1,<3.0
+django30b1: django==3.0b1
+django30b1: djangorestframework>=3.10
+django30b1: django-filter>=2.2
 setenv =
 DJANGO_SETTINGS_MODULE = patchwork.settings.dev
 PYTHONDONTWRITEBYTECODE = 1
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] travis, tox: only do coverage testing in py27

2019-10-23 Thread Daniel Axtens
Currently Travis calls `tox -e coverage` unconditionally. However,
the environment has py27 basepython, so all the runs only generate
py27 coverage!

Rather than try to untangle that, just run the coverage when run
in a py27 travis environment. This makes things faster for no
loss of coverage. It means that codecov has nothing to submit for
the py3x environments, but that's no real loss: it would otherwise
submit lots of duplicate data.

We could try to improve coverage by running coverage for 27 and 3x,
but given that 27 is going away, don't stress at this point.

Signed-off-by: Daniel Axtens 
---
 .travis.yml | 1 -
 tox.ini | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git .travis.yml .travis.yml
index 51746b2674ce..90ff36dfe52b 100644
--- .travis.yml
+++ .travis.yml
@@ -55,7 +55,6 @@ script:
   psql -c "SELECT VERSION(), CURRENT_USER, current_database()" -U 
$PW_TEST_DB_USER patchwork;
 fi
   - tox
-  - tox -e coverage
 
 after_success:
   - codecov
diff --git tox.ini tox.ini
index 617e73cdbee6..882c44a628eb 100644
--- tox.ini
+++ tox.ini
@@ -86,4 +86,4 @@ commands =
 
 [travis]
 python =
-2.7: py27, pep8
+2.7: py27, pep8, coverage
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH v2] Python 3.8 support

2019-10-23 Thread Andrew Donnellan
Enable Python 3.8 in our tests and list it as a supported version.

Signed-off-by: Andrew Donnellan 

---

v1->v2:
- Add release note that I forgot to git add
---
 README.rst  | 2 +-
 releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml | 5 +
 tools/docker/Dockerfile | 3 ++-
 tox.ini | 2 +-
 4 files changed, 9 insertions(+), 3 deletions(-)
 create mode 100644 releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml

diff --git a/README.rst b/README.rst
index 01da41969168..074ded9a7db2 100644
--- a/README.rst
+++ b/README.rst
@@ -41,7 +41,7 @@ of community projects.
 Requirements
 
 
-- Python (2.7, 3.5 - 3.7)
+- Python (2.7, 3.5 - 3.8)
 
 - Django (1.11 - 2.2)
 
diff --git a/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml 
b/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml
new file mode 100644
index ..935cfb91a260
--- /dev/null
+++ b/releasenotes/notes/python-3-8-support-59150fb6391f9b73.yaml
@@ -0,0 +1,5 @@
+---
+features:
+  - |
+`Python 3.8 `_ is now
+supported.
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index 61678134d418..5ef11203e850 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -49,7 +49,8 @@ RUN curl -L 
https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-instal
 RUN pyenv latest install 2.7 && \
 pyenv latest install 3.5 && \
 pyenv latest install 3.6 && \
-pyenv latest install 3.7
+pyenv latest install 3.7 && \
+pyenv latest install 3.8
 RUN pyenv global $(pyenv versions --bare | tac)
 
 RUN pip install tox tox-pyenv
diff --git a/tox.ini b/tox.ini
index 617e73cdbee6..4267f47241b6 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 minversion = 2.0
-envlist = pep8,docs,py27-django111,py{35,36,37}-django{111,20,21,22}
+envlist = pep8,docs,py27-django111,py{35,36,37,38}-django{111,20,21,22}
 skipsdist = True
 
 [testenv]
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] Python 3.8 support

2019-10-23 Thread Andrew Donnellan
Enable Python 3.8 in our tests and list it as a supported version.

Signed-off-by: Andrew Donnellan 
---
 README.rst  | 2 +-
 tools/docker/Dockerfile | 3 ++-
 tox.ini | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/README.rst b/README.rst
index 01da41969168..074ded9a7db2 100644
--- a/README.rst
+++ b/README.rst
@@ -41,7 +41,7 @@ of community projects.
 Requirements
 
 
-- Python (2.7, 3.5 - 3.7)
+- Python (2.7, 3.5 - 3.8)
 
 - Django (1.11 - 2.2)
 
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index 61678134d418..5ef11203e850 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -49,7 +49,8 @@ RUN curl -L 
https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-instal
 RUN pyenv latest install 2.7 && \
 pyenv latest install 3.5 && \
 pyenv latest install 3.6 && \
-pyenv latest install 3.7
+pyenv latest install 3.7 && \
+pyenv latest install 3.8
 RUN pyenv global $(pyenv versions --bare | tac)
 
 RUN pip install tox tox-pyenv
diff --git a/tox.ini b/tox.ini
index 617e73cdbee6..4267f47241b6 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 minversion = 2.0
-envlist = pep8,docs,py27-django111,py{35,36,37}-django{111,20,21,22}
+envlist = pep8,docs,py27-django111,py{35,36,37,38}-django{111,20,21,22}
 skipsdist = True
 
 [testenv]
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: Deduplication of patchwork mail content?

2019-10-23 Thread Daniel Axtens
Konstantin Ryabitsev  writes:

> On Wed, Oct 09, 2019 at 05:35:03PM +1100, Daniel Axtens wrote:
>> Hi sfr, jk, Konstantin and any other admins lurking,
>> 
>> I'm in the process of reworking the patchwork db schema to avoid one of
>> our very big and very annoying (and slow) JOINs.
>> 
>> While I'm at it, it occurred to me that for both the ozlabs and
>> kernel.org instances, there are a lot of mails that are sent across
>> multiple projects. ATM the entire contents of the mail - content,
>> headers, diff, what have you, will be stored in full for each project.
>> 
>> Would it be of value for your deployments if I used this opportunity to
>> normalise the database and deduplicate emails? I was thinking of
>> splitting the big raw text fields (diff, content, headers) into their
>> own table and then indexing into that by message-id.
>
> Daniel:
>
> I think space is pretty cheap, and it's going to be a lot of work for
> little savings. Adding some indexes would be a much more effective way
> of improving performance in my view.
>
Cool, thanks to both of you. I will keep things the way they are, and
look at what indexes can be added.

Regards,
Daniel

> Best,
> -K
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH 2/2] [PW3] tox: Add Django 3.0b1

2019-10-23 Thread Daniel Axtens
Andrew Donnellan  writes:

> Now that we've dropped Python 2, we can get ready for Django 3.0.
>
> Add Django 3.0b1 as a tox environment.
>
> Closes: #311 ("Django 3.0 support")
> Signed-off-by: Andrew Donnellan 
>
> ---
>
> Not adding upper bounds on the version numbers until 3.0 actually drops.
>
> I'm considering this as closing the issue for Django 3.0 support, as now
> that Django 3.0 is in beta it's unlikely to get further breaking changes
> and we'll catch anything as we test it.

If you're going to close the issue, you should probably update the
README and add a release note with `reno new`.

Regards,
Daniel

> ---
>  tox.ini | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tox.ini b/tox.ini
> index ae15ce815f26..8ee11de56d14 100644
> --- a/tox.ini
> +++ b/tox.ini
> @@ -1,6 +1,6 @@
>  [tox]
>  minversion = 2.0
> -envlist = pep8,docs,py{36,37}-django{20,21,22}
> +envlist = pep8,docs,py{36,37}-django{20,21,22,30b1}
>  skipsdist = True
>  
>  [testenv]
> @@ -13,6 +13,9 @@ deps =
>  django22: django>=2.2,<2.3
>  django22: djangorestframework>=3.10,<3.11
>  django22: django-filter>=2.1,<3.0
> +django30b1: django==3.0b1
> +django30b1: djangorestframework>=3.10
> +django30b1: django-filter>=2.2
>  setenv =
>  DJANGO_SETTINGS_MODULE = patchwork.settings.dev
>  PYTHONDONTWRITEBYTECODE = 1
> -- 
> 2.20.1
>
> ___
> Patchwork mailing list
> Patchwork@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] README: remove dead landscape.io badge

2019-10-23 Thread Daniel Axtens
landsape.io is down and seems to have been for some time.
The issue tracker [1] doesn't seem to have anything since April.

Pull out the broken badge. If landscape.io returns we can add it
back later.

[1] 
https://github.com/landscapeio/landscape-issues/issues?q=is%3Aopen+is%3Aissue

Signed-off-by: Daniel Axtens 
---
 README.rst | 4 
 1 file changed, 4 deletions(-)

diff --git README.rst README.rst
index 01da41969168..8cf4c4b51fe5 100644
--- README.rst
+++ README.rst
@@ -10,10 +10,6 @@ Patchwork
:target: https://codecov.io/gh/getpatchwork/patchwork
:alt: Codecov
 
-.. image:: 
https://landscape.io/github/getpatchwork/patchwork/master/landscape.svg?style=flat
-   :target: https://landscape.io/github/getpatchwork/patchwork/master
-   :alt: Code Health
-
 .. image:: https://travis-ci.org/getpatchwork/patchwork.svg?branch=master
:target: https://travis-ci.org/getpatchwork/patchwork
:alt: Build Status
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] travis: fix codecov

2019-10-23 Thread Daniel Axtens
In e017f69376da ("travis: run pep8/flake8 tests"), codecov
was removed from the install step, on the basis that tox-travis
would pull it in automatically.

This, it turns out, isn't entirely true: it is pulled in to the
tox environment, but the data is actually sent in an after_success
step. That is outside the tox environment, as it should be - if it
were part of the tox environment, running `tox -e coverage` on a
developer laptop would try to send data to the web. But, as codecov
now isn't present outside the tox environment, we see in the logs:

$ codecov
codecov: command not found

We don't get any reporting of success/failure in the after_success
step, so we didn't notice.

Restore the installation in the travis environment.

Fixes: e017f69376da ("travis: run pep8/flake8 tests")
Signed-off-by: Daniel Axtens 
---
 .travis.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git .travis.yml .travis.yml
index cc326840cdb2..51746b2674ce 100644
--- .travis.yml
+++ .travis.yml
@@ -44,6 +44,7 @@ before_script:
 
 install:
   - pip install tox-travis
+  - pip install codecov
 
 script:
   - >
-- 
2.20.1

___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: Deduplication of patchwork mail content?

2019-10-23 Thread Konstantin Ryabitsev
On Wed, Oct 09, 2019 at 05:35:03PM +1100, Daniel Axtens wrote:
> Hi sfr, jk, Konstantin and any other admins lurking,
> 
> I'm in the process of reworking the patchwork db schema to avoid one of
> our very big and very annoying (and slow) JOINs.
> 
> While I'm at it, it occurred to me that for both the ozlabs and
> kernel.org instances, there are a lot of mails that are sent across
> multiple projects. ATM the entire contents of the mail - content,
> headers, diff, what have you, will be stored in full for each project.
> 
> Would it be of value for your deployments if I used this opportunity to
> normalise the database and deduplicate emails? I was thinking of
> splitting the big raw text fields (diff, content, headers) into their
> own table and then indexing into that by message-id.

Daniel:

I think space is pretty cheap, and it's going to be a lot of work for
little savings. Adding some indexes would be a much more effective way
of improving performance in my view.

Best,
-K
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


Re: [PATCH] api: support filtering patches by hash

2019-10-23 Thread Konstantin Ryabitsev
On Thu, Oct 24, 2019 at 01:33:42AM +1100, Daniel Axtens wrote:
> This is a feature that the XML-RPC API has, and which is used in
> the wild [1], so support it in the REST API.

Nice! Thank you for this.

> I tried to version the new filter field, but it's not at all clear
> how to do this with django-filters. The best way I could find
> requires manually manipulating request.GET, which seems to defeat
> the point of django-filters. So document it for 1.2, and have it
> work on older versions as an undocumented feature.
> 
> [1] 
> https://git.kernel.org/pub/scm/linux/kernel/git/mricon/korg-helpers.git/tree/git-patchwork-bot.py?id=104e7374e1be8458e6d2e82478625a7bf8c822ff
> 
> Cc: Konstantin Ryabitsev 
> Signed-off-by: Daniel Axtens 

Acked-by: Konstantin Ryabitsev 

-K
___
Patchwork mailing list
Patchwork@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/patchwork


[PATCH] api: support filtering patches by hash

2019-10-23 Thread Daniel Axtens
This is a feature that the XML-RPC API has, and which is used in
the wild [1], so support it in the REST API.

I tried to version the new filter field, but it's not at all clear
how to do this with django-filters. The best way I could find
requires manually manipulating request.GET, which seems to defeat
the point of django-filters. So document it for 1.2, and have it
work on older versions as an undocumented feature.

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/mricon/korg-helpers.git/tree/git-patchwork-bot.py?id=104e7374e1be8458e6d2e82478625a7bf8c822ff

Cc: Konstantin Ryabitsev 
Signed-off-by: Daniel Axtens 
---
 docs/api/schemas/latest/patchwork.yaml|  7 
 docs/api/schemas/patchwork.j2 |  9 +
 docs/api/schemas/v1.2/patchwork.yaml  |  7 
 patchwork/api/filters.py  |  8 -
 patchwork/tests/api/test_patch.py | 36 +++
 .../rest-filter-hash-e031bd3db42eb540.yaml|  5 +++
 6 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/rest-filter-hash-e031bd3db42eb540.yaml

diff --git docs/api/schemas/latest/patchwork.yaml 
docs/api/schemas/latest/patchwork.yaml
index 46969000a65b..6c7564baf81b 100644
--- docs/api/schemas/latest/patchwork.yaml
+++ docs/api/schemas/latest/patchwork.yaml
@@ -463,6 +463,13 @@ paths:
 enum:
   - 'true'
   - 'false'
+- in: query
+  name: hash
+  description: >
+The patch hash as a case-insensitive hexadecimal string, to filter 
by.
+  schema:
+title: ''
+type: string
   responses:
 '200':
   description: ''
diff --git docs/api/schemas/patchwork.j2 docs/api/schemas/patchwork.j2
index 4fc100eb4a92..12a6f67de32b 100644
--- docs/api/schemas/patchwork.j2
+++ docs/api/schemas/patchwork.j2
@@ -468,6 +468,15 @@ paths:
 enum:
   - 'true'
   - 'false'
+{% if version >= (1, 2) %}
+- in: query
+  name: hash
+  description: >
+The patch hash as a case-insensitive hexadecimal string, to filter 
by.
+  schema:
+title: ''
+type: string
+{% endif %}
   responses:
 '200':
   description: ''
diff --git docs/api/schemas/v1.2/patchwork.yaml 
docs/api/schemas/v1.2/patchwork.yaml
index 2ced470b7dc0..7dc95793faa3 100644
--- docs/api/schemas/v1.2/patchwork.yaml
+++ docs/api/schemas/v1.2/patchwork.yaml
@@ -463,6 +463,13 @@ paths:
 enum:
   - 'true'
   - 'false'
+- in: query
+  name: hash
+  description: >
+The patch hash as a case-insensitive hexadecimal string, to filter 
by.
+  schema:
+title: ''
+type: string
   responses:
 '200':
   description: ''
diff --git patchwork/api/filters.py patchwork/api/filters.py
index 37aca82d9ab2..4184ee8253f0 100644
--- patchwork/api/filters.py
+++ patchwork/api/filters.py
@@ -7,6 +7,7 @@ from django.contrib.auth.models import User
 from django.core.exceptions import ValidationError
 from django.db.models import Q
 from django_filters.rest_framework import FilterSet
+from django_filters import CharFilter
 from django_filters import IsoDateTimeFilter
 from django_filters import ModelMultipleChoiceFilter
 from django.forms import ModelMultipleChoiceField as BaseMultipleChoiceField
@@ -176,11 +177,16 @@ class PatchFilterSet(TimestampMixin, FilterSet):
 submitter = PersonFilter(queryset=Person.objects.all())
 delegate = UserFilter(queryset=User.objects.all())
 state = StateFilter(queryset=State.objects.all())
+hash = CharFilter(lookup_expr='iexact')
 
 class Meta:
 model = Patch
+# NOTE(dja): ideally we want to version the hash field, but I cannot
+# find a way to do that which is reliable and not extremely ugly.
+# The best I can come up with is manually working with request.GET
+# which seems to rather defeat the point of using django-filters.
 fields = ('project', 'series', 'submitter', 'delegate',
-  'state', 'archived')
+  'state', 'archived', 'hash')
 
 
 class CheckFilterSet(TimestampMixin, FilterSet):
diff --git patchwork/tests/api/test_patch.py patchwork/tests/api/test_patch.py
index edae9851c422..4afc15a9ba1c 100644
--- patchwork/tests/api/test_patch.py
+++ patchwork/tests/api/test_patch.py
@@ -22,6 +22,13 @@ from patchwork.tests.utils import create_user
 if settings.ENABLE_REST_API:
 from rest_framework import status
 
+# a diff different from the default, required to test hash filtering
+SAMPLE_DIFF = """--- /dev/null\t2019-01-01 00:00:00.0 +0800
 a\t2019-01-01 00:00:00.0 +0800
+@@ -0,0 +1 @@
++b
+"""
+
 
 @unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API')
 class TestPatchAPI(utils.APITestCase):
@@ -152,6 +159,35 @@ class