-
Notifications
You must be signed in to change notification settings - Fork 332
/
actions_runs_list.go
107 lines (96 loc) · 2.94 KB
/
actions_runs_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package cmd
import (
"net/http"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/api/apigen"
"github.com/treeverse/lakefs/pkg/api/apiutil"
)
const actionsRunsListTemplate = `{{.ActionsRunsTable | table -}}
{{.Pagination | paginate }}
`
var actionsRunsListCmd = &cobra.Command{
Use: "list <repository URI> [--branch <branch>] [--commit <commit_id>]",
Short: "List runs",
Long: `List all runs on a repository optional filter by branch or commit`,
Example: "lakectl actions runs list " + myRepoExample + " --branch " + myBranchExample + " --commit " + myDigestExample,
Args: cobra.ExactArgs(1),
ValidArgsFunction: ValidArgsRepository,
Run: func(cmd *cobra.Command, args []string) {
amount := Must(cmd.Flags().GetInt("amount"))
after := Must(cmd.Flags().GetString("after"))
commit := Must(cmd.Flags().GetString("commit"))
branch := Must(cmd.Flags().GetString("branch"))
u := MustParseRepoURI("repository URI", args[0])
if commit != "" && branch != "" {
Die("Can't specify 'commit' and 'branch'", 1)
}
client := getClient()
ctx := cmd.Context()
// list runs with optional branch filter
var optionalBranch *string
if branch != "" {
optionalBranch = &branch
}
var optionalCommit *string
if commit != "" {
optionalCommit = &commit
}
resp, err := client.ListRepositoryRunsWithResponse(ctx, u.Repository, &apigen.ListRepositoryRunsParams{
After: apiutil.Ptr(apigen.PaginationAfter(after)),
Amount: apiutil.Ptr(apigen.PaginationAmount(amount)),
Branch: optionalBranch,
Commit: optionalCommit,
})
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
if resp.JSON200 == nil {
Die("Bad response from server", 1)
}
results := resp.JSON200.Results
rows := make([][]interface{}, len(results))
for i, row := range results {
rows[i] = []interface{}{
row.RunId,
row.EventType,
row.StartTime,
row.EndTime,
row.Branch,
row.CommitId,
row.Status,
}
}
pagination := resp.JSON200.Pagination
data := struct {
ActionsRunsTable *Table
Pagination *Pagination
}{
ActionsRunsTable: &Table{
Headers: []interface{}{
"Run ID",
"Event",
"Start Time",
"End Time",
"Branch",
"Commit ID",
"Status",
},
Rows: rows,
},
}
if pagination.HasMore {
data.Pagination = &Pagination{
Amount: amount,
HasNext: true,
After: pagination.NextOffset,
}
}
Write(actionsRunsListTemplate, data)
},
}
//nolint:gochecknoinits
func init() {
actionsRunsCmd.AddCommand(actionsRunsListCmd)
actionsRunsListCmd.Flags().Int("amount", defaultAmountArgumentValue, "number of results to return")
actionsRunsListCmd.Flags().String("after", "", "show results after this value (used for pagination)")
actionsRunsListCmd.Flags().String("branch", "", "show results for specific branch")
actionsRunsListCmd.Flags().String("commit", "", "show results for specific commit ID")
}