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

Commit

Permalink
feat: Add --git-commit-id flag to CLI (#401)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Feb 23, 2022
1 parent 9083494 commit 45c145b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions pkg/api/models/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type Evaluation struct {

// Evaluation end timestamp
End string `json:"end,omitempty"`

// Evaluation commit ID context
GitCommitID string `json:"gitcommitid,omitempty"`
}

// ToJSON converts object to JSON string
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/models/keptn_context_extended_c_e.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type KeptnContextExtendedCE struct {
Triggeredid string `json:"triggeredid,omitempty"`

// gitcommitid
Gitcommitid string `json:"gitcommitid,omitempty"`
GitCommitID string `json:"gitcommitid,omitempty"`

// type
// Required: true
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/models/keptn_context_extended_c_e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestKeptnContextExtendedCE_Validate(t *testing.T) {
Specversion string
Time time.Time
Triggeredid string
Gitcommitid string
GitCommitID string
Type *string
}
tests := []struct {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestKeptnContextExtendedCE_Validate(t *testing.T) {
Specversion: tt.fields.Specversion,
Time: tt.fields.Time,
Triggeredid: tt.fields.Triggeredid,
Gitcommitid: tt.fields.Gitcommitid,
GitCommitID: tt.fields.GitCommitID,
Type: tt.fields.Type,
}
if err := ce.Validate(); (err != nil) != tt.wantErr {
Expand Down
15 changes: 8 additions & 7 deletions pkg/lib/v0_2_0/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ func IsTriggeredEventType(eventType string) bool {

// EventData contains mandatory fields of all Keptn CloudEvents
type EventData struct {
Project string `json:"project,omitempty"`
Stage string `json:"stage,omitempty"`
Service string `json:"service,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Project string `json:"project,omitempty"`
Stage string `json:"stage,omitempty"`
Service string `json:"service,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
GitCommitID string `json:"gitcommitid,omitempty"`

Status StatusType `json:"status,omitempty" jsonschema:"enum=succeeded,enum=errored,enum=unknown"`
Result ResultType `json:"result,omitempty" jsonschema:"enum=pass,enum=warning,enum=fail"`
Expand Down Expand Up @@ -398,7 +399,7 @@ func (eb *KeptnEventBuilder) WithTriggeredID(triggeredID string) *KeptnEventBuil

// WithGitCommitID can be used to set the git commit ID
func (eb *KeptnEventBuilder) WithGitCommitID(gitCommitID string) *KeptnEventBuilder {
eb.Gitcommitid = gitCommitID
eb.GitCommitID = gitCommitID
return eb
}

Expand All @@ -419,7 +420,7 @@ func ToCloudEvent(keptnEvent models.KeptnContextExtendedCE) cloudevents.Event {
event.SetData(cloudevents.ApplicationJSON, keptnEvent.Data)
event.SetExtension(keptnContextCEExtension, keptnEvent.Shkeptncontext)
event.SetExtension(triggeredIDCEExtension, keptnEvent.Triggeredid)
event.SetExtension(keptnGitCommitIDCEExtension, keptnEvent.Gitcommitid)
event.SetExtension(keptnGitCommitIDCEExtension, keptnEvent.GitCommitID)
event.SetExtension(keptnSpecVersionCEExtension, keptnEvent.Shkeptnspecversion)
return event
}
Expand Down Expand Up @@ -451,7 +452,7 @@ func ToKeptnEvent(event cloudevents.Event) (models.KeptnContextExtendedCE, error
Specversion: event.SpecVersion(),
Time: event.Time(),
Triggeredid: triggeredID,
Gitcommitid: gitCommitID,
GitCommitID: gitCommitID,
Type: strutils.Stringp(event.Type()),
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/lib/v0_2_0/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestCreateSimpleKeptnEvent(t *testing.T) {
require.NotEmpty(t, event.Shkeptnspecversion)
require.Equal(t, defaultSpecVersion, event.Specversion)
require.Equal(t, "", event.Triggeredid)
require.Equal(t, "", event.Gitcommitid)
require.Equal(t, "", event.GitCommitID)
require.Equal(t, strutils.Stringp("sh.keptn.event.dev.delivery.triggered"), event.Type)
}

Expand All @@ -304,7 +304,7 @@ func TestCreateKeptnEvent(t *testing.T) {
require.Equal(t, strutils.Stringp("source"), event.Source)
require.Equal(t, "my-keptn-context", event.Shkeptncontext)
require.Equal(t, "my-triggered-id", event.Triggeredid)
require.Equal(t, "my-commit-id", event.Gitcommitid)
require.Equal(t, "my-commit-id", event.GitCommitID)
require.Equal(t, strutils.Stringp("sh.keptn.event.dev.delivery.triggered"), event.Type)
}

Expand Down Expand Up @@ -335,7 +335,7 @@ func TestToCloudEvent(t *testing.T) {
Shkeptnspecversion: config.GetKeptnGoUtilsConfig().ShKeptnSpecVersion,
Specversion: defaultSpecVersion,
Triggeredid: "my-triggered-id",
Gitcommitid: "git-commit-id",
GitCommitID: "git-commit-id",
Type: strutils.Stringp("sh.keptn.event.dev.delivery.triggered"),
}
cloudevent := ToCloudEvent(keptnEvent)
Expand All @@ -359,7 +359,7 @@ func TestToKeptnEvent(t *testing.T) {
Specversion: defaultSpecVersion,
Time: time.Time{},
Triggeredid: "my-triggered-id",
Gitcommitid: "my-commit-id",
GitCommitID: "my-commit-id",
Type: strutils.Stringp("sh.keptn.event.dev.delivery.triggered"),
}

Expand Down

0 comments on commit 45c145b

Please sign in to comment.