GitLabgitlab-org

cli

main
ply8 git calls40 ms99 KiB6 cachedprotocol v2
140 lines3.4 KiBRaw
1package view
3import (
4 "errors"
5 "fmt"
6 "net/http"
8 "github.com/MakeNowJust/heredoc/v2"
9 "github.com/spf13/cobra"
11 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
13 "gitlab.com/gitlab-org/cli/internal/cmdutils"
14 "gitlab.com/gitlab-org/cli/internal/commands/release/releaseutils"
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 "gitlab.com/gitlab-org/cli/internal/utils"
22type options struct {
23 tagName string
24 openInBrowser bool
25 outputFormat string
27 io *iostreams.IOStreams
28 gitlabClient func() (*gitlab.Client, error)
29 baseRepo func() (glrepo.Interface, error)
30 config func() config.Config
33func NewCmdView(f cmdutils.Factory) *cobra.Command {
34 opts := &options{
35 io: f.IO(),
36 gitlabClient: f.GitLabClient,
37 baseRepo: f.BaseRepo,
38 config: f.Config,
39 }
41 cmd := &cobra.Command{
42 Use: "view [<tag>]",
43 Short: "View information about a GitLab release.",
44 Long: heredoc.Doc(`View information about a GitLab release.
46 Without an explicit tag name argument, shows the latest release in the project.
47 `),
48 Example: heredoc.Doc(`
49 # View the latest release of a GitLab repository
50 glab release view
52 # View a release with specified tag name
53 glab release view v1.0.1`),
54 Args: cobra.MaximumNArgs(1),
55 Annotations: map[string]string{
56 mcpannotations.Safe: "true",
57 },
58 RunE: func(cmd *cobra.Command, args []string) error {
59 opts.complete(args)
61 return opts.run()
62 },
63 }
65 cmd.Flags().BoolVarP(&opts.openInBrowser, "web", "w", false, "Open the release in the browser.")
66 cmdutils.EnableJSONOutput(cmd, opts.io, &opts.outputFormat)
68 return cmd
71func (o *options) complete(args []string) {
72 if len(args) == 1 {
73 o.tagName = args[0]
74 }
77func (o *options) run() error {
78 client, err := o.gitlabClient()
79 if err != nil {
80 return err
81 }
83 repo, err := o.baseRepo()
84 if err != nil {
85 return err
86 }
88 cfg := o.config()
90 var resp *gitlab.Response
91 var release *gitlab.Release
93 if o.tagName == "" {
94 releases, _, err := client.Releases.ListReleases(repo.FullName(), &gitlab.ListReleasesOptions{})
95 if err != nil {
96 return cmdutils.WrapError(err, "could not fetch latest release.")
97 }
98 if len(releases) < 1 {
99 return cmdutils.WrapError(errors.New("not found"), fmt.Sprintf("no release found for %q", repo.FullName()))
100 }
102 release = releases[0]
103 o.tagName = release.TagName
104 } else {
105 release, resp, err = client.Releases.GetRelease(repo.FullName(), o.tagName)
106 if err != nil {
107 if resp != nil && (resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusForbidden) {
108 return cmdutils.WrapError(err, "release does not exist.")
109 }
110 return cmdutils.WrapError(err, "failed to fetch release.")
111 }
112 }
114 if o.openInBrowser { // open in browser if --web flag is specified
115 url := release.Links.Self
117 if o.io.IsOutputTTY() {
118 o.io.LogInfof("Opening %s in your browser.\n", url)
119 }
121 browser, _ := cfg.Get(repo.RepoHost(), "browser")
122 return utils.OpenInBrowser(url, browser)
123 }
125 if o.outputFormat == "json" {
126 return o.io.PrintJSON(release)
127 }
129 glamourStyle, _ := cfg.Get(repo.RepoHost(), "glamour_style")
130 o.io.ResolveBackgroundColor(glamourStyle)
132 err = o.io.StartPager()
133 if err != nil {
134 return err
135 }
136 defer o.io.StopPager()
138 o.io.LogInfo(releaseutils.DisplayRelease(o.io, release, repo))
139 return nil
Diagnostics8 git calls · 40 ms
CallStatusSizeTime040 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · 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=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
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: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=2
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=fb03183b7909876778f740d196d7516811003517
Open 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=5
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=1232131042f2ba4c9c4dbd99382667a1f0849e15
Open pack map
fetchtree:0200168 B · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=24
git.response.bytes=168
git.response.cache=HIT
git.response.duration_ms=5
git.fetch.filter=tree:0
git.fetch.wants=7def0f4e0a74f8ffdb83c9e3bfb46139f12c1333
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=168
git.pkt.payload.max=141
git.sideband.band1.bytes=141
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=141
git.pack.trailer=10f4babb776ace75845c5f58e336a8d23cf85e0c
Open pack map
fetch2001.4 KiB · hit24 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1453
git.response.cache=HIT
git.response.duration_ms=24
git.fetch.wants=473e1a272d2e3a4fe5ec923a26e2f34195acd88d
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=1453
git.pkt.payload.max=1426
git.sideband.band1.bytes=1426
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
a5e2c09a787589da
Request
ec2c1294…
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