2020-05-26 07:16:25 +02:00
from unittest . mock import MagicMock , patch
2017-11-16 00:43:10 +01:00
2016-11-10 19:30:09 +01:00
from zerver . lib . test_classes import WebhookTestCase
2017-11-16 00:43:10 +01:00
from zerver . lib . webhooks . git import COMMITS_LIMIT
2016-09-20 22:51:11 +02:00
2020-01-14 22:06:24 +01:00
2016-09-20 22:51:11 +02:00
class GitlabHookTests ( WebhookTestCase ) :
STREAM_NAME = ' gitlab '
2017-04-21 23:35:40 +02:00
URL_TEMPLATE = " /api/v1/external/gitlab?&api_key= {api_key} &stream= {stream} "
2016-09-20 22:51:11 +02:00
FIXTURE_DIR_NAME = ' gitlab '
2018-01-09 12:06:52 +01:00
def test_push_event_specified_topic ( self ) - > None :
self . url = self . build_webhook_url ( " topic=Specific % 20topic " )
2020-04-09 21:51:58 +02:00
expected_topic = " Specific topic "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] 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)) "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook ' , expected_topic , expected_message )
2018-01-09 12:06:52 +01:00
2017-11-04 07:47:46 +01:00
def test_push_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
expected_message = " 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)) "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook ' , expected_topic , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_push_local_branch_without_commits ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / changes "
expected_message = " Eeshan Garg [pushed](https://gitlab.com/eeshangarg/my-awesome-project/compare/0000000000000000000000000000000000000000...68d7a5528cf423dfaac37dd62a56ac9cc8a884e3) the branch changes. "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__push_local_branch_without_commits ' , expected_topic , expected_message )
2017-05-17 04:12:56 +02:00
2017-11-04 07:47:46 +01:00
def test_push_event_message_filtered_by_branches ( self ) - > None :
2017-04-21 23:35:40 +02:00
self . url = self . build_webhook_url ( branches = ' master,tomek ' )
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
expected_message = " 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)) "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook ' , expected_topic , expected_message )
2017-04-03 04:46:41 +02:00
2017-11-04 07:47:46 +01:00
def test_push_multiple_committers ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
expected_message = " Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek. Commits by Ben (1) and Tomasz Kolek (1). \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)) "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__push_multiple_committers ' , expected_topic , expected_message )
2017-04-05 09:12:19 +02:00
2017-11-04 07:47:46 +01:00
def test_push_multiple_committers_with_others ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
commit_info = " * b ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9)) \n "
2020-06-09 00:25:09 +02:00
expected_message = f " Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 7 commits to branch tomek. Commits by Ben (3), baxterthehacker (2), James (1) and others (1). \n \n { commit_info * 6 } * b ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9)) "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__push_multiple_committers_with_others ' , expected_topic , expected_message )
2017-04-05 09:12:19 +02:00
2017-11-04 07:47:46 +01:00
def test_push_commits_more_than_limit_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
commits_info = ' * b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7)) \n '
2020-06-10 06:40:53 +02:00
expected_message = f " Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek. \n \n { commits_info * COMMITS_LIMIT } [and { 50 - COMMITS_LIMIT } more commit(s)] "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__push_commits_more_than_limit ' , expected_topic , expected_message )
2016-10-07 15:20:37 +02:00
2017-11-04 07:47:46 +01:00
def test_push_commits_more_than_limit_message_filtered_by_branches ( self ) - > None :
2017-04-21 23:35:40 +02:00
self . url = self . build_webhook_url ( branches = ' master,tomek ' )
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
commits_info = ' * b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7)) \n '
2020-06-10 06:40:53 +02:00
expected_message = f " Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek. \n \n { commits_info * COMMITS_LIMIT } [and { 50 - COMMITS_LIMIT } more commit(s)] "
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__push_commits_more_than_limit ' , expected_topic , expected_message )
2017-04-03 04:46:41 +02:00
2017-11-04 07:47:46 +01:00
def test_remove_branch_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / tomek "
expected_message = " Tomasz Kolek deleted branch tomek. "
2016-10-06 17:13:40 +02:00
2019-07-15 08:10:55 +02:00
self . send_and_test_stream_message ( ' push_hook__remove_branch ' , expected_topic , expected_message )
2016-10-06 17:13:40 +02:00
2017-11-04 07:47:46 +01:00
def test_add_tag_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project "
expected_message = " Tomasz Kolek pushed tag xyz. "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' tag_push_hook__add_tag ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2016-09-20 22:51:11 +02:00
expected_message ,
HTTP_X_GITLAB_EVENT = " Tag Push Hook " ,
)
2017-11-04 07:47:46 +01:00
def test_remove_tag_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project "
expected_message = " Tomasz Kolek removed tag xyz. "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' tag_push_hook__remove_tag ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_create_issue_without_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #1 Issue title "
expected_message = " Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1): \n \n ~~~ quote \n Issue description \n ~~~ "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_without_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2018-12-18 23:37:44 +01:00
def test_create_confidential_issue_without_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #1 Testing "
expected_message = " Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1): \n \n ~~~ quote \n Testing \n ~~~ "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_created_without_assignee ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2018-07-20 00:49:05 +02:00
def test_create_issue_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [Issue #1 Issue title](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1): \n \n ~~~ quote \n Issue description \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_without_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_create_issue_with_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #1 Issue title "
expected_message = " Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1) (assigned to Tomasz Kolek): \n \n ~~~ quote \n Issue description \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_with_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2018-12-20 23:31:05 +01:00
def test_create_issue_with_two_assignees_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " Zulip GitLab Test / Issue #2 Zulip Test Issue 2 "
expected_message = " Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to adambirds and eeshangarg): \n \n ~~~ quote \n Zulip Test Issue 2 \n ~~~ "
2018-12-20 23:31:05 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_with_two_assignees ' ,
2018-12-20 23:31:05 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-20 23:31:05 +01:00
def test_create_issue_with_three_assignees_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " Zulip GitLab Test / Issue #2 Zulip Test Issue 2 "
expected_message = " Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to adambirds, eeshangarg and timabbott): \n \n ~~~ quote \n Zulip Test Issue 2 \n ~~~ "
2018-12-20 23:31:05 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_with_three_assignees ' ,
2018-12-20 23:31:05 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-20 23:31:05 +01:00
2018-12-18 23:37:44 +01:00
def test_create_confidential_issue_with_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #2 Testing "
expected_message = " Joe Bloggs created [Issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2) (assigned to joe.bloggs): \n \n ~~~ quote \n Testing \n ~~~ "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_created_with_assignee ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2018-01-24 03:08:53 +01:00
def test_create_issue_with_hidden_comment_in_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " public-repo / Issue #3 New Issue with hidden comment "
expected_message = " Eeshan Garg created [Issue #3](https://gitlab.com/eeshangarg/public-repo/issues/3): \n \n ~~~ quote \n This description actually has a hidden comment in it! \n ~~~ "
2018-01-24 03:08:53 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_created_with_hidden_comment_in_description ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-01-24 03:08:53 +01:00
2018-12-18 23:37:44 +01:00
def test_create_confidential_issue_with_hidden_comment_in_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #1 Testing "
expected_message = " Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1): \n \n ~~~ quote \n This description actually has a hidden comment in it! \n ~~~ "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_created_with_hidden_comment_in_description ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2018-03-23 18:50:46 +01:00
def test_create_issue_with_null_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #7 Issue without description "
expected_message = " Eeshan Garg created [Issue #7](https://gitlab.com/eeshangarg/my-awesome-project/issues/7). "
2018-03-23 18:50:46 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_opened_with_null_description ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-03-23 18:50:46 +01:00
2017-11-04 07:47:46 +01:00
def test_update_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #1 Issue title_new "
expected_message = " Tomasz Kolek updated [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1). "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_updated ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2018-12-18 23:37:44 +01:00
def test_update_confidential_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #1 Testing "
expected_message = " Joe Bloggs updated [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1). "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_updated ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2018-07-20 00:49:05 +02:00
def test_update_issue_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek updated [Issue #1 Issue title_new](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_updated ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_close_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #1 Issue title_new "
expected_message = " Tomasz Kolek closed [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_closed ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2018-12-18 23:37:44 +01:00
def test_close_confidential_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #1 Testing Test "
expected_message = " Joe Bloggs closed [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1). "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_closed ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2017-11-04 07:47:46 +01:00
def test_reopen_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #1 Issue title_new "
expected_message = " Tomasz Kolek reopened [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__issue_reopened ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2018-12-18 23:37:44 +01:00
def test_reopen_confidential_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " testing / Issue #1 Testing Test "
expected_message = " Joe Bloggs reopened [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1). "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' issue_hook__confidential_issue_reopened ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2017-11-04 07:47:46 +01:00
def test_note_commit_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project "
expected_message = " Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7#note_14169211) on [66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7): \n ~~~ quote \n nice commit \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__commit_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_note_merge_request_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #1 Tomek "
expected_message = " Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR #1](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1): \n \n ~~~ quote \n Nice merge request! \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__merge_request_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2020-07-29 07:39:42 +02:00
def test_note_merge_request_event_message_without_merge_request_title ( self ) - > None :
expected_topic = " my-awesome-project / MR #1 "
expected_message = " Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR #1](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1): \n \n ~~~ quote \n Nice merge request! \n ~~~ "
self . url = self . build_webhook_url ( use_merge_request_title = " false " ) # To keep things as valid JSON.
self . send_and_test_stream_message (
' note_hook__merge_request_note ' ,
expected_topic ,
expected_message )
2018-07-20 00:49:05 +02:00
def test_note_merge_request_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR #1 Tomek](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1): \n \n ~~~ quote \n Nice merge request! \n ~~~ "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__merge_request_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2017-11-04 07:47:46 +01:00
def test_note_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Issue #2 abc "
expected_message = " Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2#note_14172057) on [Issue #2](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2): \n \n ~~~ quote \n Nice issue \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__issue_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2018-12-18 23:37:44 +01:00
def test_note_confidential_issue_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_subject = " Test / Issue #3 Test "
expected_message = " Joe Bloggs [commented](https://gitlab.com/joebloggs/test/issues/3#note_101638770) on [Issue #3](https://gitlab.com/joebloggs/test/issues/3): \n \n ~~~ quote \n Test \n ~~~ "
2018-12-18 23:37:44 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__confidential_issue_note ' ,
2018-12-18 23:37:44 +01:00
expected_subject ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-12-18 23:37:44 +01:00
2018-07-20 00:49:05 +02:00
def test_note_issue_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2#note_14172057) on [Issue #2 abc](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2): \n \n ~~~ quote \n Nice issue \n ~~~ "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__issue_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2017-11-04 07:47:46 +01:00
def test_note_snippet_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / Snippet #2 test "
expected_message = " Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [Snippet #2](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2): \n \n ~~~ quote \n Nice snippet \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__snippet_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2018-07-20 00:49:05 +02:00
def test_note_snippet_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [Snippet #2 test](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2): \n \n ~~~ quote \n Nice snippet \n ~~~ "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' note_hook__snippet_note ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_created_without_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #2 NEW MR "
expected_message = " Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_created_without_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-11-29 07:22:02 +01:00
2018-07-20 00:49:05 +02:00
def test_merge_request_created_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_created_without_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_created_with_assignee_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_created_with_assignee ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_closed_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #2 NEW MR "
expected_message = " Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_closed ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2020-07-29 07:39:42 +02:00
def test_merge_request_closed_event_message_without_using_title ( self ) - > None :
expected_topic = " my-awesome-project / MR #2 "
expected_message = " Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2). "
self . url = self . build_webhook_url ( use_merge_request_title = " false " )
self . send_and_test_stream_message (
' merge_request_hook__merge_request_closed ' ,
expected_topic ,
expected_message )
2018-07-20 00:49:05 +02:00
def test_merge_request_closed_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
2020-04-22 15:28:34 +02:00
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2). "
2018-07-20 00:49:05 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_closed ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2018-07-20 00:49:05 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_reopened_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #1 Update the README with author ... "
expected_message = " Eeshan Garg reopened [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1). "
2017-05-31 06:30:04 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_reopened ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2017-05-31 06:30:04 +02:00
2017-12-18 01:58:54 +01:00
def test_merge_request_approved_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #1 Update the README with author ... "
expected_message = " Eeshan Garg approved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1). "
2017-12-18 01:58:54 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_approved ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2017-12-18 01:58:54 +01:00
2017-11-04 07:47:46 +01:00
def test_merge_request_updated_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek updated [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek) from `tomek` to `master`: \n \n ~~~ quote \n updated desc \n ~~~ "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_updated ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_added_commit_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek added commit(s) to [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_added_commit ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_merge_request_merged_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' merge_request_hook__merge_request_merged ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_wiki_page_opened_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project "
expected_message = " Tomasz Kolek created [Wiki Page \" how to \" ](https://gitlab.com/tomaszkolek0/my-awesome-project/wikis/how-to). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' wiki_page_hook__wiki_page_opened ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_wiki_page_edited_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project "
expected_message = " Tomasz Kolek updated [Wiki Page \" how to \" ](https://gitlab.com/tomaszkolek0/my-awesome-project/wikis/how-to). "
2016-09-20 22:51:11 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' wiki_page_hook__wiki_page_edited ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2019-07-15 08:10:55 +02:00
expected_message )
2016-09-28 22:02:41 +02:00
2017-11-04 07:47:46 +01:00
def test_build_created_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage was created. "
2016-09-28 22:02:41 +02:00
self . send_and_test_stream_message (
' build_created ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2016-09-28 22:02:41 +02:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Job Hook " ,
2016-09-28 22:02:41 +02:00
)
2017-11-04 07:47:46 +01:00
def test_build_started_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage started. "
2016-09-28 22:02:41 +02:00
self . send_and_test_stream_message (
' build_started ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2016-09-28 22:02:41 +02:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Job Hook " ,
2016-09-28 22:02:41 +02:00
)
2017-11-04 07:47:46 +01:00
def test_build_succeeded_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage changed status to success. "
2016-09-28 22:02:41 +02:00
self . send_and_test_stream_message (
' build_succeeded ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2016-09-28 22:02:41 +02:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Job Hook " ,
2016-09-28 22:02:41 +02:00
)
2016-09-28 23:06:04 +02:00
2018-02-24 23:41:25 +01:00
def test_build_created_event_message_legacy_event_name ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage was created. "
2018-02-24 23:41:25 +01:00
self . send_and_test_stream_message (
' build_created ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2018-02-24 23:41:25 +01:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Build Hook " ,
2018-02-24 23:41:25 +01:00
)
def test_build_started_event_message_legacy_event_name ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage started. "
2018-02-24 23:41:25 +01:00
self . send_and_test_stream_message (
' build_started ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2018-02-24 23:41:25 +01:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Build Hook " ,
2018-02-24 23:41:25 +01:00
)
def test_build_succeeded_event_message_legacy_event_name ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
expected_message = " Build job_name from test stage changed status to success. "
2018-02-24 23:41:25 +01:00
self . send_and_test_stream_message (
' build_succeeded ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
2018-02-24 23:41:25 +01:00
expected_message ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
HTTP_X_GITLAB_EVENT = " Build Hook " ,
2018-02-24 23:41:25 +01:00
)
2020-06-06 15:09:57 +02:00
def test_pipeline_succeeded_with_artifacts_event_message ( self ) - > None :
expected_topic = " onlysomeproject / test/links-in-zulip-pipeline-message "
2020-06-06 15:12:48 +02:00
expected_message = " [Pipeline (22668)](https://gitlab.example.com/group1/onlysomeproject/pipelines/22668) changed status to success with build(s): \n * [cleanup:cleanup docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58592) - success \n * [pages](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591) - success \n * built artifact: *artifacts.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/download)] \n * [black+pytest:future environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58590) - success \n * [docs:anaconda environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589) - success \n * built artifact: *sphinx-docs.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/download)] \n * [pytest:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58588) - success \n * [black:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58587) - success \n * [setup:docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58586) - success. "
2020-06-06 15:09:57 +02:00
self . send_and_test_stream_message (
' pipeline_hook__pipline_succeeded_with_artifacts ' ,
expected_topic ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
expected_message ,
2020-06-06 15:09:57 +02:00
)
2017-11-04 07:47:46 +01:00
def test_pipeline_succeeded_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
2020-06-06 15:12:48 +02:00
expected_message = " [Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/pipelines/4414206) changed status to success with build(s): \n * [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - success \n * [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - success. "
2016-09-28 23:06:04 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' pipeline_hook__pipeline_succeeded ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
expected_message ,
2016-09-28 23:06:04 +02:00
)
2017-11-04 07:47:46 +01:00
def test_pipeline_started_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
2020-06-06 15:12:48 +02:00
expected_message = " [Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/pipelines/4414206) started with build(s): \n * [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - running \n * [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending. "
2016-09-28 23:06:04 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' pipeline_hook__pipeline_started ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
expected_message ,
2016-09-28 23:06:04 +02:00
)
2017-11-04 07:47:46 +01:00
def test_pipeline_pending_event_message ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = " my-awesome-project / master "
2020-06-06 15:12:48 +02:00
expected_message = " [Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/pipelines/4414206) was created with build(s): \n * [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending \n * [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - created. "
2016-09-28 23:06:04 +02:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' pipeline_hook__pipeline_pending ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
expected_message ,
2016-09-28 23:06:04 +02:00
)
2017-04-03 04:46:41 +02:00
2018-03-12 02:47:49 +01:00
def test_issue_type_test_payload ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_topic = ' public-repo '
expected_message = " Webhook for **public-repo** has been configured successfully! :tada: "
2017-11-15 04:20:21 +01:00
self . send_and_test_stream_message (
2019-07-15 08:10:55 +02:00
' test_hook__issue_test_payload ' ,
2018-11-09 20:33:58 +01:00
expected_topic ,
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
expected_message ,
2017-11-15 04:20:21 +01:00
)
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.lib.webhooks.common.check_send_webhook_message ' )
2017-04-03 04:46:41 +02:00
def test_push_event_message_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-21 23:35:40 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2019-07-15 08:10:55 +02:00
payload = self . get_body ( ' push_hook ' )
2017-04-03 04:46:41 +02:00
result = self . client_post ( self . url , payload , HTTP_X_GITLAB_EVENT = ' Push Hook ' , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-03 04:46:41 +02:00
self . assert_json_success ( result )
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.lib.webhooks.common.check_send_webhook_message ' )
2017-04-03 04:46:41 +02:00
def test_push_commits_more_than_limit_message_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-21 23:35:40 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2019-07-15 08:10:55 +02:00
payload = self . get_body ( ' push_hook__push_commits_more_than_limit ' )
2017-04-03 04:46:41 +02:00
result = self . client_post ( self . url , payload , HTTP_X_GITLAB_EVENT = ' Push Hook ' , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-03 04:46:41 +02:00
self . assert_json_success ( result )
2020-04-25 11:09:30 +02:00
2020-05-11 23:36:05 +02:00
def test_job_hook_event ( self ) - > None :
expected_topic = " gitlab_test / gitlab-script-trigger "
expected_message = " Build test from test stage was created. "
self . send_and_test_stream_message (
' job_hook__build_created ' ,
expected_topic ,
expected_message )
2020-05-12 01:13:18 +02:00
def test_job_hook_event_topic ( self ) - > None :
self . url = self . build_webhook_url ( topic = " provided topic " )
expected_topic = " provided topic "
expected_message = " [[gitlab_test](http://192.168.64.1:3005/gitlab-org/gitlab-test)] Build test from test stage was created. "
self . send_and_test_stream_message (
' job_hook__build_created ' ,
expected_topic ,
expected_message )
2020-04-25 11:09:30 +02:00
def test_system_push_event_message ( self ) - > None :
expected_topic = " gitlab / master "
expected_message = " John Smith [pushed](http://test.example.com/gitlab/gitlab/compare/95790bf891e76fee5e1747ab589903a6a1f80f22...da1560886d4f094c3e6c9ef40349f7d38b5d27d7) 1 commit to branch master. Commits by Test User (1). \n \n * Add simple search to projects in public area ([c5feabd](https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428)) "
self . send_and_test_stream_message ( ' system_hook__push_hook ' , expected_topic , expected_message )
def test_system_merge_request_created_without_assignee_event_message ( self ) - > None :
expected_topic = " my-awesome-project / MR #2 NEW MR "
expected_message = " Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
self . send_and_test_stream_message (
' system_hook__merge_request_created_without_assignee ' ,
expected_topic ,
expected_message )
def test_system_merge_request_created_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
expected_topic = " notifications "
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
self . send_and_test_stream_message (
' system_hook__merge_request_created_without_assignee ' ,
expected_topic ,
expected_message )
def test_system_merge_request_created_with_assignee_event_message ( self ) - > None :
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek) from `tomek` to `master`: \n \n ~~~ quote \n description of merge request \n ~~~ "
self . send_and_test_stream_message (
' system_hook__merge_request_created_with_assignee ' ,
expected_topic ,
expected_message )
def test_system_merge_request_closed_event_message ( self ) - > None :
expected_topic = " my-awesome-project / MR #2 NEW MR "
expected_message = " Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2). "
self . send_and_test_stream_message (
' system_hook__merge_request_closed ' ,
expected_topic ,
expected_message )
def test_system_merge_request_merged_event_message ( self ) - > None :
expected_topic = " my-awesome-project / MR #3 New Merge Request "
expected_message = " Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3). "
self . send_and_test_stream_message (
' system_hook__merge_request_merged ' ,
expected_topic ,
expected_message )
def test_system_merge_request_closed_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = ' notifications ' )
expected_topic = " notifications "
expected_message = " [[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2). "
self . send_and_test_stream_message (
' system_hook__merge_request_closed ' ,
expected_topic ,
expected_message )
2020-04-25 11:12:42 +02:00
def test_merge_request_unapproved_event_message ( self ) - > None :
expected_topic = " my-awesome-project / MR #1 Update the README with author ... "
expected_message = " Eeshan Garg unapproved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1). "
self . send_and_test_stream_message (
' merge_request_hook__merge_request_unapproved ' ,
expected_topic ,
expected_message )