Repository: buildbot/buildbot

Issue:
REST args in GitLab push notification do not work
This is fundamentally the same problem we had at #3506 (@rodrigc). In Python3, some strings are now byte strings and are not identified properly by Buildbot.

In this case, I have a local gitlab instance with the webhook for push events: `https://mybuildbot/change_hook/gitlab?project=lthmb`.

However, when I test this the Buildbot logs show no `project` parameter set:
```
2017-10-27 18:15:14+0200 [-] injected change Change(revision='2afc1ab3ab28980db47d64714852aa0d586be7f9', who='Paulo Matos <pmatos@linki.tools>', branch='master', comments="Merge branch 'foobar'\n", when=1506599131, category='push', project='', repository='git@linki:pmatos/lthmb.git', codebase='')
```
I went ahead and printed the request received from gitlab in `www/hooks/gitlab.py` and noticed that `request.args` in `getChanges` are byte strings: `2017-10-27 18:15:14+0200 [-] {b'project': [b'lthmb']}`

I think in Buildbot nine with Py3 we might need string conversion here.


Discussion:

Resolving patch:
diff --git a/master/buildbot/www/hooks/gitlab.py b/master/buildbot/www/hooks/gitlab.py
--- a/master/buildbot/www/hooks/gitlab.py
+++ b/master/buildbot/www/hooks/gitlab.py
@@ -154,8 +154,10 @@ def getChanges(self, request):
         # newer version of gitlab have a object_kind parameter,
         # which allows not to use the http header
         event_type = payload.get('object_kind', event_type)
-        project = request.args.get('project', [''])[0]
-        codebase = request.args.get('codebase', [None])[0]
+        project = request.args.get(b'project', [''])[0]
+        project = bytes2unicode(project)
+        codebase = request.args.get(b'codebase', [None])[0]
+        codebase = bytes2unicode(codebase)
         if event_type in ("push", "tag_push", "Push Hook"):
             user = payload['user_name']
             repo = payload['repository']['name']


Test patch:
diff --git a/master/buildbot/test/unit/test_www_hooks_gitlab.py b/master/buildbot/test/unit/test_www_hooks_gitlab.py
--- a/master/buildbot/test/unit/test_www_hooks_gitlab.py
+++ b/master/buildbot/test/unit/test_www_hooks_gitlab.py
@@ -280,7 +280,7 @@ def testGitWithChange(self):
     def testGitWithChange_WithProjectToo(self):
         self.request = FakeRequest(content=gitJsonPayload)
         self.request.uri = b"/change_hook/gitlab"
-        self.request.args = {'project': ['MyProject']}
+        self.request.args = {b'project': [b'MyProject']}
         self.request.received_headers[_HEADER_EVENT] = b"Push Hook"
         self.request.method = b"POST"
         res = yield self.request.test_render(self.changeHook)
@@ -290,7 +290,7 @@ def testGitWithChange_WithProjectToo(self):
     def testGitWithChange_WithCodebaseToo(self):
         self.request = FakeRequest(content=gitJsonPayload)
         self.request.uri = b"/change_hook/gitlab"
-        self.request.args = {'codebase': ['MyCodebase']}
+        self.request.args = {b'codebase': [b'MyCodebase']}
         self.request.received_headers[_HEADER_EVENT] = b"Push Hook"
         self.request.method = b"POST"
         res = yield self.request.test_render(self.changeHook)
@@ -300,7 +300,7 @@ def testGitWithChange_WithCodebaseToo(self):
     def testGitWithChange_WithPushTag(self):
         self.request = FakeRequest(content=gitJsonPayloadTag)
         self.request.uri = b"/change_hook/gitlab"
-        self.request.args = {'codebase': ['MyCodebase']}
+        self.request.args = {b'codebase': [b'MyCodebase']}
         self.request.received_headers[_HEADER_EVENT] = b"Push Hook"
         self.request.method = b"POST"
         res = yield self.request.test_render(self.changeHook)
@@ -337,7 +337,7 @@ def test_event_property(self):
     def testGitWithChange_WithMR(self):
         self.request = FakeRequest(content=gitJsonPayloadMR)
         self.request.uri = b"/change_hook/gitlab"
-        self.request.args = {'codebase': ['MyCodebase']}
+        self.request.args = {b'codebase': [b'MyCodebase']}
         self.request.received_headers[_HEADER_EVENT] = b"Merge Request Hook"
         self.request.method = b"POST"
         res = yield self.request.test_render(self.changeHook)
@@ -359,7 +359,7 @@ def setUp(self):
     def test_missing_secret(self):
         self.request = FakeRequest(content=gitJsonPayloadTag)
         self.request.uri = b"/change_hook/gitlab"
-        self.request.args = {'codebase': ['MyCodebase']}
+        self.request.args = {b'codebase': [b'MyCodebase']}
         self.request.method = b"POST"
         self.request.received_headers[_HEADER_EVENT] = b"Push Hook"
         yield self.request.test_render(self.changeHook)