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

Update GitLab payloads #194

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 49 additions & 24 deletions gitlab/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions testdata/gitlab/merge-request-event.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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": [
Expand Down
Loading