Skip to content

Commit 8244adf

Browse files
wip
1 parent 79ce73d commit 8244adf

File tree

2 files changed

+143
-139
lines changed

2 files changed

+143
-139
lines changed

pkg/codefresh/pipeline_v2.go

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type (
1111
IPipelineV2API interface {
12-
Get(ctx context.Context, name, namespace, runtime string) (model.Pipeline, error)
12+
Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error)
1313
List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error)
1414
}
1515

@@ -36,28 +36,29 @@ func newPipelineV2API(codefresh *codefresh) IPipelineV2API {
3636
return &pipelineV2{codefresh: codefresh}
3737
}
3838

39-
func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (model.Pipeline, error) {
39+
func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Pipeline, error) {
4040
jsonData := map[string]interface{}{
41-
"query": `{
42-
pipeline(
43-
runtime: String!
44-
name: String!
45-
namespace: String
41+
"query": `
42+
query Pipeline(
43+
$runtime: String!
44+
$name: String!
45+
$namespace: String
4646
) {
47-
metadata {
48-
name
49-
namespace
50-
}
51-
self {
52-
healthStatus
53-
version
54-
}
55-
projects
56-
spec {
57-
trigger
47+
pipeline(name: $name, namespace: $namespace, runtime: $runtime) {
48+
metadata {
49+
name
50+
namespace
51+
}
52+
self {
53+
healthStatus
54+
version
55+
}
56+
projects
57+
spec {
58+
trigger
59+
}
5860
}
59-
}
60-
}`,
61+
}`,
6162
"variables": map[string]interface{}{
6263
"runtime": runtime,
6364
"name": name,
@@ -68,38 +69,39 @@ func (p *pipelineV2) Get(ctx context.Context, name, namespace, runtime string) (
6869
res := &graphqlGetPipelineResponse{}
6970
err := p.codefresh.graphqlAPI(ctx, jsonData, res)
7071
if err != nil {
71-
return model.Pipeline{}, fmt.Errorf("failed getting pipeline list: %w", err)
72+
return nil, fmt.Errorf("failed getting pipeline: %w", err)
7273
}
7374

7475
if len(res.Errors) > 0 {
75-
return model.Pipeline{}, graphqlErrorResponse{errors: res.Errors}
76+
return nil, graphqlErrorResponse{errors: res.Errors}
7677
}
7778

78-
return res.Data.Pipeline, nil
79+
return &res.Data.Pipeline, nil
7980
}
8081

8182
func (p *pipelineV2) List(ctx context.Context, filterArgs model.PipelinesFilterArgs) ([]model.Pipeline, error) {
8283
jsonData := map[string]interface{}{
83-
"query": `{
84-
pipelines(filters: PipelineFilterArgs) {
85-
edges {
86-
node {
87-
metadata {
88-
name
89-
namespace
90-
}
91-
self {
92-
healthStatus
93-
version
94-
}
95-
projects
96-
spec {
97-
trigger
84+
"query": `
85+
query Pipelines($filters: PipelinesFilterArgs) {
86+
pipelines(filters: $filters) {
87+
edges {
88+
node {
89+
metadata {
90+
name
91+
namespace
92+
}
93+
self {
94+
healthStatus
95+
version
96+
}
97+
projects
98+
spec {
99+
trigger
100+
}
98101
}
99102
}
100103
}
101-
}
102-
}`,
104+
}`,
103105
"variables": map[string]interface{}{
104106
"filters": filterArgs,
105107
},

pkg/codefresh/workflow_v2.go

Lines changed: 101 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type (
1111
IWorkflowV2API interface {
12-
Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error)
12+
Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error)
1313
List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error)
1414
}
1515

@@ -36,58 +36,59 @@ func newWorkflowV2API(codefresh *codefresh) IWorkflowV2API {
3636
return &workflowV2{codefresh: codefresh}
3737
}
3838

39-
func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (model.Workflow, error) {
39+
func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (*model.Workflow, error) {
4040
jsonData := map[string]interface{}{
41-
"query": `{
42-
workflow(
43-
runtime: String!
44-
name: String!
45-
namespace: String
41+
"query": `
42+
query Workflow(
43+
$runtime: String!
44+
$name: String!
45+
$namespace: String
4646
) {
47-
metadata {
48-
name
49-
namespace
50-
}
51-
projects
52-
spec {
53-
entrypoint
54-
templates {
55-
name
56-
}
57-
workflowTemplateRef {
58-
name
59-
namespace
60-
}
61-
}
62-
status {
63-
createdAt
64-
startedAt
65-
finishedAt
66-
phase
67-
progress {
68-
total
69-
done
70-
}
71-
nodes {
72-
type
73-
name
74-
}
75-
message
76-
statuses {
77-
since
78-
phase
79-
message
80-
}
81-
}
82-
pipeline {
47+
workflow(name: $name, namespace: $namespace, runtime: $runtime) {
8348
metadata {
84-
name
85-
namespace
49+
name
50+
namespace
8651
}
87-
}
88-
actualManifest
89-
}
90-
}`,
52+
projects
53+
spec {
54+
entrypoint
55+
templates {
56+
name
57+
}
58+
workflowTemplateRef {
59+
name
60+
namespace
61+
}
62+
}
63+
status {
64+
createdAt
65+
startedAt
66+
finishedAt
67+
phase
68+
progress {
69+
total
70+
done
71+
}
72+
nodes {
73+
type
74+
name
75+
}
76+
message
77+
statuses {
78+
since
79+
phase
80+
message
81+
}
82+
}
83+
pipeline {
84+
metadata {
85+
name
86+
namespace
87+
}
88+
}
89+
actualManifest
90+
}
91+
}`,
9192
"variables": map[string]interface{}{
9293
"runtime": runtime,
9394
"name": name,
@@ -98,68 +99,69 @@ func (w *workflowV2) Get(ctx context.Context, name, namespace, runtime string) (
9899
res := &graphqlGetWorkflowResponse{}
99100
err := w.codefresh.graphqlAPI(ctx, jsonData, res)
100101
if err != nil {
101-
return model.Workflow{}, fmt.Errorf("failed getting pipeline list: %w", err)
102+
return nil, fmt.Errorf("failed getting workflow: %w", err)
102103
}
103104

104105
if len(res.Errors) > 0 {
105-
return model.Workflow{}, graphqlErrorResponse{errors: res.Errors}
106+
return nil, graphqlErrorResponse{errors: res.Errors}
106107
}
107108

108-
return res.Data.Workflow, nil
109+
return &res.Data.Workflow, nil
109110
}
110111

111112
func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterArgs) ([]model.Workflow, error) {
112113
jsonData := map[string]interface{}{
113-
"query": `{
114-
workflows(filters: WorkflowFilterArgs) {
115-
edges {
116-
node {
117-
metadata {
118-
name
119-
namespace
120-
}
121-
projects
122-
spec {
123-
entrypoint
124-
templates {
125-
name
126-
}
127-
workflowTemplateRef {
128-
name
129-
namespace
130-
}
131-
}
132-
status {
133-
createdAt
134-
startedAt
135-
finishedAt
136-
phase
137-
progress {
138-
total
139-
done
140-
}
141-
nodes {
142-
type
143-
name
144-
}
145-
message
146-
statuses {
147-
since
148-
phase
149-
message
150-
}
151-
}
152-
pipeline {
114+
"query": `
115+
query Workflows($filters: WorkflowsFilterArgs) {
116+
workflows(filters: $filters) {
117+
edges {
118+
node {
153119
metadata {
154-
name
155-
namespace
120+
name
121+
namespace
156122
}
157-
}
158-
actualManifest
123+
projects
124+
spec {
125+
entrypoint
126+
templates {
127+
name
128+
}
129+
workflowTemplateRef {
130+
name
131+
namespace
132+
}
133+
}
134+
status {
135+
createdAt
136+
startedAt
137+
finishedAt
138+
phase
139+
progress {
140+
total
141+
done
142+
}
143+
nodes {
144+
type
145+
name
146+
}
147+
message
148+
statuses {
149+
since
150+
phase
151+
message
152+
}
153+
}
154+
pipeline {
155+
metadata {
156+
name
157+
namespace
158+
}
159+
}
160+
actualManifest
161+
}
159162
}
160163
}
161-
}
162-
}`,
164+
}`,
163165
"variables": map[string]interface{}{
164166
"filters": filterArgs,
165167
},
@@ -168,7 +170,7 @@ func (w *workflowV2) List(ctx context.Context, filterArgs model.WorkflowsFilterA
168170
res := &graphqlListWorkflowsResponse{}
169171
err := w.codefresh.graphqlAPI(ctx, jsonData, res)
170172
if err != nil {
171-
return nil, fmt.Errorf("failed getting pipeline list: %w", err)
173+
return nil, fmt.Errorf("failed getting workflow list: %w", err)
172174
}
173175

174176
if len(res.Errors) > 0 {

0 commit comments

Comments
 (0)