GitLabgitlab-org

cli

main
ply10 git calls238 ms100 KiB8 cachedprotocol v2
141 lines3.9 KiBRaw
1package delete
3import (
4 "context"
5 "errors"
6 "fmt"
7 "strconv"
9 "github.com/MakeNowJust/heredoc/v2"
10 "github.com/spf13/cobra"
12 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
14 "gitlab.com/gitlab-org/cli/internal/cmdutils"
15 "gitlab.com/gitlab-org/cli/internal/commands/mr/mrutils"
16 "gitlab.com/gitlab-org/cli/internal/glrepo"
17 "gitlab.com/gitlab-org/cli/internal/iostreams"
18 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
19 "gitlab.com/gitlab-org/cli/internal/text"
22type options struct {
23 io *iostreams.IOStreams
24 factory cmdutils.Factory
25 gitlabClient func() (*gitlab.Client, error)
27 // Flags.
28 yes bool
30 // Populated in complete.
31 client *gitlab.Client
32 mr *gitlab.MergeRequest
33 repo glrepo.Interface
34 draftNoteID int64
35 draftBody string
38func NewCmd(f cmdutils.Factory) *cobra.Command {
39 opts := &options{
40 io: f.IO(),
41 factory: f,
42 gitlabClient: f.GitLabClient,
43 }
45 cmd := &cobra.Command{
46 Use: "delete [<id> | <branch>] <draft-note-id>",
47 Short: "Delete one of your pending review comments from a merge request. (EXPERIMENTAL)",
48 Long: heredoc.Docf(`
49 Discard a pending review comment before you publish the review. %[1]s<draft-note-id>%[1]s is the ID printed by %[1]sglab mr note draft create%[1]s or listed by %[1]sglab mr note draft list%[1]s.
51 Deletion is permanent and cannot be undone. Unless you pass %[1]s--yes%[1]s, the command shows the comment and prompts you to confirm. When not running interactively, %[1]s--yes%[1]s is required.
52 `, "`") + text.ExperimentalString,
53 Example: heredoc.Doc(`
54 # Delete pending review comment 456 from merge request 123
55 glab mr note draft delete 123 456
57 # Delete a pending review comment on the current branch's merge request
58 glab mr note draft delete 456
60 # Delete without confirmation
61 glab mr note draft delete 123 456 --yes
62 `),
63 Args: cobra.RangeArgs(1, 2),
64 Annotations: map[string]string{
65 mcpannotations.Destructive: "true",
66 },
67 RunE: func(cmd *cobra.Command, args []string) error {
68 if err := opts.validate(); err != nil {
69 return err
70 }
71 if err := opts.complete(cmd.Context(), args); err != nil {
72 return err
73 }
74 return opts.run(cmd.Context())
75 },
76 }
78 cmd.Flags().BoolVarP(&opts.yes, "yes", "y", false, "Skip confirmation prompt.")
80 return cmd
83func (o *options) complete(ctx context.Context, args []string) error {
84 idArg := args[len(args)-1]
85 draftNoteID, err := strconv.ParseInt(idArg, 10, 64)
86 if err != nil {
87 return fmt.Errorf("invalid pending review comment ID %q: must be a number", idArg)
88 }
89 o.draftNoteID = draftNoteID
91 client, err := o.gitlabClient()
92 if err != nil {
93 return err
94 }
95 o.client = client
97 mr, repo, err := mrutils.MRFromArgs(ctx, o.factory, args[:len(args)-1], "any")
98 if err != nil {
99 return err
100 }
101 o.mr = mr
102 o.repo = repo
104 draft, err := mrutils.GetDraftNote(ctx, client, repo.FullName(), mr.IID, draftNoteID)
105 if err != nil {
106 return err
107 }
108 o.draftBody = draft.Note
109 return nil
112// validate checks only flag values, so it runs before complete to reject bad
113// input without any API calls.
114func (o *options) validate() error {
115 if !o.yes && !o.io.PromptEnabled() {
116 return cmdutils.FlagError{Err: errors.New("--yes required when not running interactively")}
117 }
118 return nil
121func (o *options) run(ctx context.Context) error {
122 if !o.yes {
123 o.io.LogInfof("Pending review comment %d: %s\n", o.draftNoteID, mrutils.NotePreview(o.draftBody))
125 var confirmed bool
126 if err := o.io.Confirm(ctx, &confirmed, "Delete this pending review comment?"); err != nil {
127 return err
128 }
129 if !confirmed {
130 o.io.LogInfo("Aborted.")
131 return nil
132 }
133 }
135 if _, err := o.client.DraftNotes.DeleteDraftNote(o.repo.FullName(), o.mr.IID, o.draftNoteID, gitlab.WithContext(ctx)); err != nil {
136 return fmt.Errorf("failed to delete pending review comment: %w", err)
137 }
139 o.io.LogInfof("✓ Deleted pending review comment %d from !%d\n", o.draftNoteID, o.mr.IID)
140 return nil
Diagnostics10 git calls · 238 ms
CallStatusSizeTime0238 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
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 · 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: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
fetchtree:02001.8 KiB · 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=1857
git.response.cache=HIT
git.response.duration_ms=2
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:0200746 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=746
git.response.cache=HIT
git.response.duration_ms=2
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=330baf80c59a4208b55120dff7dd824b7952b790
Open 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=6c82398efd91c9e023d583b948fde889bd4991b2
Open pack map
fetchtree:0200259 B · hit4 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=259
git.response.cache=HIT
git.response.duration_ms=4
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=a86d2eccaf7aae3b0fec29dbfe655131faf5a4ad
Open pack map
fetchtree:0200139 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=139
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=ab90e01a9f4f08a6b0a9b69db49354f9dee75a09
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=139
git.pkt.payload.max=112
git.sideband.band1.bytes=112
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=112
git.pack.trailer=ba2164c4d3f529421e2b90f2acfcb1ed0991729c
Open pack map
fetch2001.6 KiB219 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=219
git.response.bytes=1661
git.response.cache=MISS
git.response.duration_ms=219
git.fetch.wants=ff874bf9a9b0ab597d21a059af6da91a9ea01a33
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=1661
git.pkt.payload.max=1634
git.sideband.band1.bytes=1634
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
a5e2ba9f69c4cf46
Request
b4d7cd2d…
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