GitLabgitlab-org
cli
main
1package list
3import (
4 "context"
5 "slices"
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/mr/mrutils"
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/text"
18)
20type options struct {
21 io *iostreams.IOStreams
22 factory cmdutils.Factory
23 gitlabClient func() (*gitlab.Client, error)
25 // Flags.
26 filePath string
27 outputFormat string
29 // Populated in complete.
30 client *gitlab.Client
31 mr *gitlab.MergeRequest
32 repo glrepo.Interface
33}
35func NewCmd(f cmdutils.Factory) *cobra.Command {
36 opts := &options{
37 io: f.IO(),
38 factory: f,
39 gitlabClient: f.GitLabClient,
40 }
42 cmd := &cobra.Command{
43 Use: "list [<id> | <branch>]",
44 Short: "List your pending review comments on a merge request. (EXPERIMENTAL)",
45 Long: heredoc.Docf(`
46 Human-readable output shows the ID of each pending comment, the file and line it targets, and the discussion it replies to. Pass the ID to %[1]sglab mr note draft update%[1]s or %[1]sglab mr note draft delete%[1]s.
48 JSON output returns the pending comment objects as the API reports them.
49 `, "`") + text.ExperimentalString,
50 Example: heredoc.Doc(`
51 # List your pending review comments on the current branch's merge request
52 glab mr note draft list
54 # List your pending review comments on merge request 123
55 glab mr note draft list 123
57 # List only pending comments on a specific file
58 glab mr note draft list 123 --file src/main.go
60 # Print the IDs of your pending comments
61 glab mr note draft list 123 -F json | jq '.[].id'
62 `),
63 Args: cobra.MaximumNArgs(1),
64 Annotations: map[string]string{
65 mcpannotations.Safe: "true",
66 },
67 RunE: func(cmd *cobra.Command, args []string) error {
68 if err := opts.complete(cmd, args); err != nil {
69 return err
70 }
71 return opts.run(cmd.Context())
72 },
73 }
75 cmd.Flags().StringVar(&opts.filePath, "file", "", "Show only pending diff comments on this file path.")
76 cmdutils.EnableJSONOutput(cmd, f.IO(), &opts.outputFormat)
78 return cmd
79}
81func (o *options) complete(cmd *cobra.Command, args []string) error {
82 client, err := o.gitlabClient()
83 if err != nil {
84 return err
85 }
86 o.client = client
88 mr, repo, err := mrutils.MRFromArgs(cmd.Context(), o.factory, args, "any")
89 if err != nil {
90 return err
91 }
92 o.mr = mr
93 o.repo = repo
94 return nil
95}
97func (o *options) run(ctx context.Context) error {
98 drafts, err := mrutils.ListAllDraftNotes(ctx, o.client, o.repo.FullName(), o.mr.IID)
99 if err != nil {
100 return err
101 }
103 if o.filePath != "" {
104 drafts = slices.DeleteFunc(drafts, func(d *gitlab.DraftNote) bool {
105 return d.Position == nil || (d.Position.NewPath != o.filePath && d.Position.OldPath != o.filePath)
106 })
107 }
109 if o.outputFormat == "json" {
110 return o.io.PrintJSON(drafts)
111 }
112 if len(drafts) == 0 {
113 o.io.LogInfo("No pending review comments found.")
114 return nil
115 }
116 mrutils.PrintDraftNotes(o.io, drafts)
117 return nil
118}
Diagnostics10 git calls · 208 ms
CallStatusSizeTime0208 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 KiB2 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=UPDATING 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
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 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=2 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: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=2 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=44Open pack map
fetchtree:02001.8 KiB · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=1857 git.response.cache=HIT git.response.duration_ms=1 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200746 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=746 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=f3d413a22af5a9c2fe9aa49709b1cb36d1351a7f 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=746 git.pkt.payload.max=719 git.sideband.band1.bytes=719 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=719 git.pack.trailer=330baf80c59a4208b55120dff7dd824b7952b790Open pack map
fetchtree:0200540 B · hit2 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=540 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=d1be7f980a856805fa31e30e01fff4db335cbe1b 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=540 git.pkt.payload.max=513 git.sideband.band1.bytes=513 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=513 git.pack.trailer=6c82398efd91c9e023d583b948fde889bd4991b2Open pack map
fetchtree:0200259 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=259 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=17c60670b892d93213e07c56d27bf8c78b2f6eee 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=259 git.pkt.payload.max=232 git.sideband.band1.bytes=232 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=232 git.pack.trailer=a86d2eccaf7aae3b0fec29dbfe655131faf5a4adOpen pack map
fetchtree:0200134 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=134 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=844f3e4c5e4134cddc834103e7d104ed5eeb3cd0 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=134 git.pkt.payload.max=107 git.sideband.band1.bytes=107 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=107 git.pack.trailer=8e6ed7a1882f58b8548ab7f7f041c414bd2747e5Open pack map
fetch2001.3 KiB192 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=192 git.response.bytes=1353 git.response.cache=MISS git.response.duration_ms=192 git.fetch.wants=f24400356ae9ef2c4944ae089f48f6e6c435f1da 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=1353 git.pkt.payload.max=1326 git.sideband.band1.bytes=1326 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
- a5e2cd723c817929
- Request
- e9779629…
- 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