Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Gitlab Autoplan wont trigger when switching Draft to Ready #3568

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
154 changes: 154 additions & 0 deletions server/events/testdata/gitlab-merge-request-event-mark-as-ready.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]: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": "[email protected]:sheather/test.git",
"ssh_url": "[email protected]: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": "[email protected]: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": "[email protected]:sheather/test.git",
"ssh_url": "[email protected]: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": "[email protected]: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": "[email protected]:sheather/test.git",
"ssh_url": "[email protected]: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": "[email protected]: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]"
}
]
}