Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit aaac660

Browse files
author
Sam McGeown
committed
Improve the get execution filters
1 parent 175b22c commit aaac660

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

cmd/api-func-executions.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/go-resty/resty/v2"
1515
"github.com/mitchellh/mapstructure"
16+
log "github.com/sirupsen/logrus"
1617
)
1718

1819
func getExecutions(id string, status string, name string, nested bool) ([]*CodestreamAPIExecutions, error) {
@@ -28,16 +29,30 @@ func getExecutions(id string, status string, name string, nested bool) ([]*Codes
2829
client := resty.New()
2930
var qParams = make(map[string]string)
3031
qParams["$orderby"] = "_requestTimeInMicros desc"
32+
33+
var filters []string
3134
if status != "" {
32-
qParams["$filter"] = "((status eq '" + strings.ToUpper(status) + "') and (_nested eq '" + strconv.FormatBool(nested) + "'))"
35+
filters = append(filters, "(status eq '"+strings.ToUpper(status)+"')")
3336
}
3437
if name != "" {
35-
qParams["$filter"] = "((name eq '" + name + "') and (_nested eq '" + strconv.FormatBool(nested) + "'))"
38+
filters = append(filters, "(name eq '"+name+"')")
39+
}
40+
if nested {
41+
filters = append(filters, "(_nested eq '"+strconv.FormatBool(nested)+"')")
42+
}
43+
if project != "" {
44+
filters = append(filters, "(project eq '"+project+"')")
3645
}
46+
if len(filters) > 0 {
47+
qParams["$filter"] = "(" + strings.Join(filters, ") and (") + ")"
48+
log.Debugln(qParams["$filter"])
49+
}
50+
3751
queryResponse, err := client.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: ignoreCert}).R().
3852
SetQueryParams(qParams).
3953
SetHeader("Accept", "application/json").
4054
SetResult(&documentsList{}).
55+
SetError(&CodeStreamException{}).
4156
SetAuthToken(targetConfig.accesstoken).
4257
Get("https://" + targetConfig.server + "/pipeline/api/executions")
4358
if queryResponse.IsError() {

cmd/execution.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func init() {
105105
getExecutionCmd.Flags().StringVarP(&name, "name", "n", "", "Name of the pipeline to list executions for")
106106
getExecutionCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the executions to list")
107107
getExecutionCmd.Flags().StringVarP(&status, "status", "s", "", "Filter executions by status (Completed|Waiting|Pausing|Paused|Resuming|Running)")
108+
getExecutionCmd.Flags().StringVarP(&project, "project", "p", "", "Filter executions by Project")
108109
getExecutionCmd.Flags().BoolVarP(&nested, "nested", "", false, "Include nested executions")
109110
// Delete
110111
deleteCmd.AddCommand(delExecutionCmd)

cmd/pipeline.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ cs-cli get execution --status Failed`,
101101
if task.Type == "Custom" {
102102
customintegrations = append(customintegrations, task.Input.Name)
103103
}
104-
log.Infoln("-- [Task]", n, "(", task.Type, ")")
104+
log.Debugln("-- [Task]", n, "(", task.Type, ")")
105105
}
106106
}
107107
if dependencies {

0 commit comments

Comments
 (0)