Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.32.6
0.33.0
10 changes: 10 additions & 0 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type (
Runtime() IRuntimeAPI
GitSource() IGitSourceAPI
Component() IComponentAPI
Workflow() IWorkflowV2API
Pipeline() IPipelineV2API
}
)

Expand Down Expand Up @@ -108,6 +110,14 @@ func (c *codefresh) Component() IComponentAPI {
return newComponentAPI(c)
}

func (c *codefresh) Workflow() IWorkflowV2API {
return newWorkflowV2API(c)
}

func (c *codefresh) Pipeline() IPipelineV2API {
return newPipelineV2API(c)
}

func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
return c.requestAPIWithContext(context.Background(), opt)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/codefresh/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions pkg/codefresh/pipeline_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package codefresh

import (
"context"
"fmt"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
)

type (
IPipelineV2API interface {
Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error)
List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error)
}

pipelineV2 struct {
codefresh *codefresh
}

graphqlListPipelinesResponse struct {
Data struct {
Pipelines model.PipelinePage
}
Errors []graphqlError
}

graphqlGetPipelineResponse struct {
Data struct {
Pipeline model.Pipeline
}
Errors []graphqlError
}
)

func newPipelineV2API(codefresh *codefresh) IPipelineV2API {
return &pipelineV2{codefresh: codefresh}
}

func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error) {
jsonData := map[string]interface{}{
"query": `
query Pipeline(
$runtime: String!
$name: String!
$namespace: String
) {
pipeline(name: $name, namespace: $namespace, runtime: $runtime) {
metadata {
name
namespace
runtime
}
self {
healthStatus
syncStatus
version
}
projects
spec {
trigger
}
}
}`,
"variables": map[string]interface{}{
"runtime": runtime,
"name": name,
"namespace": namespace,
},
}

res := &graphqlGetPipelineResponse{}
err := p.codefresh.graphqlAPI(ctx, jsonData, res)
if err != nil {
return nil, fmt.Errorf("failed getting pipeline: %w", err)
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

if res.Data.Pipeline.Metadata == nil {
return nil, err
}

return &res.Data.Pipeline, nil
}

func (p *pipelineV2) List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) {
jsonData := map[string]interface{}{
"query": `
query Pipelines($filters: PipelinesFilterArgs) {
pipelines(filters: $filters) {
edges {
node {
metadata {
name
namespace
runtime
}
self {
healthStatus
syncStatus
version
}
projects
spec {
trigger
}
}
}
}
}`,
"variables": map[string]interface{}{
"filters": filterArgs,
},
}

res := &graphqlListPipelinesResponse{}
err := p.codefresh.graphqlAPI(ctx, jsonData, res)
if err != nil {
return nil, fmt.Errorf("failed getting pipeline list: %w", err)
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

pipelines := make([]model.Pipeline, len(res.Data.Pipelines.Edges))
for i := range res.Data.Pipelines.Edges {
pipelines[i] = *res.Data.Pipelines.Edges[i].Node
}

return pipelines, nil
}
170 changes: 170 additions & 0 deletions pkg/codefresh/workflow_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package codefresh

import (
"context"
"fmt"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
)

type (
IWorkflowV2API interface {
Get(ctx context.Context, uid string) (*model.Workflow, error)
List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error)
}

workflowV2 struct {
codefresh *codefresh
}

graphqlListWorkflowsResponse struct {
Data struct {
Workflows model.WorkflowPage
}
Errors []graphqlError
}

graphqlGetWorkflowResponse struct {
Data struct {
Workflow model.Workflow
}
Errors []graphqlError
}
)

func newWorkflowV2API(codefresh *codefresh) IWorkflowV2API {
return &workflowV2{codefresh: codefresh}
}

func (w *workflowV2) Get(ctx context.Context, uid string) (*model.Workflow, error) {
jsonData := map[string]interface{}{
"query": `
query Workflow(
$uid: String!
) {
workflow(uid: $uid) {
metadata {
uid
name
namespace
runtime
}
projects
spec {
entrypoint
templates {
name
}
workflowTemplateRef {
name
namespace
}
}
status {
phase
progress {
total
done
}
nodes {
type
name
}
}
pipeline {
metadata {
name
namespace
}
}
}
}`,
"variables": map[string]interface{}{
"uid": uid,
},
}

res := &graphqlGetWorkflowResponse{}
err := w.codefresh.graphqlAPI(ctx, jsonData, res)
if err != nil {
return nil, fmt.Errorf("failed getting workflow: %w", err)
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

if res.Data.Workflow.Metadata == nil {
return nil, err
}

return &res.Data.Workflow, nil
}

func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) {
jsonData := map[string]interface{}{
"query": `
query Workflows($filters: WorkflowsFilterArgs) {
workflows(filters: $filters) {
edges {
node {
metadata {
uid
name
namespace
runtime
}
projects
spec {
entrypoint
templates {
name
}
workflowTemplateRef {
name
namespace
}
}
status {
phase
progress {
total
done
}
nodes {
type
name
}
}
pipeline {
metadata {
name
namespace
}
}
}
}
}
}`,
"variables": map[string]interface{}{
"filters": filterArgs,
},
}

res := &graphqlListWorkflowsResponse{}
err := w.codefresh.graphqlAPI(ctx, jsonData, res)
if err != nil {
return nil, fmt.Errorf("failed getting workflow list: %w", err)
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

workflows := make([]model.Workflow, len(res.Data.Workflows.Edges))
for i := range res.Data.Workflows.Edges {
workflows[i] = *res.Data.Workflows.Edges[i].Node
}

return workflows, nil
}