Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Move type to types.go
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Oct 28, 2024
1 parent 5e67378 commit 10afd04
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 48 deletions.
23 changes: 2 additions & 21 deletions group_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,30 +229,11 @@ func (s *GroupsService) DeleteGroupHook(pid interface{}, hook int, options ...Re
return s.client.Do(req, nil)
}

// GroupHookTriggerType represents the type of event to trigger for a group hook test.
type GroupHookTriggerType string

// List of available group hook trigger types.
const (
GroupHookTriggerPush GroupHookTriggerType = "push_events"
GroupHookTriggerTagPush GroupHookTriggerType = "tag_push_events"
GroupHookTriggerIssue GroupHookTriggerType = "issues_events"
GroupHookTriggerConfidentialIssue GroupHookTriggerType = "confidential_issues_events"
GroupHookTriggerNote GroupHookTriggerType = "note_events"
GroupHookTriggerMergeRequest GroupHookTriggerType = "merge_requests_events"
GroupHookTriggerJob GroupHookTriggerType = "job_events"
GroupHookTriggerPipeline GroupHookTriggerType = "pipeline_events"
GroupHookTriggerWikiPage GroupHookTriggerType = "wiki_page_events"
GroupHookTriggerRelease GroupHookTriggerType = "releases_events"
GroupHookTriggerEmoji GroupHookTriggerType = "emoji_events"
GroupHookTriggerResourceAccessToken GroupHookTriggerType = "resource_access_token_events"
)

// TriggerTestGroupHook triggers a test hook for a specified group.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_hooks.html#trigger-a-test-group-hook
func (s *GroupsService) TriggerTestGroupHook(pid interface{}, hook int, trigger GroupHookTriggerType, options ...RequestOptionFunc) (*Response, error) {
// https://docs.gitlab.com/ee/api/group_webhooks.html#trigger-a-test-group-hook
func (s *GroupsService) TriggerTestGroupHook(pid interface{}, hook int, trigger GroupHookTrigger, options ...RequestOptionFunc) (*Response, error) {
group, err := parseID(pid)
if err != nil {
return nil, err
Expand Down
54 changes: 27 additions & 27 deletions group_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,44 +374,44 @@ func TestTriggerTestGroupHook(t *testing.T) {
})

tests := []struct {
name string
groupID interface{}
hookID int
triggerType GroupHookTriggerType
wantErr bool
wantStatus int
wantErrMsg string
name string
groupID interface{}
hookID int
trigger GroupHookTrigger
wantErr bool
wantStatus int
wantErrMsg string
}{
{
name: "Valid trigger",
groupID: 1,
hookID: 1,
triggerType: GroupHookTriggerPush,
wantErr: false,
wantStatus: http.StatusCreated,
name: "Valid trigger",
groupID: 1,
hookID: 1,
trigger: GroupHookTriggerPush,
wantErr: false,
wantStatus: http.StatusCreated,
},
{
name: "Invalid group ID",
groupID: "invalid",
hookID: 1,
triggerType: GroupHookTriggerPush,
wantErr: true,
wantStatus: http.StatusNotFound,
name: "Invalid group ID",
groupID: "invalid",
hookID: 1,
trigger: GroupHookTriggerPush,
wantErr: true,
wantStatus: http.StatusNotFound,
},
{
name: "Invalid trigger type",
groupID: 1,
hookID: 1,
triggerType: "invalid_trigger",
wantErr: true,
wantStatus: http.StatusBadRequest,
wantErrMsg: "trigger does not have a valid value",
name: "Invalid trigger type",
groupID: 1,
hookID: 1,
trigger: "invalid_trigger",
wantErr: true,
wantStatus: http.StatusBadRequest,
wantErrMsg: "trigger does not have a valid value",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp, err := client.Groups.TriggerTestGroupHook(tt.groupID, tt.hookID, tt.triggerType)
resp, err := client.Groups.TriggerTestGroupHook(tt.groupID, tt.hookID, tt.trigger)

if tt.wantErr {
assert.Error(t, err)
Expand Down
20 changes: 20 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,26 @@ func GenericPackageStatus(v GenericPackageStatusValue) *GenericPackageStatusValu
return Ptr(v)
}

// GroupHookTrigger represents the type of event to trigger for a group
// hook test.
type GroupHookTrigger string

// List of available group hook trigger types.
const (
GroupHookTriggerPush GroupHookTrigger = "push_events"
GroupHookTriggerTagPush GroupHookTrigger = "tag_push_events"
GroupHookTriggerIssue GroupHookTrigger = "issues_events"
GroupHookTriggerConfidentialIssue GroupHookTrigger = "confidential_issues_events"
GroupHookTriggerNote GroupHookTrigger = "note_events"
GroupHookTriggerMergeRequest GroupHookTrigger = "merge_requests_events"
GroupHookTriggerJob GroupHookTrigger = "job_events"
GroupHookTriggerPipeline GroupHookTrigger = "pipeline_events"
GroupHookTriggerWikiPage GroupHookTrigger = "wiki_page_events"
GroupHookTriggerRelease GroupHookTrigger = "releases_events"
GroupHookTriggerEmoji GroupHookTrigger = "emoji_events"
GroupHookTriggerResourceAccessToken GroupHookTrigger = "resource_access_token_events"
)

// ISOTime represents an ISO 8601 formatted date.
type ISOTime time.Time

Expand Down

0 comments on commit 10afd04

Please sign in to comment.