GitLabgitlab-org

cli

main
ply8 git calls246 ms99 KiB6 cachedprotocol v2
135 lines3.6 KiBRaw
1package delete
3import (
4 "context"
5 "fmt"
6 "net/http"
7 "strings"
9 "github.com/MakeNowJust/heredoc/v2"
10 "github.com/spf13/cobra"
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"
19type options struct {
20 forceDelete bool
21 repoName string
22 args []string
24 io *iostreams.IOStreams
25 apiClient func(repoHost string) (*api.Client, error)
26 baseRepo func() (glrepo.Interface, error)
29func NewCmdDelete(f cmdutils.Factory) *cobra.Command {
30 opts := &options{
31 io: f.IO(),
32 apiClient: f.ApiClient,
33 baseRepo: f.BaseRepo,
34 }
36 projectCreateCmd := &cobra.Command{
37 Use: "delete [[<NAMESPACE>/]<NAME>]",
38 Short: `Delete an existing project on GitLab.`,
39 Long: heredoc.Doc(`
40 Delete an existing project on GitLab.
42 Without an argument, targets the project for the current repository.
44 This permanently deletes the entire project, including:
46 - The Git repository.
47 - Issues and merge requests.
48 - Wiki pages.
49 - CI/CD pipelines and job artifacts.
50 - Other project content and settings.
52 This action cannot be undone.
53 `),
54 Args: cobra.MaximumNArgs(1),
55 Example: heredoc.Doc(`
56 # Delete a personal project.
57 glab repo delete dotfiles
59 # Delete a project in a GitLab group, or another project
60 # you have write access to:
61 glab repo delete mygroup/dotfiles
62 glab repo delete myorg/mynamespace/dotfiles`),
63 Annotations: map[string]string{
64 mcpannotations.Destructive: "true",
65 },
66 RunE: func(cmd *cobra.Command, args []string) error {
67 opts.args = args
68 return opts.run(cmd.Context())
69 },
70 }
72 projectCreateCmd.Flags().BoolVarP(&opts.forceDelete, "yes", "y", false, "Skip the confirmation prompt and immediately delete the project.")
74 return projectCreateCmd
77func (o *options) run(ctx context.Context) error {
78 c, err := o.apiClient("")
79 if err != nil {
80 return err
81 }
82 gitlabClient := c.Lab()
84 baseRepo, baseRepoErr := o.baseRepo() // don't handle error yet
85 if len(o.args) == 1 {
86 o.repoName = o.args[0]
88 if !strings.ContainsRune(o.repoName, '/') {
89 namespace := ""
90 if baseRepoErr == nil {
91 namespace = baseRepo.RepoOwner()
92 } else {
93 currentUser, _, err := gitlabClient.Users.CurrentUser()
94 if err != nil {
95 return err
96 }
97 namespace = currentUser.Username
98 }
99 o.repoName = fmt.Sprintf("%s/%s", namespace, o.repoName)
100 }
101 } else {
102 if baseRepoErr != nil {
103 return baseRepoErr
104 }
105 o.repoName = baseRepo.FullName()
106 }
108 if !o.forceDelete && !o.io.PromptEnabled() {
109 return &cmdutils.FlagError{Err: fmt.Errorf("--yes or -y flag is required when not running interactively")}
110 }
112 if !o.forceDelete && o.io.PromptEnabled() {
113 o.io.LogErrorf("This action will permanently delete the project %s immediately, including its repositories and all content: issues, merge requests, wiki, CI/CD data, and all other project resources.\n\n", o.repoName)
114 err = o.io.Confirm(ctx, &o.forceDelete, fmt.Sprintf("Are you ABSOLUTELY SURE you wish to delete %s?", o.repoName))
115 if err != nil {
116 return err
117 }
118 }
120 if o.forceDelete {
121 if o.io.IsErrTTY && o.io.IsaTTY {
122 o.io.LogErrorf("- Deleting project %s\n", o.repoName)
123 }
124 resp, err := gitlabClient.Projects.DeleteProject(o.repoName, nil)
125 if err != nil && resp == nil {
126 return err
127 }
128 if resp.StatusCode == http.StatusUnauthorized {
129 return fmt.Errorf("you are not authorized to delete %s; check your token used for glab and make sure it has the `api` and `write_repository` scopes enabled", o.repoName)
130 }
131 return err
132 }
133 o.io.LogError("aborted by user")
134 return nil
Diagnostics8 git calls · 246 ms
CallStatusSizeTime0246 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 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 · 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=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 · 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=44
Open 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=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200614 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=614
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=3a89d0cfc8e81880c982180388e42e561a0b7eee
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=614
git.pkt.payload.max=587
git.sideband.band1.bytes=587
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=587
git.pack.trailer=eb8250f8e8340ff2fafc22c5aba90db34fd906a9
Open pack map
fetchtree:0200138 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=138
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=43bdcb87e1b93ee7e4f288551b5841bb63f8bfcd
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=fee0326c73442b3ee8f5236b0908472345c93063
Open pack map
fetch2001.6 KiB234 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=234
git.response.bytes=1643
git.response.cache=MISS
git.response.duration_ms=234
git.fetch.wants=94ae6431509d1559a87aae838b0c11168d966d76
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=1643
git.pkt.payload.max=1616
git.sideband.band1.bytes=1616
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
a5ea5665dd487089
Request
2e37cb00…
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