From 5dca98014861e396b2698375bd6288b8999177ba Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Thu, 19 Aug 2021 14:31:05 +0300 Subject: [PATCH 1/7] wip --- pkg/codefresh/codefresh.go | 10 ++ pkg/codefresh/pipeline_v2.go | 121 ++++++++++++++++++++++ pkg/codefresh/workflow_v2.go | 192 +++++++++++++++++++++++++++++++++++ 3 files changed, 323 insertions(+) create mode 100644 pkg/codefresh/pipeline_v2.go create mode 100644 pkg/codefresh/workflow_v2.go diff --git a/pkg/codefresh/codefresh.go b/pkg/codefresh/codefresh.go index 67b4198..5e3553b 100644 --- a/pkg/codefresh/codefresh.go +++ b/pkg/codefresh/codefresh.go @@ -36,6 +36,8 @@ type ( Runtime() IRuntimeAPI GitSource() IGitSourceAPI Component() IComponentAPI + Workflow() IWorkflowV2API + Pipeline() IPipelineV2API } ) @@ -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) } diff --git a/pkg/codefresh/pipeline_v2.go b/pkg/codefresh/pipeline_v2.go new file mode 100644 index 0000000..f960008 --- /dev/null +++ b/pkg/codefresh/pipeline_v2.go @@ -0,0 +1,121 @@ +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) ([]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": `{ + pipeline( + runtime: String! + name: String! + namespace: String + ) { + metadata { + name + namespace + } + self { + healthStatus + 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 model.Pipeline{}, fmt.Errorf("failed getting pipeline list: %w", err) + } + + if len(res.Errors) > 0 { + return model.Pipeline{}, graphqlErrorResponse{errors: res.Errors} + } + + return res.Data.Pipeline, nil +} + +func (p *pipelineV2) List(ctx context.Context) ([]model.Pipeline, error) { + jsonData := map[string]interface{}{ + "query": `{ + pipelines { + edges { + node { + metadata { + name + namespace + } + self { + healthStatus + version + } + projects + spec { + trigger + } + } + } + } + }`, + } + + 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 +} diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go new file mode 100644 index 0000000..adba962 --- /dev/null +++ b/pkg/codefresh/workflow_v2.go @@ -0,0 +1,192 @@ +package codefresh + +import ( + "context" + "fmt" + + "github.com/codefresh-io/go-sdk/pkg/codefresh/model" +) + +type ( + IWorkflowV2API interface { + Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error) + List(ctx context.Context, args 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, name, namespace, runtime string) (model.Workflow, error) { + jsonData := map[string]interface{}{ + "query": `{ + workflow( + runtime: String! + name: String! + namespace: String + ) { + metadata { + name + namespace + } + projects + spec { + entrypoint + templates { + name + } + workflowTemplateRef { + name + namespace + } + } + status { + createdAt + startedAt + finishedAt + phase + progress { + total + done + } + nodes { + type + name + } + message + statuses { + since + phase + message + } + } + pipeline { + metadata { + name + namespace + } + } + actualManifest + } + }`, + "variables": map[string]interface{}{ + "runtime": runtime, + "name": name, + "namespace": namespace, + }, + } + + res := &graphqlGetWorkflowResponse{} + err := w.codefresh.graphqlAPI(ctx, jsonData, res) + if err != nil { + return model.Workflow{}, fmt.Errorf("failed getting pipeline list: %w", err) + } + + if len(res.Errors) > 0 { + return model.Workflow{}, graphqlErrorResponse{errors: res.Errors} + } + + return res.Data.Workflow, nil +} + +func (w *workflowV2) List(ctx context.Context, args model.WorkflowsFilterArgs) ([]model.Workflow, error) { + jsonData := map[string]interface{}{ + "query": `{ + workflows { + edges { + node { + metadata { + name + namespace + } + projects + spec { + entrypoint + templates { + name + } + workflowTemplateRef { + name + namespace + } + } + status { + createdAt + startedAt + finishedAt + phase + progress { + total + done + } + nodes { + type + name + } + message + statuses { + since + phase + message + } + } + pipeline { + metadata { + name + namespace + } + } + actualManifest + } + } + } + }`, + "variables": map[string]interface{}{ + "project": args.Project, + "runtime": args.Runtime, + "pipeline": args.Pipeline, + "repositories": args.Repositories, + "branches": args.Branches, + "eventTypes": args.EventTypes, + "initiators": args.Initiators, + "statuses": args.Statuses, + "startDate": args.StartDate, + }, + } + + res := &graphqlListWorkflowsResponse{} + err := w.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} + } + + 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 +} From 79ce73dc7f80caa5b542f574c57717126e113a37 Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Thu, 19 Aug 2021 16:22:57 +0300 Subject: [PATCH 2/7] wip --- pkg/codefresh/model/models_gen.go | 260 ++++++++++++++++-------------- pkg/codefresh/pipeline_v2.go | 9 +- pkg/codefresh/workflow_v2.go | 16 +- 3 files changed, 152 insertions(+), 133 deletions(-) diff --git a/pkg/codefresh/model/models_gen.go b/pkg/codefresh/model/models_gen.go index f5021ee..8760dd4 100644 --- a/pkg/codefresh/model/models_gen.go +++ b/pkg/codefresh/model/models_gen.go @@ -73,11 +73,6 @@ type PushPayload interface { IsPushPayload() } -// Sensor trigger -type SensorTrigger interface { - IsSensorTrigger() -} - // Slice type Slice interface { IsSlice() @@ -516,8 +511,8 @@ type GitCommitEventPayloadData struct { Commit *GitCommit `json:"commit"` } -func (GitCommitEventPayloadData) IsEventPayloadData() {} func (GitCommitEventPayloadData) IsCommonGitEventPayloadData() {} +func (GitCommitEventPayloadData) IsEventPayloadData() {} // Git integration entity type GitIntegration struct { @@ -646,8 +641,8 @@ type GitPREventPayloadData struct { Pr *GitPr `json:"pr"` } -func (GitPREventPayloadData) IsEventPayloadData() {} func (GitPREventPayloadData) IsCommonGitEventPayloadData() {} +func (GitPREventPayloadData) IsEventPayloadData() {} // "Release data type GitRelease struct { @@ -679,8 +674,8 @@ type GitReleaseEventPayloadData struct { Release *GitRelease `json:"release"` } -func (GitReleaseEventPayloadData) IsEventPayloadData() {} func (GitReleaseEventPayloadData) IsCommonGitEventPayloadData() {} +func (GitReleaseEventPayloadData) IsEventPayloadData() {} // "Revision data type GitRevision struct { @@ -745,6 +740,23 @@ type GitSourceSlice struct { func (GitSourceSlice) IsSlice() {} +// "Unknown Git event +type GitUnknownEventPayloadData struct { + // Event payload type + Type PayloadDataTypes `json:"type"` + // Name of the git event + Event string `json:"event"` + // Git provider + Provider string `json:"provider"` + // Repository + Repository *Repository `json:"repository"` + // Event initiator + Initiator *Initiator `json:"initiator"` +} + +func (GitUnknownEventPayloadData) IsCommonGitEventPayloadData() {} +func (GitUnknownEventPayloadData) IsEventPayloadData() {} + // Github event type GithubEvent struct { // Name @@ -771,20 +783,6 @@ type GitopsEntitySource struct { GitManifest string `json:"gitManifest"` } -// Http Trigger -type HTTPTrigger struct { - // Name - Name string `json:"name"` - // Conditions - Conditions string `json:"conditions"` - // Url - URL string `json:"url"` - // Method - Method string `json:"method"` -} - -func (HTTPTrigger) IsSensorTrigger() {} - // "Event initiator type Initiator struct { // Git user username @@ -901,10 +899,10 @@ type Pipeline struct { Self *Sensor `json:"self"` // Projects Projects []string `json:"projects"` - // Dependencies - Dependencies []*SensorDependency `json:"dependencies"` // Trigger name - Trigger string `json:"trigger"` + Spec *PipelineSpec `json:"spec"` + // Statistics + Statistics *PipelineStatistics `json:"statistics"` } func (Pipeline) IsBaseEntity() {} @@ -912,6 +910,32 @@ func (Pipeline) IsK8sLogicEntity() {} func (Pipeline) IsProjectBasedEntity() {} func (Pipeline) IsEntity() {} +// Pipeline statistics for average duration +type PipelineAverageDurationStats struct { + // Info + Info *PipelineAverageDurationStatsInfo `json:"info"` + // Data + Data []*PipelineAverageDurationStatsData `json:"data"` +} + +// Stats data for pipline average duration +type PipelineAverageDurationStatsData struct { + // Time + Time *string `json:"time"` + // Average duration + AverageDuration *float64 `json:"averageDuration"` +} + +// Stats info for pipeline success rate. +type PipelineAverageDurationStatsInfo struct { + // Time period data + TimePeriodData *StatsTimePeriodData `json:"timePeriodData"` + // Total average duration for the all time period + AverageDuration *float64 `json:"averageDuration"` + // Diff in avarages between the current time period and the previous time period + PctDiffFromLastTimeFrame *float64 `json:"pctDiffFromLastTimeFrame"` +} + // Pipeline Edge type PipelineEdge struct { // Node contains the actual pipeline data @@ -922,6 +946,32 @@ type PipelineEdge struct { func (PipelineEdge) IsEdge() {} +// Pipeline statistics for pipline executions +type PipelineExecutionsStats struct { + // Info + Info *PipelineExecutionsStatsInfo `json:"info"` + // Data + Data []*PipelineExecutionsStatsData `json:"data"` +} + +// Stats data for pipline executions +type PipelineExecutionsStatsData struct { + // Time + Time *string `json:"time"` + // Executions + Executions *int `json:"executions"` +} + +// Stats info for pipeline executions. +type PipelineExecutionsStatsInfo struct { + // Time period data + TimePeriodData *StatsTimePeriodData `json:"timePeriodData"` + // Total number of executions for the all time period + TotalExecutions *float64 `json:"totalExecutions"` + // Diff in totals between the current time period and the previous time period + PctDiffFromLastTimeFrame *float64 `json:"pctDiffFromLastTimeFrame"` +} + // Pipeline Page type PipelinePage struct { // Total amount of pipelines @@ -944,6 +994,60 @@ type PipelineSlice struct { func (PipelineSlice) IsSlice() {} +// Pipeline Spec +type PipelineSpec struct { + // Trigger + Trigger string `json:"trigger"` +} + +// Pipeline statistics to be used in analytics module +type PipelineStatistics struct { + // Success Rate stats + SuccessRateStats *PipelineSuccessRateStats `json:"successRateStats"` + // Average duration stats + AverageDurationStats *PipelineAverageDurationStats `json:"averageDurationStats"` + // Execution stats + ExecutionsStats *PipelineExecutionsStats `json:"executionsStats"` +} + +// Pipeline statistics for pipline success rate +type PipelineSuccessRateStats struct { + // Info + Info *PipelineSuccessRateStatsInfo `json:"info"` + // Data + Data []*PipelineSuccessRateStatsData `json:"data"` +} + +// Stats data for pipline success rate +type PipelineSuccessRateStatsData struct { + // Time + Time *string `json:"time"` + // Success rate + SuccessRate *float64 `json:"successRate"` +} + +// Stats info for pipeline success rate. +type PipelineSuccessRateStatsInfo struct { + // Time period data + TimePeriodData *StatsTimePeriodData `json:"timePeriodData"` + // Total average success rate for the all time period + AverageSuccessRate *float64 `json:"averageSuccessRate"` + // Diff in avarages between the current time period and the previous time period + PctDiffFromLastTimeFrame *float64 `json:"pctDiffFromLastTimeFrame"` +} + +// Pipeline filter arguments +type PipelinesFilterArgs struct { + // Filter workflows from a specific project + Project *string `json:"project"` + // Filter workflows from a specific runtime + Runtime *string `json:"runtime"` + // Filter workflows from a specific runtime + Namespace *string `json:"namespace"` + // Filter workflows from a specific pipeline + Name *string `json:"name"` +} + // Progress type Progress struct { // Total @@ -1129,10 +1233,6 @@ type Sensor struct { ActualManifest *string `json:"actualManifest"` // Projects Projects []string `json:"projects"` - // Dependencies - Dependencies []*SensorDependency `json:"dependencies"` - // Triggers - Triggers []SensorTrigger `json:"triggers"` } func (Sensor) IsGitopsEntity() {} @@ -1140,16 +1240,6 @@ func (Sensor) IsBaseEntity() {} func (Sensor) IsProjectBasedEntity() {} func (Sensor) IsEntity() {} -// Sensor dependency -type SensorDependency struct { - // Name - Name string `json:"name"` - // EventSource name - EventSource string `json:"eventSource"` - // Event name - Event string `json:"event"` -} - // Sensor Edge type SensorEdge struct { // Node contains the actual sensor data @@ -1206,6 +1296,14 @@ type SlicePaginationArgs struct { Last *int `json:"last"` } +// Statistics time period meta data +type StatsTimePeriodData struct { + // Granularity for the graph X Axis + Granularity *string `json:"granularity"` + // Date range for the statistics + DateRange []*string `json:"dateRange"` +} + // Workflow status history item type StatusHistoryItem struct { // The time the status started @@ -1534,20 +1632,6 @@ type WorkflowTemplateSlice struct { func (WorkflowTemplateSlice) IsSlice() {} -// Http Trigger -type WorkflowTrigger struct { - // Name - Name string `json:"name"` - // Conditions - Conditions string `json:"conditions"` - // Workflow manifest - Workflow string `json:"workflow"` - // Operation - Op WorkflowTriggerOperation `json:"op"` -} - -func (WorkflowTrigger) IsSensorTrigger() {} - // Workflow filter arguments type WorkflowsFilterArgs struct { // Filter workflows from a specific project @@ -1718,24 +1802,20 @@ func (e HealthStatus) MarshalGQL(w io.Writer) { type PayloadDataTypes string const ( - PayloadDataTypesCalendar PayloadDataTypes = "CALENDAR" - PayloadDataTypesGitPr PayloadDataTypes = "GIT_PR" - PayloadDataTypesGitPush PayloadDataTypes = "GIT_PUSH" - PayloadDataTypesGitRelease PayloadDataTypes = "GIT_RELEASE" - PayloadDataTypesUnknown PayloadDataTypes = "UNKNOWN" + PayloadDataTypesCalendar PayloadDataTypes = "calendar" + PayloadDataTypesGit PayloadDataTypes = "git" + PayloadDataTypesUnknown PayloadDataTypes = "unknown" ) var AllPayloadDataTypes = []PayloadDataTypes{ PayloadDataTypesCalendar, - PayloadDataTypesGitPr, - PayloadDataTypesGitPush, - PayloadDataTypesGitRelease, + PayloadDataTypesGit, PayloadDataTypesUnknown, } func (e PayloadDataTypes) IsValid() bool { switch e { - case PayloadDataTypesCalendar, PayloadDataTypesGitPr, PayloadDataTypesGitPush, PayloadDataTypesGitRelease, PayloadDataTypesUnknown: + case PayloadDataTypesCalendar, PayloadDataTypesGit, PayloadDataTypesUnknown: return true } return false @@ -1961,59 +2041,3 @@ func (e *UserStatus) UnmarshalGQL(v interface{}) error { func (e UserStatus) MarshalGQL(w io.Writer) { fmt.Fprint(w, strconv.Quote(e.String())) } - -// Workflow Trigger Operation -type WorkflowTriggerOperation string - -const ( - // Resubmit - WorkflowTriggerOperationResubmit WorkflowTriggerOperation = "RESUBMIT" - // Resume - WorkflowTriggerOperationResume WorkflowTriggerOperation = "RESUME" - // Retry - WorkflowTriggerOperationRetry WorkflowTriggerOperation = "RETRY" - // Submit - WorkflowTriggerOperationSubmit WorkflowTriggerOperation = "SUBMIT" - // Suspend - WorkflowTriggerOperationSuspend WorkflowTriggerOperation = "SUSPEND" - // Terminate - WorkflowTriggerOperationTerminate WorkflowTriggerOperation = "TERMINATE" -) - -var AllWorkflowTriggerOperation = []WorkflowTriggerOperation{ - WorkflowTriggerOperationResubmit, - WorkflowTriggerOperationResume, - WorkflowTriggerOperationRetry, - WorkflowTriggerOperationSubmit, - WorkflowTriggerOperationSuspend, - WorkflowTriggerOperationTerminate, -} - -func (e WorkflowTriggerOperation) IsValid() bool { - switch e { - case WorkflowTriggerOperationResubmit, WorkflowTriggerOperationResume, WorkflowTriggerOperationRetry, WorkflowTriggerOperationSubmit, WorkflowTriggerOperationSuspend, WorkflowTriggerOperationTerminate: - return true - } - return false -} - -func (e WorkflowTriggerOperation) String() string { - return string(e) -} - -func (e *WorkflowTriggerOperation) UnmarshalGQL(v interface{}) error { - str, ok := v.(string) - if !ok { - return fmt.Errorf("enums must be strings") - } - - *e = WorkflowTriggerOperation(str) - if !e.IsValid() { - return fmt.Errorf("%s is not a valid WorkflowTriggerOperation", str) - } - return nil -} - -func (e WorkflowTriggerOperation) MarshalGQL(w io.Writer) { - fmt.Fprint(w, strconv.Quote(e.String())) -} diff --git a/pkg/codefresh/pipeline_v2.go b/pkg/codefresh/pipeline_v2.go index f960008..f4c6201 100644 --- a/pkg/codefresh/pipeline_v2.go +++ b/pkg/codefresh/pipeline_v2.go @@ -10,7 +10,7 @@ import ( type ( IPipelineV2API interface { Get(ctx context.Context, name, namespace, runtime string) (model.Pipeline, error) - List(ctx context.Context) ([]model.Pipeline, error) + List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) } pipelineV2 struct { @@ -78,10 +78,10 @@ func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) ( return res.Data.Pipeline, nil } -func (p *pipelineV2) List(ctx context.Context) ([]model.Pipeline, error) { +func (p *pipelineV2) List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) { jsonData := map[string]interface{}{ "query": `{ - pipelines { + pipelines(filters: PipelineFilterArgs) { edges { node { metadata { @@ -100,6 +100,9 @@ func (p *pipelineV2) List(ctx context.Context) ([]model.Pipeline, error) { } } }`, + "variables": map[string]interface{}{ + "filters": filterArgs, + }, } res := &graphqlListPipelinesResponse{} diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go index adba962..5e5f38b 100644 --- a/pkg/codefresh/workflow_v2.go +++ b/pkg/codefresh/workflow_v2.go @@ -10,7 +10,7 @@ import ( type ( IWorkflowV2API interface { Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error) - List(ctx context.Context, args model.WorkflowsFilterArgs) ([]model.Workflow, error) + List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) } workflowV2 struct { @@ -108,10 +108,10 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( return res.Data.Workflow, nil } -func (w *workflowV2) List(ctx context.Context, args model.WorkflowsFilterArgs) ([]model.Workflow, error) { +func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) { jsonData := map[string]interface{}{ "query": `{ - workflows { + workflows(filters: WorkflowFilterArgs) { edges { node { metadata { @@ -161,15 +161,7 @@ func (w *workflowV2) List(ctx context.Context, args model.WorkflowsFilterArgs) ( } }`, "variables": map[string]interface{}{ - "project": args.Project, - "runtime": args.Runtime, - "pipeline": args.Pipeline, - "repositories": args.Repositories, - "branches": args.Branches, - "eventTypes": args.EventTypes, - "initiators": args.Initiators, - "statuses": args.Statuses, - "startDate": args.StartDate, + "filters": filterArgs, }, } From 8244adf779afd6d01bc6f7be5b9b96b1c4864e4b Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Thu, 19 Aug 2021 21:14:33 +0300 Subject: [PATCH 3/7] wip --- pkg/codefresh/pipeline_v2.go | 82 +++++++------- pkg/codefresh/workflow_v2.go | 200 ++++++++++++++++++----------------- 2 files changed, 143 insertions(+), 139 deletions(-) diff --git a/pkg/codefresh/pipeline_v2.go b/pkg/codefresh/pipeline_v2.go index f4c6201..fb6edca 100644 --- a/pkg/codefresh/pipeline_v2.go +++ b/pkg/codefresh/pipeline_v2.go @@ -9,7 +9,7 @@ import ( type ( IPipelineV2API interface { - Get(ctx context.Context, name, namespace, runtime string) (model.Pipeline, error) + Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error) List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) } @@ -36,28 +36,29 @@ func newPipelineV2API(codefresh *codefresh) IPipelineV2API { return &pipelineV2{codefresh: codefresh} } -func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (model.Pipeline, error) { +func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error) { jsonData := map[string]interface{}{ - "query": `{ - pipeline( - runtime: String! - name: String! - namespace: String + "query": ` + query Pipeline( + $runtime: String! + $name: String! + $namespace: String ) { - metadata { - name - namespace - } - self { - healthStatus - version - } - projects - spec { - trigger + pipeline(name: $name, namespace: $namespace, runtime: $runtime) { + metadata { + name + namespace + } + self { + healthStatus + version + } + projects + spec { + trigger + } } - } - }`, + }`, "variables": map[string]interface{}{ "runtime": runtime, "name": name, @@ -68,38 +69,39 @@ func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) ( res := &graphqlGetPipelineResponse{} err := p.codefresh.graphqlAPI(ctx, jsonData, res) if err != nil { - return model.Pipeline{}, fmt.Errorf("failed getting pipeline list: %w", err) + return nil, fmt.Errorf("failed getting pipeline: %w", err) } if len(res.Errors) > 0 { - return model.Pipeline{}, graphqlErrorResponse{errors: res.Errors} + return nil, graphqlErrorResponse{errors: res.Errors} } - return res.Data.Pipeline, nil + return &res.Data.Pipeline, nil } func (p *pipelineV2) List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) { jsonData := map[string]interface{}{ - "query": `{ - pipelines(filters: PipelineFilterArgs) { - edges { - node { - metadata { - name - namespace - } - self { - healthStatus - version - } - projects - spec { - trigger + "query": ` + query Pipelines($filters: PipelinesFilterArgs) { + pipelines(filters: $filters) { + edges { + node { + metadata { + name + namespace + } + self { + healthStatus + version + } + projects + spec { + trigger + } } } } - } - }`, + }`, "variables": map[string]interface{}{ "filters": filterArgs, }, diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go index 5e5f38b..4a99f3e 100644 --- a/pkg/codefresh/workflow_v2.go +++ b/pkg/codefresh/workflow_v2.go @@ -9,7 +9,7 @@ import ( type ( IWorkflowV2API interface { - Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error) + Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) } @@ -36,58 +36,59 @@ func newWorkflowV2API(codefresh *codefresh) IWorkflowV2API { return &workflowV2{codefresh: codefresh} } -func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error) { +func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error) { jsonData := map[string]interface{}{ - "query": `{ - workflow( - runtime: String! - name: String! - namespace: String + "query": ` + query Workflow( + $runtime: String! + $name: String! + $namespace: String ) { - metadata { - name - namespace - } - projects - spec { - entrypoint - templates { - name - } - workflowTemplateRef { - name - namespace - } - } - status { - createdAt - startedAt - finishedAt - phase - progress { - total - done - } - nodes { - type - name - } - message - statuses { - since - phase - message - } - } - pipeline { + workflow(name: $name, namespace: $namespace, runtime: $runtime) { metadata { - name - namespace + name + namespace } - } - actualManifest - } - }`, + projects + spec { + entrypoint + templates { + name + } + workflowTemplateRef { + name + namespace + } + } + status { + createdAt + startedAt + finishedAt + phase + progress { + total + done + } + nodes { + type + name + } + message + statuses { + since + phase + message + } + } + pipeline { + metadata { + name + namespace + } + } + actualManifest + } + }`, "variables": map[string]interface{}{ "runtime": runtime, "name": name, @@ -98,68 +99,69 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( res := &graphqlGetWorkflowResponse{} err := w.codefresh.graphqlAPI(ctx, jsonData, res) if err != nil { - return model.Workflow{}, fmt.Errorf("failed getting pipeline list: %w", err) + return nil, fmt.Errorf("failed getting workflow: %w", err) } if len(res.Errors) > 0 { - return model.Workflow{}, graphqlErrorResponse{errors: res.Errors} + return nil, graphqlErrorResponse{errors: res.Errors} } - return res.Data.Workflow, nil + return &res.Data.Workflow, nil } func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) { jsonData := map[string]interface{}{ - "query": `{ - workflows(filters: WorkflowFilterArgs) { - edges { - node { - metadata { - name - namespace - } - projects - spec { - entrypoint - templates { - name - } - workflowTemplateRef { - name - namespace - } - } - status { - createdAt - startedAt - finishedAt - phase - progress { - total - done - } - nodes { - type - name - } - message - statuses { - since - phase - message - } - } - pipeline { + "query": ` + query Workflows($filters: WorkflowsFilterArgs) { + workflows(filters: $filters) { + edges { + node { metadata { - name - namespace + name + namespace } - } - actualManifest + projects + spec { + entrypoint + templates { + name + } + workflowTemplateRef { + name + namespace + } + } + status { + createdAt + startedAt + finishedAt + phase + progress { + total + done + } + nodes { + type + name + } + message + statuses { + since + phase + message + } + } + pipeline { + metadata { + name + namespace + } + } + actualManifest + } } } - } - }`, + }`, "variables": map[string]interface{}{ "filters": filterArgs, }, @@ -168,7 +170,7 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA res := &graphqlListWorkflowsResponse{} err := w.codefresh.graphqlAPI(ctx, jsonData, res) if err != nil { - return nil, fmt.Errorf("failed getting pipeline list: %w", err) + return nil, fmt.Errorf("failed getting workflow list: %w", err) } if len(res.Errors) > 0 { From 904f6e1357e2b78b5bb60c5114bf8ea8a24226aa Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Thu, 19 Aug 2021 21:15:11 +0300 Subject: [PATCH 4/7] version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fd9620c..be386c9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.32.1 +0.33.0 From 1e6c0ac37131c96bf68a0c0f1229fa6e439b2f63 Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Thu, 26 Aug 2021 21:26:08 +0300 Subject: [PATCH 5/7] added pipline v2 and workflow v2 api --- pkg/codefresh/pipeline_v2.go | 8 ++++++++ pkg/codefresh/workflow_v2.go | 30 ++++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pkg/codefresh/pipeline_v2.go b/pkg/codefresh/pipeline_v2.go index fb6edca..75c1e5b 100644 --- a/pkg/codefresh/pipeline_v2.go +++ b/pkg/codefresh/pipeline_v2.go @@ -48,9 +48,11 @@ func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) ( metadata { name namespace + runtime } self { healthStatus + syncStatus version } projects @@ -76,6 +78,10 @@ func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) ( return nil, graphqlErrorResponse{errors: res.Errors} } + if res.Data.Pipeline.Metadata == nil { + return nil, err + } + return &res.Data.Pipeline, nil } @@ -89,9 +95,11 @@ func (p *pipelineV2) List(ctx context.Context, filterArgs model.PipelinesFilterA metadata { name namespace + runtime } self { healthStatus + syncStatus version } projects diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go index 4a99f3e..ee217ef 100644 --- a/pkg/codefresh/workflow_v2.go +++ b/pkg/codefresh/workflow_v2.go @@ -48,6 +48,7 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( metadata { name namespace + runtime } projects spec { @@ -61,9 +62,6 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( } } status { - createdAt - startedAt - finishedAt phase progress { total @@ -73,12 +71,6 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( type name } - message - statuses { - since - phase - message - } } pipeline { metadata { @@ -86,7 +78,6 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( namespace } } - actualManifest } }`, "variables": map[string]interface{}{ @@ -106,6 +97,10 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( return nil, graphqlErrorResponse{errors: res.Errors} } + if res.Data.Workflow.Metadata == nil { + return nil, err + } + return &res.Data.Workflow, nil } @@ -119,6 +114,7 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA metadata { name namespace + runtime } projects spec { @@ -132,9 +128,6 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA } } status { - createdAt - startedAt - finishedAt phase progress { total @@ -144,20 +137,13 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA type name } - message - statuses { - since - phase - message - } - } + } pipeline { metadata { name namespace } - } - actualManifest + } } } } From 919a9acfa4997edc59d80ca7894d8a435704c9f4 Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Sun, 29 Aug 2021 14:58:15 +0300 Subject: [PATCH 6/7] wip --- pkg/codefresh/workflow_v2.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go index a29a906..ee217ef 100644 --- a/pkg/codefresh/workflow_v2.go +++ b/pkg/codefresh/workflow_v2.go @@ -63,7 +63,6 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( } status { phase - startedAt progress { total done From 27c559dce5a12a970d5fd4ca51424f839d45c8a6 Mon Sep 17 00:00:00 2001 From: daniel-codefresh Date: Sun, 29 Aug 2021 18:05:06 +0300 Subject: [PATCH 7/7] wip --- pkg/codefresh/model/models_gen.go | 6 +++--- pkg/codefresh/workflow_v2.go | 16 +++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/codefresh/model/models_gen.go b/pkg/codefresh/model/models_gen.go index d7c7477..f8203c2 100644 --- a/pkg/codefresh/model/models_gen.go +++ b/pkg/codefresh/model/models_gen.go @@ -949,6 +949,8 @@ type ObjectMeta struct { LastUpdated *string `json:"lastUpdated"` // Created Created *string `json:"created"` + // K8s object uid + UID *string `json:"uid"` } // Information about current page @@ -1226,10 +1228,8 @@ type Runtime struct { Self *AppProject `json:"self"` // Projects Projects []string `json:"projects"` - // K8s cluster where the runtime is running + // Cluster Cluster *string `json:"cluster"` - // Ingress host of the runtime - IngressHost *string `json:"ingressHost"` // Runtime version RuntimeVersion *string `json:"runtimeVersion"` } diff --git a/pkg/codefresh/workflow_v2.go b/pkg/codefresh/workflow_v2.go index ee217ef..60c5d9e 100644 --- a/pkg/codefresh/workflow_v2.go +++ b/pkg/codefresh/workflow_v2.go @@ -9,7 +9,7 @@ import ( type ( IWorkflowV2API interface { - Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error) + Get(ctx context.Context, uid string) (*model.Workflow, error) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) } @@ -36,16 +36,15 @@ func newWorkflowV2API(codefresh *codefresh) IWorkflowV2API { return &workflowV2{codefresh: codefresh} } -func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error) { +func (w *workflowV2) Get(ctx context.Context, uid string) (*model.Workflow, error) { jsonData := map[string]interface{}{ "query": ` query Workflow( - $runtime: String! - $name: String! - $namespace: String + $uid: String! ) { - workflow(name: $name, namespace: $namespace, runtime: $runtime) { + workflow(uid: $uid) { metadata { + uid name namespace runtime @@ -81,9 +80,7 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) ( } }`, "variables": map[string]interface{}{ - "runtime": runtime, - "name": name, - "namespace": namespace, + "uid": uid, }, } @@ -112,6 +109,7 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA edges { node { metadata { + uid name namespace runtime