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

New events webhooks #1913

Merged
merged 3 commits into from
Apr 18, 2024
Merged
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
120 changes: 63 additions & 57 deletions group_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,29 @@ import (
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#list-group-hooks
type GroupHook struct {
ID int `json:"id"`
URL string `json:"url"`
GroupID int `json:"group_id"`
PushEvents bool `json:"push_events"`
PushEventsBranchFilter string `json:"push_events_branch_filter"`
IssuesEvents bool `json:"issues_events"`
ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
ConfidentialNoteEvents bool `json:"confidential_note_events"`
MergeRequestsEvents bool `json:"merge_requests_events"`
TagPushEvents bool `json:"tag_push_events"`
NoteEvents bool `json:"note_events"`
JobEvents bool `json:"job_events"`
PipelineEvents bool `json:"pipeline_events"`
WikiPageEvents bool `json:"wiki_page_events"`
DeploymentEvents bool `json:"deployment_events"`
ReleasesEvents bool `json:"releases_events"`
SubGroupEvents bool `json:"subgroup_events"`
EnableSSLVerification bool `json:"enable_ssl_verification"`
AlertStatus string `json:"alert_status"`
CreatedAt *time.Time `json:"created_at"`
CustomWebhookTemplate string `json:"custom_webhook_template"`
ID int `json:"id"`
URL string `json:"url"`
GroupID int `json:"group_id"`
PushEvents bool `json:"push_events"`
PushEventsBranchFilter string `json:"push_events_branch_filter"`
IssuesEvents bool `json:"issues_events"`
ConfidentialIssuesEvents bool `json:"confidential_issues_events"`
ConfidentialNoteEvents bool `json:"confidential_note_events"`
MergeRequestsEvents bool `json:"merge_requests_events"`
TagPushEvents bool `json:"tag_push_events"`
NoteEvents bool `json:"note_events"`
JobEvents bool `json:"job_events"`
PipelineEvents bool `json:"pipeline_events"`
WikiPageEvents bool `json:"wiki_page_events"`
DeploymentEvents bool `json:"deployment_events"`
ReleasesEvents bool `json:"releases_events"`
SubGroupEvents bool `json:"subgroup_events"`
MemberEvents bool `json:"member_events"`
EnableSSLVerification bool `json:"enable_ssl_verification"`
AlertStatus string `json:"alert_status"`
CreatedAt *time.Time `json:"created_at"`
CustomWebhookTemplate string `json:"custom_webhook_template"`
ResourceAccessTokenEvents bool `json:"resource_access_token_events"`
}

// ListGroupHooksOptions represents the available ListGroupHooks() options.
Expand Down Expand Up @@ -106,24 +108,26 @@ func (s *GroupsService) GetGroupHook(pid interface{}, hook int, options ...Reque
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#add-group-hook
type AddGroupHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"`
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
MemberEvents *bool `url:"member_events,omitempty" json:"member_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
ResourceAccessTokenEvents *bool `url:"resource_access_token_events,omitempty" json:"resource_access_token_events,omitempty"`
CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"`
}

// AddGroupHook create a new group scoped webhook.
Expand Down Expand Up @@ -155,24 +159,26 @@ func (s *GroupsService) AddGroupHook(gid interface{}, opt *AddGroupHookOptions,
// GitLab API docs:
// https://docs.gitlab.com/ee/api/groups.html#edit-group-hook
type EditGroupHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"`
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
PushEventsBranchFilter *string `url:"push_events_branch_filter,omitempty" json:"push_events_branch_filter,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
ConfidentialIssuesEvents *bool `url:"confidential_issues_events,omitempty" json:"confidential_issues_events,omitempty"`
ConfidentialNoteEvents *bool `url:"confidential_note_events,omitempty" json:"confidential_note_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
JobEvents *bool `url:"job_events,omitempty" json:"job_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
DeploymentEvents *bool `url:"deployment_events,omitempty" json:"deployment_events,omitempty"`
ReleasesEvents *bool `url:"releases_events,omitempty" json:"releases_events,omitempty"`
SubGroupEvents *bool `url:"subgroup_events,omitempty" json:"subgroup_events,omitempty"`
MemberEvents *bool `url:"member_events,omitempty" json:"member_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
ResourceAccessTokenEvents *bool `url:"resource_access_token_events,omitempty" json:"resource_access_token_events,omitempty"`
CustomWebhookTemplate *string `url:"custom_webhook_template,omitempty" json:"custom_webhook_template,omitempty"`
}

// EditGroupHook edits a hook for a specified group.
Expand Down
180 changes: 98 additions & 82 deletions group_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func TestListGroupHooks(t *testing.T) {
"deployment_events": true,
"releases_events": true,
"subgroup_events": true,
"member_events": true,
"enable_ssl_verification": true,
"alert_status": "executable",
"created_at": "2012-10-12T17:04:47Z"
"created_at": "2012-10-12T17:04:47Z",
"resource_access_token_events": true
}
]`)
})
Expand All @@ -62,25 +64,27 @@ func TestListGroupHooks(t *testing.T) {

datePointer := time.Date(2012, 10, 12, 17, 4, 47, 0, time.UTC)
want := []*GroupHook{{
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
EnableSSLVerification: true,
AlertStatus: "executable",
CreatedAt: &datePointer,
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
MemberEvents: true,
EnableSSLVerification: true,
AlertStatus: "executable",
CreatedAt: &datePointer,
ResourceAccessTokenEvents: true,
}}

if !reflect.DeepEqual(groupHooks, want) {
Expand Down Expand Up @@ -111,9 +115,11 @@ func TestGetGroupHook(t *testing.T) {
"deployment_events": true,
"releases_events": true,
"subgroup_events": true,
"member_events": true,
"enable_ssl_verification": true,
"alert_status": "executable",
"created_at": "2012-10-12T17:04:47Z"
"created_at": "2012-10-12T17:04:47Z",
"resource_access_token_events": true
}`)
})

Expand All @@ -124,25 +130,27 @@ func TestGetGroupHook(t *testing.T) {

datePointer := time.Date(2012, 10, 12, 17, 4, 47, 0, time.UTC)
want := &GroupHook{
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
EnableSSLVerification: true,
AlertStatus: "executable",
CreatedAt: &datePointer,
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
MemberEvents: true,
EnableSSLVerification: true,
AlertStatus: "executable",
CreatedAt: &datePointer,
ResourceAccessTokenEvents: true,
}

if !reflect.DeepEqual(groupHook, want) {
Expand Down Expand Up @@ -173,9 +181,11 @@ func TestAddGroupHook(t *testing.T) {
"deployment_events": true,
"releases_events": true,
"subgroup_events": true,
"member_events": true,
"enable_ssl_verification": true,
"created_at": "2012-10-12T17:04:47Z",
"custom_webhook_template": "addTestValue"
"custom_webhook_template": "addTestValue",
"resource_access_token_events": true
}`)
})

Expand All @@ -191,26 +201,28 @@ func TestAddGroupHook(t *testing.T) {

datePointer := time.Date(2012, 10, 12, 17, 4, 47, 0, time.UTC)
want := &GroupHook{
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
ConfidentialNoteEvents: false,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
EnableSSLVerification: true,
CreatedAt: &datePointer,
CustomWebhookTemplate: "addTestValue",
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
ConfidentialNoteEvents: false,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
MemberEvents: true,
EnableSSLVerification: true,
CreatedAt: &datePointer,
CustomWebhookTemplate: "addTestValue",
ResourceAccessTokenEvents: true,
}

if !reflect.DeepEqual(groupHooks, want) {
Expand Down Expand Up @@ -241,9 +253,11 @@ func TestEditGroupHook(t *testing.T) {
"deployment_events": true,
"releases_events": true,
"subgroup_events": true,
"member_events": true,
"enable_ssl_verification": true,
"created_at": "2012-10-12T17:04:47Z",
"custom_webhook_template": "testValue"
"custom_webhook_template": "testValue",
"resource_access_token_events": true
}`)
})

Expand All @@ -259,26 +273,28 @@ func TestEditGroupHook(t *testing.T) {

datePointer := time.Date(2012, 10, 12, 17, 4, 47, 0, time.UTC)
want := &GroupHook{
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
ConfidentialNoteEvents: false,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
EnableSSLVerification: true,
CreatedAt: &datePointer,
CustomWebhookTemplate: "testValue",
ID: 1,
URL: "http://example.com/hook",
GroupID: 3,
PushEvents: true,
PushEventsBranchFilter: "main",
IssuesEvents: true,
ConfidentialIssuesEvents: true,
ConfidentialNoteEvents: false,
MergeRequestsEvents: true,
TagPushEvents: true,
NoteEvents: true,
JobEvents: true,
PipelineEvents: true,
WikiPageEvents: true,
DeploymentEvents: true,
ReleasesEvents: true,
SubGroupEvents: true,
MemberEvents: true,
EnableSSLVerification: true,
CreatedAt: &datePointer,
CustomWebhookTemplate: "testValue",
ResourceAccessTokenEvents: true,
}

if !reflect.DeepEqual(groupHooks, want) {
Expand Down
Loading
Loading