GitLabgitlab-org

cli

main
ply8 git calls341 ms99 KiB5 cachedprotocol v2
140 lines3.3 KiBRaw
1package delete
3import (
4 "fmt"
5 "strconv"
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/workitems/api"
14 "gitlab.com/gitlab-org/cli/internal/commands/workitems/utils"
15 "gitlab.com/gitlab-org/cli/internal/glrepo"
16 "gitlab.com/gitlab-org/cli/internal/iostreams"
17 "gitlab.com/gitlab-org/cli/internal/mcpannotations"
18 "gitlab.com/gitlab-org/cli/internal/text"
21type options struct {
22 // Dependencies
23 io *iostreams.IOStreams
24 baseRepo func() (glrepo.Interface, error)
25 gitlabClient func() (*gitlab.Client, error)
27 // Flags
28 group string
29 iid int64
31 // Internal state
32 scope *api.ScopeInfo
34 // Output
35 outputFormat string
38func NewCmd(f cmdutils.Factory) *cobra.Command {
39 opts := &options{
40 io: f.IO(),
41 baseRepo: f.BaseRepo,
42 gitlabClient: f.GitLabClient,
43 }
45 cmd := &cobra.Command{
46 Use: "delete <iid>",
47 Short: "Delete a work item in a project or group. (EXPERIMENTAL)",
48 Long: heredoc.Docf(`
49 Delete a work item by its internal ID (IID). This action cannot be undone.
51 The command behavior depends on context:
53 - By default, deletes from the current repository's project.
54 - With %[1]s--group%[1]s, deletes from the specified group.
55 - With %[1]s--repo%[1]s, deletes from the specified project.
56 `, "`") + text.ExperimentalString,
57 Example: heredoc.Doc(`
58 # Delete a work item by IID from the current project
59 glab work-items delete 42
61 # Delete a group work item
62 glab work-items delete 42 --group my-group
63 `),
64 Args: cobra.ExactArgs(1),
65 Annotations: map[string]string{
66 mcpannotations.Destructive: "true",
67 },
68 RunE: func(cmd *cobra.Command, args []string) error {
69 if err := opts.complete(cmd, args); err != nil {
70 return err
71 }
73 return opts.run()
74 },
75 }
77 // enable -R flag for repo override
78 cmdutils.EnableRepoOverride(cmd, f)
80 cmdutils.EnableJSONOutput(cmd, opts.io, &opts.outputFormat)
82 // Flags
83 fl := cmd.Flags()
84 fl.StringVarP(&opts.group, "group", "g", "", "Delete a work items from a group or subgroup.")
86 cmd.MarkFlagsMutuallyExclusive("group", "repo")
88 return cmd
91func (opts *options) complete(cmd *cobra.Command, args []string) error {
92 iid, err := strconv.ParseInt(args[0], 10, 64)
93 if err != nil {
94 return fmt.Errorf("invalid work item ID: %w", err)
95 }
96 opts.iid = iid
98 group, err := cmdutils.GroupOverride(cmd)
99 if err != nil {
100 return err
101 }
102 opts.group = group
104 scope, err := utils.DetectScope(opts.group, opts.baseRepo)
105 if err != nil {
106 return err
107 }
108 opts.scope = scope
109 return nil
112func (opts *options) run() error {
113 client, err := opts.gitlabClient()
114 if err != nil {
115 return fmt.Errorf("failed to get GitLab client: %w", err)
116 }
118 opts.io.LogInfo("- Deleting work item in", opts.scope.Path)
120 _, err = client.WorkItems.DeleteWorkItem(opts.scope.Path, opts.iid)
121 if err != nil {
122 return err
123 }
125 switch {
126 case opts.outputFormat == "json":
127 err := opts.io.PrintJSON(struct {
128 DeletedWorkItemID int64 `json:"deleted_work_item_id"`
129 }{DeletedWorkItemID: opts.iid})
130 if err != nil {
131 return err
132 }
133 case opts.io.IsaTTY:
134 opts.io.LogInfof("Successfully deleted %d\n", opts.iid)
135 default:
136 opts.io.LogInfo(opts.iid)
137 }
139 return nil
Diagnostics8 git calls · 341 ms
CallStatusSizeTime0341 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
fetchtree:0 · deepen 1020032 KiB · 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=32926
git.response.cache=HIT
git.response.duration_ms=4
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 · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=5
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=5
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 · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=7
git.response.bytes=1857
git.response.cache=HIT
git.response.duration_ms=7
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:0200317 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=317
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=33cd62a3f1bc55e6bd56a9b96f181ff12c30955a
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=317
git.pkt.payload.max=290
git.sideband.band1.bytes=290
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=290
git.pack.trailer=5711d3cc007ef3bd902f87854e977c46d0913d04
Open pack map
fetchtree:0200138 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=138
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=33585939f214e8f9d0b5e1dd76548384e32f6d87
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=138
git.pkt.payload.max=111
git.sideband.band1.bytes=111
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=111
git.pack.trailer=844194c8aaf77c6e220aed518965706eb4fb70f7
Open pack map
fetch2001.4 KiB322 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=322
git.response.bytes=1414
git.response.cache=MISS
git.response.duration_ms=322
git.fetch.wants=a37737f298b9ce5f63903b3c504e763a882ec7e6
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=1414
git.pkt.payload.max=1387
git.sideband.band1.bytes=1387
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
a5e247c18bbbee28
Request
7d0de67a…
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