GitLabgitlab-org

cli

main
ply8 git calls204 ms99 KiB6 cachedprotocol v2
156 lines5.7 KiBRaw
1package list
3import (
4 "fmt"
5 "time"
7 "github.com/MakeNowJust/heredoc/v2"
8 "github.com/spf13/cobra"
10 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
12 "gitlab.com/gitlab-org/cli/internal/cmdutils"
13 "gitlab.com/gitlab-org/cli/internal/commands/ci/ciutils"
14 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
15 "gitlab.com/gitlab-org/cli/internal/utils"
18func NewCmdList(f cmdutils.Factory) *cobra.Command {
19 pipelineListCmd := &cobra.Command{
20 Use: "list [flags]",
21 Short: `List CI/CD pipelines.`,
22 Long: heredoc.Docf(`
23 Defaults to the current project. Use %[1]s--status%[1]s to filter pipelines by status.
24 `, "`"),
25 Example: heredoc.Doc(`
26 glab ci list
27 glab ci list --status=failed`),
28 Args: cobra.NoArgs,
29 ValidArgsFunction: cobra.NoFileCompletions,
30 Annotations: map[string]string{
31 mcpannotations.Safe: "true",
32 },
33 RunE: func(cmd *cobra.Command, args []string) error {
34 var err error
35 var titleQualifier string
37 client, err := f.GitLabClient()
38 if err != nil {
39 return err
40 }
42 repo, err := f.BaseRepo()
43 if err != nil {
44 return err
45 }
47 l := &gitlab.ListProjectPipelinesOptions{
48 ListOptions: gitlab.ListOptions{
49 Page: 1,
50 },
51 }
53 format, _ := cmd.Flags().GetString("output")
54 jsonOut := format == "json"
56 if m, _ := cmd.Flags().GetString("status"); m != "" {
57 l.Status = new(gitlab.BuildStateValue(m))
58 titleQualifier = m
59 }
60 // Support both --order and --orderBy (deprecated) for backward compatibility
61 var orderByValue string
62 if cmd.Flags().Changed("orderBy") {
63 orderByValue, _ = cmd.Flags().GetString("orderBy")
64 } else {
65 orderByValue, _ = cmd.Flags().GetString("order")
66 }
67 if orderByValue != "" {
68 l.OrderBy = new(orderByValue)
69 }
70 if m, _ := cmd.Flags().GetString("sort"); m != "" {
71 l.Sort = new(m)
72 }
73 if p, _ := cmd.Flags().GetInt("page"); p != 0 {
74 l.Page = int64(p)
75 }
76 if p, _ := cmd.Flags().GetInt("per-page"); p != 0 {
77 l.PerPage = int64(p)
78 }
79 if m, _ := cmd.Flags().GetString("ref"); m != "" {
80 l.Ref = new(m)
81 }
82 if m, _ := cmd.Flags().GetString("scope"); m != "" {
83 l.Scope = new(m)
84 }
85 if m, _ := cmd.Flags().GetString("source"); m != "" {
86 l.Source = new(m)
87 }
88 if m, _ := cmd.Flags().GetString("sha"); m != "" {
89 l.SHA = new(m)
90 }
91 if m, _ := cmd.Flags().GetBool("yaml-errors"); m {
92 l.YamlErrors = new(m)
93 }
94 if m, _ := cmd.Flags().GetString("name"); m != "" {
95 l.Name = new(m)
96 }
97 if m, _ := cmd.Flags().GetString("username"); m != "" {
98 l.Username = new(m)
99 }
100 if m, _ := cmd.Flags().GetString("updated-after"); m != "" {
101 updatedAfterTime, err := time.Parse("2006-01-02T15:04:05Z", m)
102 if err != nil {
103 return err
104 }
105 l.UpdatedAfter = new(updatedAfterTime)
106 }
107 if m, _ := cmd.Flags().GetString("updated-before"); m != "" {
108 updatedBeforeTime, err := time.Parse("2006-01-02T15:04:05Z", m)
109 if err != nil {
110 return err
111 }
112 l.UpdatedBefore = new(updatedBeforeTime)
113 }
115 pipes, resp, err := client.Pipelines.ListProjectPipelines(repo.FullName(), l)
116 if err != nil {
117 return err
118 }
120 title := utils.NewListTitle(fmt.Sprintf("%s pipeline", titleQualifier))
121 title.RepoName = repo.FullName()
122 title.Page = int(l.Page)
123 title.CurrentPageTotal = len(pipes)
124 if resp != nil {
125 title.Total = int(resp.TotalItems)
126 }
128 if jsonOut {
129 return f.IO().PrintJSON(pipes)
130 } else {
131 f.IO().LogInfof("%s\n%s\n", title.Describe(), ciutils.DisplayMultiplePipelines(f.IO(), pipes, repo.FullName()))
132 }
133 return nil
134 },
135 }
136 pipelineListCmd.Flags().StringP("status", "s", "", "Filter pipelines by status. Options: running, pending, success, failed, canceled, skipped, created, manual, waiting_for_resource, preparing, scheduled.")
137 pipelineListCmd.Flags().StringP("order", "o", "id", "Order pipelines by this field. Options: id, status, ref, updated_at, user_id.")
138 pipelineListCmd.Flags().String("orderBy", "id", "Deprecated: use --order instead.")
139 _ = pipelineListCmd.Flags().MarkDeprecated("orderBy", "use --order instead")
140 pipelineListCmd.Flags().StringP("sort", "", "desc", "Sort direction for '--order': asc or desc.")
141 pipelineListCmd.Flags().IntP("page", "p", 1, "Page number.")
142 pipelineListCmd.Flags().IntP("per-page", "P", 0, "Number of items to list per page. Defaults to the GitLab API default (20).")
143 pipelineListCmd.Flags().StringP("output", "F", "text", "Format output. Options: text, json.")
144 pipelineListCmd.Flags().StringP("ref", "r", "", "Return only pipelines for the given ref.")
145 pipelineListCmd.Flags().String("scope", "", "Return only pipelines with the given scope. Options: running, pending, finished, branches, tags.")
146 pipelineListCmd.Flags().String("source", "", "Return only pipelines triggered by the given source. For the full list, see https://docs.gitlab.com/ci/jobs/job_rules/#ci_pipeline_source-predefined-variable. Commonly used options: merge_request_event, parent_pipeline, pipeline, push, trigger.")
147 pipelineListCmd.Flags().String("sha", "", "Return only pipelines with the given SHA.")
148 pipelineListCmd.Flags().BoolP("yaml-errors", "y", false, "Return only pipelines with invalid configurations.")
149 pipelineListCmd.Flags().StringP("name", "n", "", "Return only pipelines with the given name.")
150 pipelineListCmd.Flags().StringP("username", "u", "", "Return only pipelines triggered by the given username.")
151 pipelineListCmd.Flags().StringP("updated-before", "b", "", "Return only pipelines updated before the specified date. Expected in ISO 8601 format (2019-03-15T08:00:00Z).")
152 pipelineListCmd.Flags().StringP("updated-after", "a", "", "Return only pipelines updated after the specified date. Expected in ISO 8601 format (2019-03-15T08:00:00Z).")
154 cmdutils.AddJQFlag(pipelineListCmd, f.IO())
155 return pipelineListCmd
Diagnostics8 git calls · 204 ms
CallStatusSizeTime0204 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:02001.8 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200635 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=635
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=517b073a0d5c32bc4e93f86de74b31d60ff8cf03
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=635
git.pkt.payload.max=608
git.sideband.band1.bytes=608
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=608
git.pack.trailer=178abb9456d874b7fd38fa21ad5cf9ca3ebcccaa
Open pack map
fetchtree:0200168 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=168
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=6ca5b26387fd434500ad395c6d60920a43ede2d5
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=168
git.pkt.payload.max=141
git.sideband.band1.bytes=141
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=141
git.pack.trailer=571be34d9227ee765b60b0ef0698b1edad444b18
Open pack map
fetch2001.9 KiB190 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=190
git.response.bytes=1947
git.response.cache=MISS
git.response.duration_ms=190
git.fetch.wants=fb43a107ee00a9a1bf358a48d538ce5f95c3c691
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1947
git.pkt.payload.max=1920
git.sideband.band1.bytes=1920
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2dec889a52308
Request
f8607fe4…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format