GitLabgitlab-org

cli

main
ply8 git calls250 ms99 KiB6 cachedprotocol v2
174 lines5.1 KiBRaw
1package list
3import (
4 "fmt"
5 "strings"
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/api"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/glrepo"
15 "gitlab.com/gitlab-org/cli/internal/iostreams"
16 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
17 "gitlab.com/gitlab-org/cli/internal/utils"
20type options struct {
21 io *iostreams.IOStreams
22 apiClient func(repoHost string) (*api.Client, error)
23 baseRepo func() (glrepo.Interface, error)
24 group string
25 page int
26 perPage int
27 outputFormat string
30func NewCmdList(f cmdutils.Factory) *cobra.Command {
31 opts := &options{
32 io: f.IO(),
33 apiClient: f.ApiClient,
34 baseRepo: f.BaseRepo,
35 }
37 iterationListCmd := &cobra.Command{
38 Use: "list [flags]",
39 Short: `List project iterations.`,
40 Long: heredoc.Docf(`
41 By default, lists the iterations for the current project. Use
42 %[1]s--group%[1]s to list a group's iterations instead, or %[1]s--repo%[1]s to
43 target a project other than the current one.
44 `, "`"),
45 Aliases: []string{"ls"},
46 Example: heredoc.Doc(`
47 glab iteration list
48 glab iteration ls
49 glab iteration list -R owner/repository
50 glab iteration list -g mygroup`),
51 Args: cobra.NoArgs,
52 ValidArgsFunction: cobra.NoFileCompletions,
53 Annotations: map[string]string{
54 mcpannotations.Safe: "true",
55 },
56 RunE: func(cmd *cobra.Command, args []string) error {
57 return opts.run()
58 },
59 }
61 iterationListCmd.Flags().IntVarP(&opts.page, "page", "p", 1, "Page number.")
62 iterationListCmd.Flags().IntVarP(&opts.perPage, "per-page", "P", 30, "Number of items to list per page.")
63 cmdutils.EnableJSONOutput(iterationListCmd, opts.io, &opts.outputFormat)
64 iterationListCmd.Flags().StringVarP(&opts.group, "group", "g", "", "List iterations for a group.")
65 return iterationListCmd
68type listProjectIterationsOptions struct {
69 IncludeAncestors *bool
70 PerPage int64
71 Page int64
74func (opts *listProjectIterationsOptions) listProjectIterationsOptions() *gitlab.ListProjectIterationsOptions {
75 projectOpts := &gitlab.ListProjectIterationsOptions{}
76 projectOpts.IncludeAncestors = opts.IncludeAncestors
77 projectOpts.PerPage = opts.PerPage
78 projectOpts.Page = opts.Page
79 return projectOpts
82func (opts *listProjectIterationsOptions) listGroupIterationsOptions() *gitlab.ListGroupIterationsOptions {
83 groupOpts := &gitlab.ListGroupIterationsOptions{}
84 groupOpts.IncludeAncestors = opts.IncludeAncestors
85 groupOpts.PerPage = opts.PerPage
86 groupOpts.Page = opts.Page
87 return groupOpts
90func (o *options) run() error {
91 // NOTE: this command can not only be used for projects,
92 // so we have to manually check for the base repo, if it doesn't exist,
93 // we bootstrap the client with the default hostname.
94 var repoHost string
95 if baseRepo, err := o.baseRepo(); err == nil {
96 repoHost = baseRepo.RepoHost()
97 }
98 apiClient, err := o.apiClient(repoHost)
99 if err != nil {
100 return err
101 }
102 client := apiClient.Lab()
104 iterationApiOpts := &listProjectIterationsOptions{}
105 iterationApiOpts.IncludeAncestors = new(true)
107 if o.page != 0 {
108 iterationApiOpts.Page = int64(o.page)
109 }
110 if o.perPage != 0 {
111 iterationApiOpts.PerPage = int64(o.perPage)
112 } else {
113 iterationApiOpts.PerPage = api.DefaultListLimit
114 }
116 var iterationBuilder strings.Builder
118 if o.group != "" {
119 iterations, resp, err := client.GroupIterations.ListGroupIterations(o.group, iterationApiOpts.listGroupIterationsOptions())
120 if err != nil {
121 return err
122 }
123 if o.outputFormat == "json" {
124 if err := o.io.PrintJSON(iterations); err != nil {
125 return err
126 }
127 } else {
128 o.io.LogInfof("%s\n", o.listTitle(o.group, len(iterations), resp))
129 for _, iteration := range iterations {
130 iterationBuilder.WriteString(formatIterationInfo(iteration.Description, iteration.Title, iteration.WebURL))
131 }
132 o.io.LogInfo(utils.Indent(iterationBuilder.String(), " "))
133 }
134 } else {
135 repo, err := o.baseRepo()
136 if err != nil {
137 return err
138 }
139 iterations, resp, err := client.ProjectIterations.ListProjectIterations(repo.FullName(), iterationApiOpts.listProjectIterationsOptions())
140 if err != nil {
141 return err
142 }
143 if o.outputFormat == "json" {
144 if err := o.io.PrintJSON(iterations); err != nil {
145 return err
146 }
147 } else {
148 o.io.LogInfof("%s\n", o.listTitle(repo.FullName(), len(iterations), resp))
149 for _, iteration := range iterations {
150 iterationBuilder.WriteString(formatIterationInfo(iteration.Description, iteration.Title, iteration.WebURL))
151 }
152 o.io.LogInfo(utils.Indent(iterationBuilder.String(), " "))
153 }
154 }
155 return nil
158func formatIterationInfo(description string, title string, webURL string) string {
159 if description != "" {
160 description = fmt.Sprintf(" -> %s", description)
161 }
162 return fmt.Sprintf("%s%s (%s)\n", title, description, webURL)
165func (o *options) listTitle(repoName string, count int, resp *gitlab.Response) string {
166 title := utils.NewListTitle("iteration")
167 title.RepoName = repoName
168 title.Page = o.page
169 title.CurrentPageTotal = count
170 if resp != nil {
171 title.Total = int(resp.TotalItems)
172 }
173 return title.Describe()
Diagnostics8 git calls · 250 ms
CallStatusSizeTime0250 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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=4
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 · hit4 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=4
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:0200173 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=173
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=8ac918baeed3139875cbcdc137f38cfb62fb2dd1
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=173
git.pkt.payload.max=146
git.sideband.band1.bytes=146
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=146
git.pack.trailer=9ba4921db5e89ed276b38a8c60b7a7cb31d1e799
Open pack map
fetchtree:0200144 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=236
git.response.bytes=144
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=2027645b4787a18b14dbda23b058e4fa9995a3d6
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=144
git.pkt.payload.max=117
git.sideband.band1.bytes=117
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=117
git.pack.trailer=aae2511ccb89aa136f2c1ef74b4cb9f466c4efbb
Open pack map
fetch2001.7 KiB236 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1755
git.response.cache=MISS
git.response.duration_ms=236
git.fetch.wants=2362c1ec9f9b104d649901b7745c9f7ea85149f9
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=1755
git.pkt.payload.max=1728
git.sideband.band1.bytes=1728
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
a5e2f564dabd3a24
Request
1462eb02…
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