From 1831a3235d996d2876ff0eae304e1797ccc3f986 Mon Sep 17 00:00:00 2001 From: elad-codefresh Date: Wed, 8 Dec 2021 12:38:50 +0200 Subject: [PATCH] initial commit --- pkg/codefresh/git-source.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/codefresh/git-source.go b/pkg/codefresh/git-source.go index 1718ec4..f61faa6 100644 --- a/pkg/codefresh/git-source.go +++ b/pkg/codefresh/git-source.go @@ -9,7 +9,8 @@ import ( type ( IGitSourceAPI interface { - List(ctc context.Context, runtimeName string) ([]model.GitSource, error) + List(ctx context.Context, runtimeName string) ([]model.GitSource, error) + Delete(ctx context.Context, runtimeName string, name string) error } gitSource struct { @@ -22,6 +23,10 @@ type ( } Errors []graphqlError } + + graphQlDeleteGitSourceResponse struct { + Errors []graphqlError + } ) func newGitSourceAPI(codefresh *codefresh) IGitSourceAPI { @@ -72,3 +77,29 @@ func (g *gitSource) List(ctx context.Context, runtimeName string) ([]model.GitSo return gitSources, nil } + +func (g *gitSource) Delete(ctx context.Context, runtimeName string, name string) error { + jsonData := map[string]interface{}{ + "query": ` + mutation RemoveGitSource($runtime: String, $name: String) { + removeGitSource(runtime: $runtime, name: $name) + } + `, + "variables": map[string]interface{}{ + "runtime": runtimeName, + "name": name, + }, + } + + res := graphQlDeleteGitSourceResponse{} + err := g.codefresh.graphqlAPI(ctx, jsonData, res) + if err != nil { + return fmt.Errorf("failed making a graphql API call to removeGitSource: %w", err) + } + + if len(res.Errors) > 0 { + return graphqlErrorResponse{errors: res.Errors} + } + + return nil +}