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 7f7d690..cce3a6e 100644 --- a/gitlab/payload.go +++ b/gitlab/payload.go @@ -37,8 +37,8 @@ type IssueEventPayload struct { Project Project `json:"project"` Repository Repository `json:"repository"` ObjectAttributes ObjectAttributes `json:"object_attributes"` - Assignee Assignee `json:"assignee"` - Assignees []Assignee `json:"assignees"` + Assignee User `json:"assignee"` + Assignees []User `json:"assignees"` Changes Changes `json:"changes"` } @@ -59,17 +59,13 @@ type MergeRequestEventPayload struct { Project Project `json:"project"` Repository Repository `json:"repository"` Labels []Label `json:"labels"` - Assignees []Assignee `json:"assignees"` - Reviewers []Reviewers `json:"reviewers"` + Assignees []User `json:"assignees"` + Reviewers []User `json:"reviewers"` } // Reviewers contains all of the GitLab reviewers information -type Reviewers struct { - ID int `json:"id"` - Name string `json:"name"` - Username string `json:"username"` - AvatarURL string `json:"avatar_url"` -} +// Deprecated: Use User instead +type Reviewers User // PushEventPayload contains the information for GitLab's push event type PushEventPayload struct { @@ -728,7 +724,8 @@ type ObjectAttributes struct { Source Source `json:"source"` Target Target `json:"target"` LastCommit LastCommit `json:"last_commit"` - Assignee Assignee `json:"assignee"` + Assignee User `json:"assignee"` + Draft bool `json:"draft"` } // PipelineObjectAttributes contains pipeline specific GitLab object attributes information @@ -800,18 +797,13 @@ type MergeRequest struct { Target Target `json:"target"` LastCommit LastCommit `json:"last_commit"` WorkInProgress bool `json:"work_in_progress"` - Assignee Assignee `json:"assignee"` + Assignee User `json:"assignee"` URL string `json:"url"` } // Assignee contains all of the GitLab assignee information -type Assignee struct { - ID int64 `json:"id"` - Name string `json:"name"` - Username string `json:"username"` - AvatarURL string `json:"avatar_url"` - Email string `json:"email"` -} +// Deprecated: Use User instead +type Assignee User // StDiff contains all of the GitLab diff information type StDiff struct { @@ -879,13 +871,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"` } -// LabelChanges contains changes in labels assocatiated with a GitLab issue or MR -type LabelChanges struct { - Previous []Label `json:"previous"` - Current []Label `json:"current"` +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 +} + +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 @@ -901,3 +916,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..65ce9b5 100644 --- a/testdata/gitlab/merge-request-event.json +++ b/testdata/gitlab/merge-request-event.json @@ -50,6 +50,7 @@ "milestone_id": null, "state_id": 1, "state": "opened", + "draft": false, "blocking_discussions_resolved": true, "work_in_progress": false, "first_contribution": true, @@ -133,10 +134,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 +187,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": [