From f18c1b80df4e35c0d68cf38e94a6c4edbcceec45 Mon Sep 17 00:00:00 2001 From: X-Guardian Date: Sun, 2 Jul 2023 18:23:27 +0100 Subject: [PATCH 1/2] Fix: Gitlab Autoplan wont trigger when switching Draft to Ready --- server/events/event_parser.go | 4 +- server/events/event_parser_test.go | 4 + ...lab-merge-request-event-mark-as-ready.json | 154 ++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 server/events/testdata/gitlab-merge-request-event-mark-as-ready.json diff --git a/server/events/event_parser.go b/server/events/event_parser.go index f759a4661e..4c80918002 100644 --- a/server/events/event_parser.go +++ b/server/events/event_parser.go @@ -585,7 +585,9 @@ func (e *EventParser) ParseGithubRepo(ghRepo *github.Repository) (models.Repo, e // ParseGitlabMergeRequestUpdateEvent dives deeper into Gitlab merge request update events func (e *EventParser) ParseGitlabMergeRequestUpdateEvent(event gitlab.MergeEvent) models.PullRequestEventType { // New commit to opened MR - if len(event.ObjectAttributes.OldRev) > 0 { + if len(event.ObjectAttributes.OldRev) > 0 || + // Check for MR that has been marked as ready + (strings.HasPrefix(event.Changes.Title.Previous, "Draft:") && !strings.HasPrefix(event.Changes.Title.Current, "Draft:")) { return models.UpdatedPullEvent } diff --git a/server/events/event_parser_test.go b/server/events/event_parser_test.go index 37c189a602..ce7193b819 100644 --- a/server/events/event_parser_test.go +++ b/server/events/event_parser_test.go @@ -494,6 +494,10 @@ func TestParseGitlabMergeEvent_Update_ActionType(t *testing.T) { filename: "gitlab-merge-request-event-update-target-branch.json", exp: models.UpdatedPullEvent, }, + { + filename: "gitlab-merge-request-event-mark-as-ready.json", + exp: models.UpdatedPullEvent, + }, } for _, c := range cases { diff --git a/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json b/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json new file mode 100644 index 0000000000..72782d3565 --- /dev/null +++ b/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json @@ -0,0 +1,154 @@ +{ + "object_kind": "merge_request", + "event_type": "merge_request", + "user": { + "id": 2, + "name": "Simon Heather", + "username": "sheather", + "avatar_url": "https://secure.gravatar.com/avatar/000b3c2c6b410f2f327d6450faab4d88?s=80&d=identicon", + "email": "[REDACTED]" + }, + "project": { + "id": 2, + "name": "test", + "description": null, + "web_url": "https://gitlab.lan/sheather/test", + "avatar_url": null, + "git_ssh_url": "git@gitlab.lan:sheather/test.git", + "git_http_url": "https://gitlab.lan/sheather/test.git", + "namespace": "Simon Heather", + "visibility_level": 0, + "path_with_namespace": "sheather/test", + "default_branch": "main", + "ci_config_path": null, + "homepage": "https://gitlab.lan/sheather/test", + "url": "git@gitlab.lan:sheather/test.git", + "ssh_url": "git@gitlab.lan:sheather/test.git", + "http_url": "https://gitlab.lan/sheather/test.git" + }, + "object_attributes": { + "assignee_id": null, + "author_id": 2, + "created_at": "2023-07-02 15:59:31 UTC", + "description": "", + "head_pipeline_id": 8, + "id": 3, + "iid": 3, + "last_edited_at": null, + "last_edited_by_id": null, + "merge_commit_sha": null, + "merge_error": null, + "merge_params": { + "force_remove_source_branch": "1" + }, + "merge_status": "can_be_merged", + "merge_user_id": null, + "merge_when_pipeline_succeeds": false, + "milestone_id": 1, + "source_branch": "sheather-cloudfront-patch-92417", + "source_project_id": 2, + "state_id": 1, + "target_branch": "cloudfront", + "target_project_id": 2, + "time_estimate": 0, + "title": "Update live/aws/123456789012/develop/eu-west-2/cloudfront/main.tf", + "updated_at": "2023-07-02 17:02:07 UTC", + "updated_by_id": 2, + "url": "https://gitlab.lan/sheather/test/-/merge_requests/3", + "source": { + "id": 2, + "name": "test", + "description": null, + "web_url": "https://gitlab.lan/sheather/test", + "avatar_url": null, + "git_ssh_url": "git@gitlab.lan:sheather/test.git", + "git_http_url": "https://gitlab.lan/sheather/test.git", + "namespace": "Simon Heather", + "visibility_level": 0, + "path_with_namespace": "sheather/test", + "default_branch": "main", + "ci_config_path": null, + "homepage": "https://gitlab.lan/sheather/test", + "url": "git@gitlab.lan:sheather/test.git", + "ssh_url": "git@gitlab.lan:sheather/test.git", + "http_url": "https://gitlab.lan/sheather/test.git" + }, + "target": { + "id": 2, + "name": "test", + "description": null, + "web_url": "https://gitlab.lan/sheather/test", + "avatar_url": null, + "git_ssh_url": "git@gitlab.lan:sheather/test.git", + "git_http_url": "https://gitlab.lan/sheather/test.git", + "namespace": "Simon Heather", + "visibility_level": 0, + "path_with_namespace": "sheather/test", + "default_branch": "main", + "ci_config_path": null, + "homepage": "https://gitlab.lan/sheather/test", + "url": "git@gitlab.lan:sheather/test.git", + "ssh_url": "git@gitlab.lan:sheather/test.git", + "http_url": "https://gitlab.lan/sheather/test.git" + }, + "last_commit": { + "id": "386f281f2c9b1a3b659fc7a244ca6781174e1836", + "message": "Update main.tf", + "title": "Update main.tf", + "timestamp": "2023-07-02T16:33:22+00:00", + "url": "https://gitlab.lan/sheather/test/-/commit/386f281f2c9b1a3b659fc7a244ca6781174e1836", + "author": { + "name": "Simon Heather", + "email": "[REDACTED]" + } + }, + "work_in_progress": false, + "total_time_spent": 0, + "time_change": 0, + "human_total_time_spent": null, + "human_time_change": null, + "human_time_estimate": null, + "assignee_ids": [ + + ], + "reviewer_ids": [ + 2 + ], + "labels": [ + + ], + "state": "opened", + "blocking_discussions_resolved": true, + "first_contribution": false, + "detailed_merge_status": "ci_must_pass", + "action": "update" + }, + "labels": [ + + ], + "changes": { + "title": { + "previous": "Draft: Update live/aws/123456789012/develop/eu-west-2/cloudfront/main.tf", + "current": "Update live/aws/123456789012/develop/eu-west-2/cloudfront/main.tf" + }, + "updated_at": { + "previous": "2023-07-02 17:01:45 UTC", + "current": "2023-07-02 17:02:07 UTC" + } + }, + "repository": { + "name": "test", + "url": "git@gitlab.lan:sheather/test.git", + "description": null, + "homepage": "https://gitlab.lan/sheather/test" + }, + "reviewers": [ + { + "id": 2, + "name": "Simon Heather", + "username": "sheather", + "avatar_url": "https://secure.gravatar.com/avatar/000b3c2c6b410f2f327d6450faab4d88?s=80&d=identicon", + "email": "[REDACTED]" + } + ] + } \ No newline at end of file From 3c34d3b10d17d84b8e6fd54365019d581db93c15 Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Sun, 2 Jul 2023 19:48:35 +0100 Subject: [PATCH 2/2] Update gitlab-merge-request-event-mark-as-ready.json --- .../testdata/gitlab-merge-request-event-mark-as-ready.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json b/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json index 72782d3565..af544dee60 100644 --- a/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json +++ b/server/events/testdata/gitlab-merge-request-event-mark-as-ready.json @@ -151,4 +151,4 @@ "email": "[REDACTED]" } ] - } \ No newline at end of file + }