From 08de1ba043d7b82f31cc8c08c9df8f4b21f418d2 Mon Sep 17 00:00:00 2001 From: nitishfy Date: Thu, 19 Dec 2024 13:25:31 +0530 Subject: [PATCH] add ui code Signed-off-by: nitishfy --- internal/directives/file_deleter.go | 3 +-- internal/directives/file_deleter_test.go | 5 ++++- internal/directives/schemas/delete-config.json | 2 +- internal/directives/zz_config_types.go | 2 +- .../registry/use-discover-registries.ts | 7 +++++++ ui/src/gen/directives/delete-config.json | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/directives/file_deleter.go b/internal/directives/file_deleter.go index c522896a2..dd4ef557a 100644 --- a/internal/directives/file_deleter.go +++ b/internal/directives/file_deleter.go @@ -63,7 +63,6 @@ func (f *fileDeleter) runPromotionStep( } symlink, err := f.isSymlink(absPath) - /* TODO if err != nil { @@ -73,7 +72,7 @@ func (f *fileDeleter) runPromotionStep( if symlink { err = os.Remove(absPath) if err != nil { - return PromotionStepResult{}, err + return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored}, err } } else { pathToDelete, err := securejoin.SecureJoin(stepCtx.WorkDir, cfg.Path) diff --git a/internal/directives/file_deleter_test.go b/internal/directives/file_deleter_test.go index 3f1c012df..473ce7cc2 100644 --- a/internal/directives/file_deleter_test.go +++ b/internal/directives/file_deleter_test.go @@ -120,7 +120,7 @@ func Test_fileDeleter_runPromotionStep(t *testing.T) { return tmpDir }, cfg: DeleteConfig{ - Path: "foo", + Path: "foo/", }, assertions: func(t *testing.T, workDir string, result PromotionStepResult, err error) { assert.NoError(t, err) @@ -129,6 +129,9 @@ func Test_fileDeleter_runPromotionStep(t *testing.T) { _, statErr := os.Stat(filepath.Join(workDir, "foo", "file.txt")) assert.Error(t, statErr) assert.True(t, os.IsNotExist(statErr)) + + _, statErr = os.Stat(filepath.Join(workDir, "bar", "file.txt")) + assert.NoError(t, statErr) }, }, } diff --git a/internal/directives/schemas/delete-config.json b/internal/directives/schemas/delete-config.json index bb6f8c15c..31a79358f 100644 --- a/internal/directives/schemas/delete-config.json +++ b/internal/directives/schemas/delete-config.json @@ -5,7 +5,7 @@ "additionalProperties": false, "required": ["path"], "properties": { - "Path": { + "path": { "type": "string", "description": "Path is the path to the file or directory to delete.", "minLength": 1 diff --git a/internal/directives/zz_config_types.go b/internal/directives/zz_config_types.go index 959cfd5a2..c200d7d3b 100644 --- a/internal/directives/zz_config_types.go +++ b/internal/directives/zz_config_types.go @@ -119,7 +119,7 @@ type CopyConfig struct { type DeleteConfig struct { // Path is the path to the file or directory to delete. - Path string `json:"Path"` + Path string `json:"path"` } type GitClearConfig struct { diff --git a/ui/src/features/promotion-directives/registry/use-discover-registries.ts b/ui/src/features/promotion-directives/registry/use-discover-registries.ts index 36e3351be..3952f9041 100644 --- a/ui/src/features/promotion-directives/registry/use-discover-registries.ts +++ b/ui/src/features/promotion-directives/registry/use-discover-registries.ts @@ -8,6 +8,7 @@ import { faCodeBranch, faCodePullRequest, faCopy, + faDelete, faDraftingCompass, faEdit, faExchangeAlt, @@ -29,6 +30,7 @@ import { JSONSchema7 } from 'json-schema'; // IMPORTANT(Marvin9): this must be replaced with proper discovery mechanism import argocdUpdateConfig from '@ui/gen/directives/argocd-update-config.json'; import copyConfig from '@ui/gen/directives/copy-config.json'; +import deleteConfig from '@ui/gen/directives/delete-config.json'; import gitOverwriteConfig from '@ui/gen/directives/git-clear-config.json'; import gitCloneConfig from '@ui/gen/directives/git-clone-config.json'; import gitCommitConfig from '@ui/gen/directives/git-commit-config.json'; @@ -61,6 +63,11 @@ export const useDiscoverPromotionDirectivesRegistries = (): PromotionDirectivesR unstable_icons: [faCopy], config: copyConfig as JSONSchema7 }, + { + identifier: 'delete', + unstable_icons: [faDelete], + config: deleteConfig as JSONSchema7 + }, { identifier: 'git-clone', unstable_icons: [faCodeBranch, faClone], diff --git a/ui/src/gen/directives/delete-config.json b/ui/src/gen/directives/delete-config.json index fef437ae5..21df07078 100644 --- a/ui/src/gen/directives/delete-config.json +++ b/ui/src/gen/directives/delete-config.json @@ -4,7 +4,7 @@ "type": "object", "additionalProperties": false, "properties": { - "Path": { + "path": { "type": "string", "description": "Path is the path to the file or directory to delete.", "minLength": 1