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

Feature/event common utils #281

Merged
merged 14 commits into from
Apr 29, 2021
Merged

Feature/event common utils #281

merged 14 commits into from
Apr 29, 2021

Conversation

warber
Copy link
Contributor

@warber warber commented Apr 9, 2021

This PR contains utilities for creating Keptn Cloud Events as well as several other utility functions

pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
pkg/common/eventutils/eventutils.go Outdated Show resolved Hide resolved
@@ -0,0 +1,5 @@
package strutils

func Stringp(str string) *string {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function Stringp should have comment or be unexported

return keptnEvent, nil
}

func IsTaskEventType(eventType string) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function IsTaskEventType should have comment or be unexported

return len(parts) == 5
}

func IsSequenceEventType(eventType string) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function IsSequenceEventType should have comment or be unexported

return len(parts) == 6
}

func IsValidEventType(eventType string) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function IsValidEventType should have comment or be unexported

return IsSequenceEventType(eventType) || IsTaskEventType(eventType)
}

func ParseSequenceEventType(sequenceTriggeredEventType string) (string, string, string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ParseSequenceEventType should have comment or be unexported

return "", "", "", fmt.Errorf("%s is not a valid keptn sequence triggered event type", sequenceTriggeredEventType)
}

func ParseTaskEventType(taskEventType string) (string, string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ParseTaskEventType should have comment or be unexported

return parts[3], parts[4], nil
}

func ParseEventKind(eventType string) (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ParseEventKind should have comment or be unexported

return parts[len(parts)-1], nil
}

func ParseEventTypeWithoutKind(eventType string) (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ParseEventTypeWithoutKind should have comment or be unexported

return strings.TrimSuffix(eventType, "."+kind), nil
}

func ReplaceEventTypeKind(eventType, newKind string) (string, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ReplaceEventTypeKind should have comment or be unexported

@@ -176,3 +265,109 @@ func Decode(in, out interface{}) error {
func EventDataAs(in models.KeptnContextExtendedCE, out interface{}) error {
return Decode(in.Data, out)
}

func KeptnEvent(eventType string, payload interface{}) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function KeptnEvent should have comment or be unexported

return &KeptnEventBuilder{ce}
}

type KeptnEventBuilder struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported type KeptnEventBuilder should have comment or be unexported

models.KeptnContextExtendedCE
}

func (eb *KeptnEventBuilder) Build() (models.KeptnContextExtendedCE, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.Build should have comment or be unexported

return eb.KeptnContextExtendedCE, nil
}

func (eb *KeptnEventBuilder) WithKeptnSpecVersion(keptnSpecVersion string) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.WithKeptnSpecVersion should have comment or be unexported

return eb
}

func (eb *KeptnEventBuilder) WithKeptnContext(keptnContext string) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.WithKeptnContext should have comment or be unexported

return eb
}

func (eb *KeptnEventBuilder) WithSource(source string) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.WithSource should have comment or be unexported

return eb
}

func (eb *KeptnEventBuilder) WithTriggeredID(triggeredID string) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.WithTriggeredID should have comment or be unexported

return eb
}

func (eb *KeptnEventBuilder) WithID(id string) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported method KeptnEventBuilder.WithID should have comment or be unexported

return eb
}

func ToCloudEvent(keptnEvent models.KeptnContextExtendedCE) cloudevents.Event {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ToCloudEvent should have comment or be unexported

return event
}

func ToKeptnEvent(event cloudevents.Event) (models.KeptnContextExtendedCE, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function ToKeptnEvent should have comment or be unexported


import "os"

// GetOSEnv retrieves the value of the environment variable named by the key.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
comment on exported function GetOSEnvOrDefault should be of the form "GetOSEnvOrDefault ..."


const keptnTimeFormat = "2006-01-02T15:04:05.000Z"

func GetKeptnTimeStamp(timestamp time.Time) string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function GetKeptnTimeStamp should have comment or be unexported

@@ -176,3 +266,105 @@ func Decode(in, out interface{}) error {
func EventDataAs(in models.KeptnContextExtendedCE, out interface{}) error {
return Decode(in.Data, out)
}

func KeptnEvent(eventType string, source string, payload interface{}) *KeptnEventBuilder {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
exported function KeptnEvent should have comment or be unexported

warber added 3 commits April 26, 2021 10:49
Signed-off-by: warber <[email protected]>
This reverts commit ac6c097

Signed-off-by: warber <[email protected]>
Signed-off-by: warber <[email protected]>
@warber warber marked this pull request as ready for review April 29, 2021 05:58
Signed-off-by: warber <[email protected]>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -0,0 +1,6 @@
package strutils

// Sringp returns a string pointer of the given string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[golint] reported by reviewdog 🐶
comment on exported function Stringp should be of the form "Stringp ..."

Copy link
Member

@bacherfl bacherfl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@warber warber merged commit 086f16f into master Apr 29, 2021
@warber warber deleted the feature/event-common-utils branch April 29, 2021 12:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants