From cdf6f6791b71e6a58bac92c4f027aa7bd062f8a6 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 26 Oct 2021 10:16:22 +0200 Subject: [PATCH] fix lint (use const for eventObjectKind) --- event_parsing.go | 16 +++++++++++----- event_parsing_systemhook_test.go | 6 +++--- event_parsing_webhook_test.go | 8 ++++---- event_webhook_types_test.go | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/event_parsing.go b/event_parsing.go index d3cf4e2d3..5f96dcebe 100644 --- a/event_parsing.go +++ b/event_parsing.go @@ -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 { @@ -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{} @@ -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) diff --git a/event_parsing_systemhook_test.go b/event_parsing_systemhook_test.go index 39cdb6838..e61cfe2b3 100644 --- a/event_parsing_systemhook_test.go +++ b/event_parsing_systemhook_test.go @@ -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) { @@ -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) { @@ -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) { diff --git a/event_parsing_webhook_test.go b/event_parsing_webhook_test.go index 6ab098ec2..7c83b716c 100644 --- a/event_parsing_webhook_test.go +++ b/event_parsing_webhook_test.go @@ -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 { @@ -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 { diff --git a/event_webhook_types_test.go b/event_webhook_types_test.go index 9fd059b78..7f6d0eeb6 100644 --- a/event_webhook_types_test.go +++ b/event_webhook_types_test.go @@ -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 {