gitlab: Add support for unapproved merge request.

This commit is contained in:
pemontto 2020-04-25 10:12:42 +01:00 committed by Tim Abbott
parent 740e01e456
commit 1688863be0
3 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,130 @@
{
"object_kind":"merge_request",
"user":{
"name":"Eeshan Garg",
"username":"eeshangargtest",
"avatar_url":"https://secure.gravatar.com/avatar/36cf0dc28c5302bcd68119fcaaf4d4f3?s=80\u0026d=identicon"
},
"project":{
"id":3319043,
"name":"my-awesome-project",
"description":"",
"web_url":"https://gitlab.com/eeshangarg/my-awesome-project",
"avatar_url":null,
"git_ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"git_http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git",
"namespace":"eeshangarg",
"visibility_level":20,
"path_with_namespace":"eeshangarg/my-awesome-project",
"default_branch":"feature",
"ci_config_path":null,
"homepage":"https://gitlab.com/eeshangarg/my-awesome-project",
"url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git"
},
"object_attributes":{
"assignee_id":null,
"author_id":1129123,
"created_at":"2017-05-31 03:27:26 UTC",
"deleted_at":null,
"description":"",
"head_pipeline_id":null,
"id":3673242,
"iid":1,
"last_edited_at":null,
"last_edited_by_id":null,
"merge_commit_sha":null,
"merge_error":null,
"merge_params":{
"force_remove_source_branch":null
},
"merge_status":"can_be_merged",
"merge_user_id":null,
"merge_when_pipeline_succeeds":false,
"milestone_id":null,
"source_branch":"changes",
"source_project_id":3319043,
"target_branch":"feature",
"target_project_id":3319043,
"time_estimate":0,
"title":"Update the README with author name",
"updated_at":"2017-12-18 00:39:44 UTC",
"updated_by_id":null,
"url":"https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1",
"source":{
"id":3319043,
"name":"my-awesome-project",
"description":"",
"web_url":"https://gitlab.com/eeshangarg/my-awesome-project",
"avatar_url":null,
"git_ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"git_http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git",
"namespace":"eeshangarg",
"visibility_level":20,
"path_with_namespace":"eeshangarg/my-awesome-project",
"default_branch":"feature",
"ci_config_path":null,
"homepage":"https://gitlab.com/eeshangarg/my-awesome-project",
"url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git"
},
"target":{
"id":3319043,
"name":"my-awesome-project",
"description":"",
"web_url":"https://gitlab.com/eeshangarg/my-awesome-project",
"avatar_url":null,
"git_ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"git_http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git",
"namespace":"eeshangarg",
"visibility_level":20,
"path_with_namespace":"eeshangarg/my-awesome-project",
"default_branch":"feature",
"ci_config_path":null,
"homepage":"https://gitlab.com/eeshangarg/my-awesome-project",
"url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"ssh_url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"http_url":"https://gitlab.com/eeshangarg/my-awesome-project.git"
},
"last_commit":{
"id":"b1b2824f280e73c5f57c78da5f8eb3cd19990867",
"message":"Update the README with author name\n",
"timestamp":"2017-05-31T00:55:38-02:30",
"url":"https://gitlab.com/eeshangarg/my-awesome-project/commit/b1b2824f280e73c5f57c78da5f8eb3cd19990867",
"author":{
"name":"Eeshan Garg",
"email":"jerryguitarist@gmail.com"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"human_total_time_spent": null,
"human_time_estimate": null,
"assignee_ids": [
3655283
],
"state": "opened",
"action": "unapproved"
},
"labels":[
],
"changes": {
"updated_at": {
"previous": "2020-04-25 07:40:54 UTC",
"current": "2020-04-25 07:44:00 UTC"
},
"total_time_spent": {
"previous": null,
"current": 0
}
},
"repository":{
"name":"my-awesome-project",
"url":"git@gitlab.com:eeshangarg/my-awesome-project.git",
"description":"",
"homepage":"https://gitlab.com/eeshangarg/my-awesome-project"
}
}

View File

@ -606,3 +606,12 @@ class GitlabHookTests(WebhookTestCase):
'system_hook__merge_request_closed',
expected_topic,
expected_message)
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)

View File

@ -297,6 +297,7 @@ EVENT_FUNCTION_MAPPER = {
'Confidential Note Hook Issue': get_commented_issue_event_body,
'Note Hook Snippet': get_commented_snippet_event_body,
'Merge Request Hook approved': partial(get_merge_request_event_body, action='approved'),
'Merge Request Hook unapproved': partial(get_merge_request_event_body, action='unapproved'),
'Merge Request Hook open': partial(get_merge_request_open_or_updated_body, action='created'),
'Merge Request Hook update': get_merge_request_updated_event_body,
'Merge Request Hook merge': partial(get_merge_request_event_body, action='merged'),