Skip to content

Commit 59237b8

Browse files
authored
Fix: Fixes the request workflowstep (#211)
1 parent d7db9c4 commit 59237b8

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

charts/vela-workflow/templates/definitions/request.yaml

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,45 @@ spec:
1414
cue:
1515
template: |
1616
import (
17-
"vela/op"
18-
"encoding/json"
17+
"vela/http"
18+
"vela/op"
19+
"encoding/json"
1920
)
2021
21-
http: op.#HTTPDo & {
22-
method: parameter.method
23-
url: parameter.url
24-
request: {
25-
if parameter.body != _|_ {
26-
body: json.Marshal(parameter.body)
27-
}
28-
if parameter.header != _|_ {
29-
header: parameter.header
30-
}
31-
}
32-
}
22+
req: http.#HTTPDo & {
23+
$params: {
24+
method: parameter.method
25+
url: parameter.url
26+
request: {
27+
if parameter.body != _|_ {
28+
body: json.Marshal(parameter.body)
29+
}
30+
if parameter.header != _|_ {
31+
header: parameter.header
32+
}
33+
}
34+
}
35+
} @step(1)
36+
37+
wait: op.#ConditionalWait & {
38+
continue: req.$returns != _|_
39+
message?: "Waiting for response from \(parameter.url)"
40+
} @step(2)
41+
3342
fail: op.#Steps & {
34-
if http.response.statusCode > 400 {
35-
requestFail: op.#Fail & {
36-
message: "request of \(parameter.url) is fail: \(http.response.statusCode)"
37-
}
38-
}
39-
}
40-
response: json.Unmarshal(http.response.body)
43+
if req.$returns.statusCode > 400 {
44+
requestFail: op.#Fail & {
45+
message: "request of \(parameter.url) is fail: \(req.$returns.statusCode)"
46+
}
47+
}
48+
} @step(3)
49+
50+
response: json.Unmarshal(req.$returns.body)
51+
4152
parameter: {
42-
url: string
43-
method: *"GET" | "POST" | "PUT" | "DELETE"
44-
body?: {...}
45-
header?: [string]: string
53+
url: string
54+
method: *"GET" | "POST" | "PUT" | "DELETE"
55+
body?: {...}
56+
header?: [string]: string
4657
}
4758

pkg/providers/http/http.cue

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@
3434
}
3535

3636
$returns?: {
37-
// +usage=The response of the request will be filled in this field after the action is executed
38-
response: {
39-
// +usage=The body of the response
40-
body: string
41-
// +usage=The header of the response
42-
header?: [string]: [...string]
43-
// +usage=The trailer of the response
44-
trailer?: [string]: [...string]
45-
// +usage=The status code of the response
46-
statusCode: int
47-
...
48-
}
37+
// +usage=The body of the response
38+
body: string
39+
// +usage=The header of the response
40+
header?: [string]: [...string]
41+
// +usage=The trailer of the response
42+
trailer?: [string]: [...string]
43+
// +usage=The status code of the response
44+
statusCode: int
45+
...
4946
}
5047
...
5148
}

0 commit comments

Comments
 (0)