Skip to content

Commit

Permalink
fix: Edited GitLab MR should be an update action, not a sync
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Bayer <[email protected]>
  • Loading branch information
abayer committed Apr 29, 2020
1 parent 5e0cb12 commit 74cab80
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 8 deletions.
154 changes: 154 additions & 0 deletions scm/driver/gitlab/testdata/webhooks/pull_request_edited.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"object_kind": "merge_request",
"user": {
"name": "Sid Sijbrandij",
"username": "sytses",
"avatar_url": "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87?s=80&d=identicon"
},
"project": {
"id": 4861503,
"name": "hello-world",
"description": "",
"web_url": "https://gitlab.com/gitlab-org/hello-world",
"avatar_url": null,
"git_ssh_url": "[email protected]:gitlab-org/hello-world.git",
"git_http_url": "https://gitlab.com/gitlab-org/hello-world.git",
"namespace": "sytses",
"visibility_level": 0,
"path_with_namespace": "gitlab-org/hello-world",
"default_branch": "master",
"ci_config_path": null,
"homepage": "https://gitlab.com/gitlab-org/hello-world",
"url": "[email protected]:gitlab-org/hello-world.git",
"ssh_url": "[email protected]:gitlab-org/hello-world.git",
"http_url": "https://gitlab.com/gitlab-org/hello-world.git"
},
"object_attributes": {
"assignee_id": null,
"author_id": 51764,
"created_at": "2017-12-10 17:01:11 UTC",
"deleted_at": null,
"description": "adding build instructions to readme",
"head_pipeline_id": null,
"id": 6632669,
"iid": 1,
"last_edited_at": null,
"last_edited_by_id": null,
"merge_commit_sha": null,
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "0"
},
"merge_status": "unchecked",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "feature",
"source_project_id": 4861503,
"state": "opened",
"target_branch": "master",
"target_project_id": 4861503,
"time_estimate": 0,
"title": "update readme",
"updated_at": "2017-12-10 17:01:11 UTC",
"updated_by_id": null,
"url": "https://gitlab.com/gitlab-org/hello-world/merge_requests/1",
"source": {
"id": 4861503,
"name": "hello-world",
"description": "",
"web_url": "https://gitlab.com/gitlab-org/hello-world",
"avatar_url": null,
"git_ssh_url": "[email protected]:gitlab-org/hello-world.git",
"git_http_url": "https://gitlab.com/gitlab-org/hello-world.git",
"namespace": "sytses",
"visibility_level": 0,
"path_with_namespace": "gitlab-org/hello-world",
"default_branch": "master",
"ci_config_path": null,
"homepage": "https://gitlab.com/gitlab-org/hello-world",
"url": "[email protected]:gitlab-org/hello-world.git",
"ssh_url": "[email protected]:gitlab-org/hello-world.git",
"http_url": "https://gitlab.com/gitlab-org/hello-world.git"
},
"target": {
"id": 4861503,
"name": "hello-world",
"description": "",
"web_url": "https://gitlab.com/gitlab-org/hello-world",
"avatar_url": null,
"git_ssh_url": "[email protected]:gitlab-org/hello-world.git",
"git_http_url": "https://gitlab.com/gitlab-org/hello-world.git",
"namespace": "sytses",
"visibility_level": 0,
"path_with_namespace": "gitlab-org/hello-world",
"default_branch": "master",
"ci_config_path": null,
"homepage": "https://gitlab.com/gitlab-org/hello-world",
"url": "[email protected]:gitlab-org/hello-world.git",
"ssh_url": "[email protected]:gitlab-org/hello-world.git",
"http_url": "https://gitlab.com/gitlab-org/hello-world.git"
},
"last_commit": {
"id": "c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"message": "update readme\n",
"timestamp": "2017-12-10T08:28:36-08:00",
"url": "https://gitlab.com/gitlab-org/hello-world/commit/c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"author": {
"name": "Sid Sijbrandij",
"email": "[email protected]"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"human_total_time_spent": null,
"human_time_estimate": null,
"action": "update"
},
"labels": [{
"id": 206,
"title": "API",
"color": "#ffffff",
"project_id": 14,
"created_at": "2013-12-03T17:15:43Z",
"updated_at": "2013-12-03T17:15:43Z",
"template": false,
"description": "API related issues",
"type": "ProjectLabel",
"group_id": 41
}],
"changes": {
"labels": {
"previous": [{
"id": 206,
"title": "API",
"color": "#ffffff",
"project_id": 14,
"created_at": "2013-12-03T17:15:43Z",
"updated_at": "2013-12-03T17:15:43Z",
"template": false,
"description": "API related issues",
"type": "ProjectLabel",
"group_id": 41
}],
"current": [{
"id": 205,
"title": "Platform",
"color": "#123123",
"project_id": 14,
"created_at": "2013-12-03T17:15:43Z",
"updated_at": "2013-12-03T17:15:43Z",
"template": false,
"description": "Platform related issues",
"type": "ProjectLabel",
"group_id": 41
}]
}
},
"repository": {
"name": "hello-world",
"url": "[email protected]:gitlab-org/hello-world.git",
"description": "",
"homepage": "https://gitlab.com/gitlab-org/hello-world"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"Action": "updated",
"Repo": {
"ID": "4861503",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
"Private": false,
"Clone": "https://gitlab.com/gitlab-org/hello-world.git",
"CloneSSH": "[email protected]:gitlab-org/hello-world.git",
"Link": "https://gitlab.com/gitlab-org/hello-world",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"PullRequest": {
"Number": 1,
"Title": "update readme",
"Body": "adding build instructions to readme",
"State": "open",
"Sha": "c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"Ref": "refs/merge-requests/1/head",
"Base": {
"Ref": "master",
"Repo": {
"ID": "4861503",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
"Private": false,
"Clone": "https://gitlab.com/gitlab-org/hello-world.git",
"CloneSSH": "[email protected]:gitlab-org/hello-world.git",
"Link": "https://gitlab.com/gitlab-org/hello-world",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
}
},
"Head": {
"Sha": "c4c79227ed610f1151f05bbc5be33b4f340d39c8",
"Repo": {
"ID": "4861503",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
"Private": false,
"Clone": "https://gitlab.com/gitlab-org/hello-world.git",
"CloneSSH": "[email protected]:gitlab-org/hello-world.git",
"Link": "https://gitlab.com/gitlab-org/hello-world",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
}
},
"Source": "feature",
"Target": "master",
"Fork": "sytses/hello-world",
"Link": "https://gitlab.com/gitlab-org/hello-world/merge_requests/1",
"Closed": false,
"Merged": false,
"Author": {
"Login": "sytses",
"Name": "Sid Sijbrandij",
"Email": "",
"Avatar": "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87?s=80\u0026d=identicon"
},
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
},
"Sender": {
"Login": "sytses",
"Name": "Sid Sijbrandij",
"Email": "",
"Avatar": "https://secure.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87?s=80\u0026d=identicon"
}
}
4 changes: 2 additions & 2 deletions scm/driver/gitlab/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func convertTagHook(src *pushHook) *scm.TagHook {
}

func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
action := scm.ActionSync
action := scm.ActionUpdate
switch src.ObjectAttributes.Action {
case "open":
action = scm.ActionOpen
Expand All @@ -225,7 +225,7 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
case "merge":
action = scm.ActionMerge
case "update":
action = scm.ActionSync
action = scm.ActionUpdate
}
fork := scm.Join(
src.ObjectAttributes.Source.Namespace,
Expand Down
12 changes: 6 additions & 6 deletions scm/driver/gitlab/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func TestWebhooks(t *testing.T) {
after: "testdata/webhooks/pull_request_create.json.golden",
obj: new(scm.PullRequestHook),
},
// {
// event: "Merge Request Hook",
// before: "testdata/webhooks/pull_request_edited.json",
// after: "testdata/webhooks/pull_request_edited.json.golden",
// obj: new(scm.PullRequestHook),
// },
{
event: "Merge Request Hook",
before: "testdata/webhooks/pull_request_edited.json",
after: "testdata/webhooks/pull_request_edited.json.golden",
obj: new(scm.PullRequestHook),
},
// {
// event: "Merge Request Hook",
// before: "testdata/webhooks/pull_request_synchronized.json",
Expand Down

0 comments on commit 74cab80

Please sign in to comment.