Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CR-7465 #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion pkg/codefresh/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,6 +23,10 @@ type (
}
Errors []graphqlError
}

graphQlDeleteGitSourceResponse struct {
Errors []graphqlError
}
)

func newGitSourceAPI(codefresh *codefresh) IGitSourceAPI {
Expand Down Expand Up @@ -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
}