GitLabgitlab-org
cli
main
1package delete
3import (
4 "context"
5 "errors"
6 "fmt"
7 "net/http"
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/config"
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)
21type options struct {
22 forceDelete bool
23 deleteTag bool
24 tagName string
26 io *iostreams.IOStreams
27 gitlabClient func() (*gitlab.Client, error)
28 baseRepo func() (glrepo.Interface, error)
29 config func() config.Config
30}
32func NewCmdDelete(f cmdutils.Factory) *cobra.Command {
33 opts := &options{
34 io: f.IO(),
35 gitlabClient: f.GitLabClient,
36 baseRepo: f.BaseRepo,
37 config: f.Config,
38 }
40 cmd := &cobra.Command{
41 Use: "delete <tag>",
42 Short: "Delete a GitLab release.",
43 Long: heredoc.Docf(`Delete release assets to GitLab release. Requires the Maintainer role or higher.
45 Deleting a release does not delete the associated tag, unless you specify %[1]s--with-tag%[1]s.
46 `, "`"),
47 Args: cobra.ExactArgs(1),
48 Example: heredoc.Doc(`
49 # Delete a release (with a confirmation prompt)
50 glab release delete v1.1.0
52 # Skip the confirmation prompt and force delete
53 glab release delete v1.0.1 -y
55 # Delete release and associated tag
56 glab release delete v1.0.1 --with-tag`),
57 Annotations: map[string]string{
58 mcpannotations.Destructive: "true",
59 },
60 RunE: func(cmd *cobra.Command, args []string) error {
61 opts.complete(args)
63 if err := opts.validate(); err != nil {
64 return err
65 }
67 return opts.run(cmd.Context())
68 },
69 }
71 cmd.Flags().BoolVarP(&opts.forceDelete, "yes", "y", false, "Skip the confirmation prompt.")
72 cmd.Flags().BoolVarP(&opts.deleteTag, "with-tag", "t", false, "Delete the associated tag.")
74 return cmd
75}
77func (o *options) complete(args []string) {
78 o.tagName = args[0]
79}
81func (o *options) validate() error {
82 if !o.forceDelete && !o.io.PromptEnabled() {
83 return &cmdutils.FlagError{Err: errors.New("--yes or -y flag is required when not running interactively")}
84 }
86 return nil
87}
89func (o *options) run(ctx context.Context) error {
90 client, err := o.gitlabClient()
91 if err != nil {
92 return err
93 }
95 repo, err := o.baseRepo()
96 if err != nil {
97 return err
98 }
99 color := o.io.Color()
100 var resp *gitlab.Response
102 o.io.LogInfof("%s Validating tag %s=%s %s=%s\n",
103 color.ProgressIcon(),
104 color.Blue("repo"), repo.FullName(),
105 color.Blue("tag"), o.tagName)
107 release, resp, err := client.Releases.GetRelease(repo.FullName(), o.tagName)
108 if err != nil {
109 if resp != nil && (resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusForbidden) {
110 return cmdutils.WrapError(err, fmt.Sprintf("no release found for %q.", repo.FullName()))
111 }
112 return cmdutils.WrapError(err, "failed to fetch release.")
113 }
115 if !o.forceDelete && o.io.PromptEnabled() {
116 o.io.LogInfof("This action will permanently delete release %q immediately.\n\n", release.TagName)
117 err = o.io.Confirm(ctx, &o.forceDelete, fmt.Sprintf("Are you ABSOLUTELY SURE you wish to delete this release %q?", release.Name))
118 if err != nil {
119 return cmdutils.WrapError(err, "could not prompt")
120 }
121 }
123 if !o.forceDelete {
124 return cmdutils.CancelError()
125 }
127 o.io.LogInfof("%s Deleting release %s=%s %s=%s\n",
128 color.ProgressIcon(),
129 color.Blue("repo"), repo.FullName(),
130 color.Blue("tag"), o.tagName)
132 release, _, err = client.Releases.DeleteRelease(repo.FullName(), release.TagName)
133 if err != nil {
134 return cmdutils.WrapError(err, "failed to delete release.")
135 }
137 o.io.LogInfof(color.Bold("%s Release %q deleted.\n"), color.RedCheck(), release.Name)
139 if o.deleteTag {
141 o.io.LogInfof("%s Deleting associated tag %q.\n",
142 color.ProgressIcon(), o.tagName)
144 _, err = client.Tags.DeleteTag(repo.FullName(), release.TagName)
145 if err != nil {
146 return cmdutils.WrapError(err, "failed to delete tag.")
147 }
149 o.io.LogInfof(color.Bold("%s Tag %q deleted.\n"), color.RedCheck(), release.Name)
150 }
151 return nil
152}
Diagnostics8 git calls · 227 ms
CallStatusSizeTime0227 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
fetchtree:0 · deepen 1020032 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=32926 git.response.cache=HIT git.response.duration_ms=2 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
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 · 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=fb03183b7909876778f740d196d7516811003517Open pack map
fetchtree:0200350 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=350 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=b2a837e646ba305993f35203fafafb109e57a7ca 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=350 git.pkt.payload.max=323 git.sideband.band1.bytes=323 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=323 git.pack.trailer=1232131042f2ba4c9c4dbd99382667a1f0849e15Open pack map
fetchtree:0200138 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=138 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=225395e9ee95c76c80156a4b863bad567fdd8cf1 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=2990233a8e9bd91e5d8d8432c4b9013c512bc953Open pack map
fetch2001.5 KiB211 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=211 git.response.bytes=1570 git.response.cache=MISS git.response.duration_ms=211 git.fetch.wants=9d3789ffa06a4ac7744d9d1046be1b31d510e2d3 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=1570 git.pkt.payload.max=1543 git.sideband.band1.bytes=1543 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
- a5e2c9739aa94b67
- Request
- 39339fea…
- 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