Skip to content

Commit cb75564

Browse files
committed
Support other 'changes' for GitLab payloads
1 parent 7aeb478 commit cb75564

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
name: Test
2424
strategy:
2525
matrix:
26-
go-version: [1.17.x, 1.18.x, 1.20.x]
26+
go-version: [1.18.x, 1.20.x]
2727
os: [ubuntu-latest, macos-latest]
2828
runs-on: ${{ matrix.os }}
2929
steps:

gitlab/payload.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,36 @@ type Author struct {
870870

871871
// Changes contains all changes associated with a GitLab issue or MR
872872
type Changes struct {
873-
LabelChanges LabelChanges `json:"labels"`
873+
LabelChanges *ListChange[Label] `json:"labels"`
874+
Draft *PropChange[bool] `json:"draft"`
875+
StateId *PropChange[IssuableStateID] `json:"state_id"`
876+
Assignees *ListChange[User] `json:"assignees"`
877+
Reviewers *ListChange[User] `json:"reviewers"`
878+
Title *PropChange[string] `json:"title"`
879+
Description *PropChange[string] `json:"description"`
880+
881+
UpdatedAt *PropChange[customTime] `json:"updated_at"`
882+
UpdatedByID *PropChange[int64] `json:"updated_by_id"`
883+
LastEditedAt *PropChange[customTime] `json:"last_edited_at"`
884+
LastEditedByID *PropChange[int64] `json:"last_edited_by_id"`
885+
}
886+
887+
type PropChange[T comparable] struct {
888+
Previous T `json:"previous"`
889+
Current T `json:"current"`
890+
}
891+
892+
func (p *PropChange[T]) Was(value T) bool {
893+
return p != nil && p.Previous == value
874894
}
875895

876-
// LabelChanges contains changes in labels assocatiated with a GitLab issue or MR
877-
type LabelChanges struct {
878-
Previous []Label `json:"previous"`
879-
Current []Label `json:"current"`
896+
func (p *PropChange[T]) Became(newValue T) bool {
897+
return p != nil && p.Current == newValue
898+
}
899+
900+
type ListChange[T comparable] struct {
901+
Previous []T `json:"previous"`
902+
Current []T `json:"current"`
880903
}
881904

882905
// Label contains all of the GitLab label information
@@ -892,3 +915,13 @@ type Label struct {
892915
Type string `json:"type"`
893916
GroupID int64 `json:"group_id"`
894917
}
918+
919+
type IssuableStateID int
920+
921+
// Source: https://forum.gitlab.com/t/merge-event-state-id-meanings/47433
922+
const (
923+
StateOpened IssuableStateID = 1
924+
StateClosed IssuableStateID = 2
925+
StateMerged IssuableStateID = 3
926+
StateLocked IssuableStateID = 4
927+
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/go-playground/webhooks/v6
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/gogits/go-gogs-client v0.0.0-20200905025246-8bb8a50cb355

testdata/gitlab/merge-request-event.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,22 @@
133133
"group_id": 41
134134
}],
135135
"changes": {
136+
"title": {
137+
"previous": "MS Viewport",
138+
"current": "MS-Viewport"
139+
},
140+
"description": {
141+
"previous": "Lorem ipsum dolor sit amet",
142+
"current": ""
143+
},
136144
"updated_by_id": {
137145
"previous": null,
138146
"current": 1
139147
},
148+
"draft": {
149+
"previous": true,
150+
"current": false
151+
},
140152
"updated_at": {
141153
"previous": "2017-09-15 16:50:55 UTC",
142154
"current":"2017-09-15 16:52:00 UTC"
@@ -174,6 +186,28 @@
174186
"last_edited_by_id": {
175187
"previous": null,
176188
"current": 3278533
189+
},
190+
"assignees": {
191+
"previous": [],
192+
"current": [
193+
{
194+
"id": 6,
195+
"name": "User1",
196+
"username": "user1",
197+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
198+
}
199+
]
200+
},
201+
"reviewers": {
202+
"previous": [],
203+
"current": [
204+
{
205+
"id": 6,
206+
"name": "User1",
207+
"username": "user1",
208+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40\u0026d=identicon"
209+
}
210+
]
177211
}
178212
},
179213
"assignees": [

0 commit comments

Comments
 (0)