From 3c483d3cd07026a2c733c1028d72d0e7b5faf211 Mon Sep 17 00:00:00 2001 From: Dat Dao Date: Thu, 2 Nov 2023 17:47:18 +0700 Subject: [PATCH] atlasexec: add enums for trigger type --- atlasexec/atlas.go | 14 ++++++++++++-- atlasexec/atlas_test.go | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/atlasexec/atlas.go b/atlasexec/atlas.go index b9201b2..ed2898f 100644 --- a/atlasexec/atlas.go +++ b/atlasexec/atlas.go @@ -37,10 +37,12 @@ type ( Env string Vars Vars } + // TriggerType defines the type for the "trigger_type" enum field. + TriggerType string // DeployRunContext describes what triggered this command (e.g., GitHub Action, v1.2.3) DeployRunContext struct { - TriggerType string `json:"triggerType,omitempty"` - TriggerVersion string `json:"triggerVersion,omitempty"` + TriggerType TriggerType `json:"triggerType,omitempty"` + TriggerVersion string `json:"triggerVersion,omitempty"` } // MigrateApplyParams are the parameters for the `migrate apply` command. MigrateApplyParams struct { @@ -121,6 +123,14 @@ type ( LintParams = MigrateLintParams ) +// TriggerType values. +const ( + TriggerTypeCLI TriggerType = "CLI" + TriggerTypeKubernetes TriggerType = "KUBERNETES" + TriggerTypeTerraform TriggerType = "TERRAFORM" + TriggerTypeGithubAction TriggerType = "GITHUB_ACTION" +) + // NewClient returns a new Atlas client with the given atlas-cli path. func NewClient(workingDir, execPath string) (*Client, error) { if execPath == "" { diff --git a/atlasexec/atlas_test.go b/atlasexec/atlas_test.go index 9b9db16..2d99ea8 100644 --- a/atlasexec/atlas_test.go +++ b/atlasexec/atlas_test.go @@ -129,7 +129,7 @@ func Test_MigrateApplyWithRemote(t *testing.T) { require.Nil(t, reportPayload.MigrateApplyReport.Input.Context) got, err = c.MigrateApply(context.Background(), &atlasexec.MigrateApplyParams{ Env: "test", - Context: &atlasexec.DeployRunContext{TriggerVersion: "1.2.3", TriggerType: "GITHUB_ACTION"}, + Context: &atlasexec.DeployRunContext{TriggerVersion: "1.2.3", TriggerType: atlasexec.TriggerTypeGithubAction}, }) require.NoError(t, err) require.NotNil(t, got)