From ad10ec65af4ec0a53be6f5f56ea993726fd48d0a Mon Sep 17 00:00:00 2001 From: EmilLuta Date: Tue, 12 Nov 2019 20:38:27 +0200 Subject: [PATCH 1/2] Update current gitlab merge request event payload Gitlab Merge Request event has been updated at an unknown time. I have updated the current interface to work with the version we have now, 12th of November 2019. I have also updated the testdata with the official event from docs: https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#merge-request-events --- gitlab/payload.go | 28 +++++------------------- testdata/gitlab/merge-request-event.json | 12 +++++++--- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/gitlab/payload.go b/gitlab/payload.go index c2c2b8a..332781f 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -488,27 +488,11 @@ type Author struct { Email string `json:"email"` } -// Changes contains all changes associated with a GitLab issue or MR -type Changes struct { - LabelChanges LabelChanges `json:"labels"` -} - -// LabelChanges contains changes in labels assocatiated with a GitLab issue or MR -type LabelChanges struct { - Previous []Label `json:"previous"` - Current []Label `json:"current"` -} +// Changes contains all the changes in a MergeRequest +type Changes map[string]Change -// Label contains all of the GitLab label information -type Label struct { - ID int64 `json:"id"` - Title string `json:"title"` - Color string `json:"color"` - ProjectID int64 `json:"project_id"` - CreatedAt customTime `json:"created_at"` - UpdatedAt customTime `json:"updated_at"` - Template bool `json:"template"` - Description string `json:"description"` - Type string `json:"type"` - GroupID int64 `json:"group_id"` +// Change is an individual change of a field in a MergeRequest +type Change struct { + Current interface{} + Previous interface{} } diff --git a/testdata/gitlab/merge-request-event.json b/testdata/gitlab/merge-request-event.json index eb890fb..3a07e43 100644 --- a/testdata/gitlab/merge-request-event.json +++ b/testdata/gitlab/merge-request-event.json @@ -108,8 +108,14 @@ "group_id": 41 }], "changes": { - "updated_by_id": [null, 1], - "updated_at": ["2017-09-15 16:50:55 UTC", "2017-09-15 16:52:00 UTC"], + "updated_by_id": { + "previous": null, + "current": 1 + }, + "updated_at": { + "previous": "2017-09-15 16:50:55 UTC", + "current":"2017-09-15 16:52:00 UTC" + }, "labels": { "previous": [{ "id": 206, @@ -137,4 +143,4 @@ }] } } -} \ No newline at end of file +} From 1b6f1b0ccf154aa2327e4feb80c167e4038bbb48 Mon Sep 17 00:00:00 2001 From: EmilLuta Date: Tue, 12 Nov 2019 22:27:33 +0200 Subject: [PATCH 2/2] Add JSON unmarshalling shorthand for Change --- gitlab/payload.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab/payload.go b/gitlab/payload.go index 332781f..e4ed37d 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -493,6 +493,6 @@ type Changes map[string]Change // Change is an individual change of a field in a MergeRequest type Change struct { - Current interface{} - Previous interface{} + Current interface{} `json:"current"` + Previous interface{} `json:"previous"` }