Repository: zulip/zulip

Issue:
integrations: Add topic query parameter for gitlab integration.
https://chat.zulip.org/#narrow/stream/integrations/topic/gitlab.20configuration.20request


Discussion:
Hello @zulip/server-integrations members, this issue was labeled with the **area: integrations** label, so you may want to check it out!

<!-- areaLabelNotification -->
@rishig can take up this issue? 
It's best to work on only one issue at a time, but other than that go ahead!
@rishig can you help me with what i am supposed to do?
I would like to work on this bug. Could anyone explain about this bug?
@zulipbot claim
Welcome to Zulip, @fossbalaji! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* Sign the [Dropbox Contributor License Agreement](https://opensource.dropbox.com/cla/), so that Zulip can use your code.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
Hello @fossbalaji, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

You can reclaim this issue or claim any other issue by commenting `@zulipbot claim` on that issue.

Thanks for your contributions, and hope to see you again soon!
@zulipbot claim
Welcome to Zulip, @hrishi3108! We just sent you an invite to collaborate on this repository at https://github.com/zulip/zulip/invitations. Please accept this invite in order to claim this issue and begin a fun, rewarding experience contributing to Zulip!

Here's some tips to get you off to a good start:
* Join me on the [Zulip developers' server](https://chat.zulip.org), to get help, chat about this issue, and meet the other developers.
* Sign the [Dropbox Contributor License Agreement](https://opensource.dropbox.com/cla/), so that Zulip can use your code.
* [Unwatch this repository](https://help.github.com/articles/unwatching-repositories/), so that you don't get 100 emails a day.

As you work on this issue, you'll also want to refer to the [Zulip code contribution guide](https://zulip.readthedocs.io/en/latest/contributing/index.html), as well as the rest of the developer documentation on that site.

See you on the other side (that is, the pull request side)!
@zulipbot abandon
@zulipbot claim

Resolving patch:
diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py
--- a/zerver/webhooks/gitlab/view.py
+++ b/zerver/webhooks/gitlab/view.py
@@ -264,13 +264,15 @@ def get_object_url(payload: Dict[str, Any]) -> Text:
 @has_request_variables
 def api_gitlab_webhook(request: HttpRequest, user_profile: UserProfile,
                        stream: Text=REQ(default='gitlab'),
+                       topic: Text=REQ(default=None),
                        payload: Dict[str, Any]=REQ(argument_type='body'),
                        branches: Optional[Text]=REQ(default=None)) -> HttpResponse:
     event = get_event(request, payload, branches)
     if event is not None:
         body = get_body_based_on_event(event)(payload)
-        subject = get_subject_based_on_event(event, payload)
-        check_send_stream_message(user_profile, request.client, stream, subject, body)
+        if topic is None:
+            topic = get_subject_based_on_event(event, payload)
+        check_send_stream_message(user_profile, request.client, stream, topic, body)
     return json_success()
 
 def get_body_based_on_event(event: str) -> Any:


Test patch:
diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py
--- a/zerver/webhooks/gitlab/tests.py
+++ b/zerver/webhooks/gitlab/tests.py
@@ -11,6 +11,12 @@ class GitlabHookTests(WebhookTestCase):
     URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}&stream={stream}"
     FIXTURE_DIR_NAME = 'gitlab'
 
+    def test_push_event_specified_topic(self) -> None:
+        self.url = self.build_webhook_url("topic=Specific%20topic")
+        expected_topic = u"Specific topic"
+        expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
+        self.send_and_test_stream_message('push', expected_topic, expected_message, HTTP_X_GITLAB_EVENT="Push Hook")
+
     def test_push_event_message(self) -> None:
         expected_subject = u"my-awesome-project / tomek"
         expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"