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

Commit

Permalink
fix lint (use const for eventObjectKind)
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Oct 26, 2021
1 parent 4e9851d commit cdf6f67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
16 changes: 11 additions & 5 deletions event_parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ const (
noteableTypeSnippet = "Snippet"
)

const (
eventObjectKindPush = "push"
eventObjectKindTagPush = "tag_push"
eventObjectKindMergeRequest = "merge_request"
)

type noteEvent struct {
ObjectKind string `json:"object_kind"`
ObjectAttributes struct {
Expand Down Expand Up @@ -124,9 +130,9 @@ func ParseSystemhook(payload []byte) (event interface{}, err error) {
}

switch e.EventName {
case "push":
case eventObjectKindPush:
event = &PushSystemEvent{}
case "tag_push":
case eventObjectKindTagPush:
event = &TagPushSystemEvent{}
case "repository_update":
event = &RepositoryUpdateSystemEvent{}
Expand Down Expand Up @@ -254,11 +260,11 @@ func ParseWebhook(eventType EventType, payload []byte) (event interface{}, err e
return nil, err
}
switch service.ObjectKind {
case "push":
case eventObjectKindPush:
event = &PushEvent{}
case "tag_push":
case eventObjectKindTagPush:
event = &TagEvent{}
case "merge_request":
case eventObjectKindMergeRequest:
event = &MergeEvent{}
default:
return nil, fmt.Errorf("unexpected service type %s", service.ObjectKind)
Expand Down
6 changes: 3 additions & 3 deletions event_parsing_systemhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestParseSystemhookPush(t *testing.T) {
if !ok {
t.Errorf("Expected PushSystemHookEvent, but parsing produced %T", parsedEvent)
}
assert.Equal(t, "push", event.EventName)
assert.Equal(t, eventObjectKindPush, event.EventName)
}

func TestParseSystemhookTagPush(t *testing.T) {
Expand All @@ -49,7 +49,7 @@ func TestParseSystemhookTagPush(t *testing.T) {
if !ok {
t.Errorf("Expected TagPushSystemHookEvent, but parsing produced %T", parsedEvent)
}
assert.Equal(t, "tag_push", event.EventName)
assert.Equal(t, eventObjectKindTagPush, event.EventName)
}

func TestParseSystemhookMergeRequest(t *testing.T) {
Expand All @@ -64,7 +64,7 @@ func TestParseSystemhookMergeRequest(t *testing.T) {
if !ok {
t.Errorf("Expected MergeRequestSystemHookEvent, but parsing produced %T", parsedEvent)
}
assert.Equal(t, "merge_request", event.ObjectKind)
assert.Equal(t, eventObjectKindMergeRequest, event.ObjectKind)
}

func TestParseSystemhookRepositoryUpdate(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions event_parsing_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ func TestParsePushHook(t *testing.T) {
t.Errorf("Expected PushEvent, but parsing produced %T", parsedEvent)
}

if event.ObjectKind != "push" {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "push")
if event.ObjectKind != eventObjectKindPush {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, eventObjectKindPush)
}

if event.ProjectID != 15 {
Expand Down Expand Up @@ -373,8 +373,8 @@ func TestParseTagHook(t *testing.T) {
t.Errorf("Expected TagEvent, but parsing produced %T", parsedEvent)
}

if event.ObjectKind != "tag_push" {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "tag_push")
if event.ObjectKind != eventObjectKindTagPush {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, eventObjectKindTagPush)
}

if event.ProjectID != 1 {
Expand Down
4 changes: 2 additions & 2 deletions event_webhook_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func TestMergeEventUnmarshalFromGroup(t *testing.T) {
t.Errorf("Group Merge Event is null")
}

if event.ObjectKind != "merge_request" {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, "merge_request")
if event.ObjectKind != eventObjectKindMergeRequest {
t.Errorf("ObjectKind is %v, want %v", event.ObjectKind, eventObjectKindMergeRequest)
}

if event.User.Username != expectedUsername {
Expand Down

0 comments on commit cdf6f67

Please sign in to comment.