diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index dac0a63..16a5e0c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -23,7 +23,7 @@ jobs: name: Test strategy: matrix: - go-version: [1.17.x, 1.18.x, 1.20.x] + go-version: [1.18.x, 1.20.x] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/gitlab/payload.go b/gitlab/payload.go index 42fde5c..e9d073a 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -870,13 +870,36 @@ type Author struct { // Changes contains all changes associated with a GitLab issue or MR type Changes struct { - LabelChanges LabelChanges `json:"labels"` + LabelChanges *ListChange[Label] `json:"labels"` + Draft *PropChange[bool] `json:"draft"` + StateId *PropChange[IssuableStateID] `json:"state_id"` + Assignees *ListChange[User] `json:"assignees"` + Reviewers *ListChange[User] `json:"reviewers"` + Title *PropChange[string] `json:"title"` + Description *PropChange[string] `json:"description"` + + UpdatedAt *PropChange[customTime] `json:"updated_at"` + UpdatedByID *PropChange[int64] `json:"updated_by_id"` + LastEditedAt *PropChange[customTime] `json:"last_edited_at"` + LastEditedByID *PropChange[int64] `json:"last_edited_by_id"` +} + +type PropChange[T comparable] struct { + Previous T `json:"previous"` + Current T `json:"current"` +} + +func (p *PropChange[T]) Was(value T) bool { + return p != nil && p.Previous == value } -// LabelChanges contains changes in labels assocatiated with a GitLab issue or MR -type LabelChanges struct { - Previous []Label `json:"previous"` - Current []Label `json:"current"` +func (p *PropChange[T]) Became(newValue T) bool { + return p != nil && p.Current == newValue +} + +type ListChange[T comparable] struct { + Previous []T `json:"previous"` + Current []T `json:"current"` } // Label contains all of the GitLab label information @@ -892,3 +915,13 @@ type Label struct { Type string `json:"type"` GroupID int64 `json:"group_id"` } + +type IssuableStateID int + +// Source: https://forum.gitlab.com/t/merge-event-state-id-meanings/47433 +const ( + StateOpened IssuableStateID = 1 + StateClosed IssuableStateID = 2 + StateMerged IssuableStateID = 3 + StateLocked IssuableStateID = 4 +) diff --git a/go.mod b/go.mod index bb0fa5a..a63b5d8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-playground/webhooks/v6 -go 1.17 +go 1.18 require ( github.com/gogits/go-gogs-client v0.0.0-20200905025246-8bb8a50cb355 diff --git a/testdata/gitlab/merge-request-event.json b/testdata/gitlab/merge-request-event.json index d873114..26e5333 100644 --- a/testdata/gitlab/merge-request-event.json +++ b/testdata/gitlab/merge-request-event.json @@ -133,10 +133,22 @@ "group_id": 41 }], "changes": { + "title": { + "previous": "MS Viewport", + "current": "MS-Viewport" + }, + "description": { + "previous": "Lorem ipsum dolor sit amet", + "current": "" + }, "updated_by_id": { "previous": null, "current": 1 }, + "draft": { + "previous": true, + "current": false + }, "updated_at": { "previous": "2017-09-15 16:50:55 UTC", "current":"2017-09-15 16:52:00 UTC" @@ -174,6 +186,28 @@ "last_edited_by_id": { "previous": null, "current": 3278533 + }, + "assignees": { + "previous": [], + "current": [ + { + "id": 6, + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } + ] + }, + "reviewers": { + "previous": [], + "current": [ + { + "id": 6, + "name": "User1", + "username": "user1", + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon" + } + ] } }, "assignees": [