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 +}