GitLabgitlab-org

cli

main
ply8 git calls233 ms99 KiB6 cachedprotocol v2
153 lines4.3 KiBRaw
1package releaseutils
3import (
4 "context"
5 "encoding/json"
6 "fmt"
7 "io"
8 "os"
9 "strings"
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/upload"
15 "gitlab.com/gitlab-org/cli/internal/glrepo"
16 "gitlab.com/gitlab-org/cli/internal/iostreams"
17 "gitlab.com/gitlab-org/cli/internal/tableprinter"
18 "gitlab.com/gitlab-org/cli/internal/utils"
21func DisplayAllReleases(io *iostreams.IOStreams, releases []*gitlab.Release, repoName string) string {
22 c := io.Color()
23 table := tableprinter.NewTablePrinter()
24 table.AddRow("Name", "Tag", "Created")
25 for _, r := range releases {
26 table.AddRow(r.Name, r.TagName, c.Gray(utils.TimeToPrettyTimeAgo(*r.CreatedAt)))
27 }
29 return table.Render()
32func RenderReleaseAssertLinks(assets []*gitlab.ReleaseLink) string {
33 if len(assets) == 0 {
34 return "There are no assets for this release"
35 }
36 t := tableprinter.NewTablePrinter()
37 for _, asset := range assets {
38 t.AddRow(asset.Name, asset.DirectAssetURL)
39 }
40 return t.String()
43func DisplayRelease(io *iostreams.IOStreams, r *gitlab.Release, repo glrepo.Interface) string {
44 c := io.Color()
45 duration := utils.TimeToPrettyTimeAgo(*r.CreatedAt)
46 description, err := utils.RenderMarkdown(r.Description, io.BackgroundColor())
47 if err != nil {
48 description = r.Description
49 }
51 var assetsSources strings.Builder
52 for _, asset := range r.Assets.Sources {
53 assetsSources.WriteString(asset.URL + "\n")
54 }
56 footer := fmt.Sprintf(c.Gray("View this release on GitLab at %s"), r.Links.Self)
57 return fmt.Sprintf("%s\n%s released this %s\n%s - %s\n%s\n%s\n%s\n%s\n%s\n\n%s", // whoops
58 c.Bold(r.Name), r.Author.Name, duration, r.Commit.ShortID, r.TagName, description, c.Bold("ASSETS"),
59 RenderReleaseAssertLinks(r.Assets.Links), c.Bold("SOURCES"), assetsSources.String(), footer,
60 )
63func AssetsFromArgs(args []string) ([]*upload.ReleaseFile, error) {
64 var assets []*upload.ReleaseFile
65 for _, arg := range args {
66 var label string
67 var linkType string
68 fn := arg
69 if arr := strings.SplitN(arg, "#", 3); len(arr) > 0 {
70 fn = arr[0]
71 if len(arr) > 1 {
72 label = arr[1]
73 }
74 if len(arr) > 2 {
75 linkType = arr[2]
76 }
77 }
79 var fi os.FileInfo
80 fi, err := os.Stat(fn)
81 if err != nil {
82 return assets, err
83 }
85 if label == "" {
86 label = fi.Name()
87 }
89 rf := &upload.ReleaseFile{
90 Open: func() (io.ReadCloser, error) {
91 return os.Open(fn)
92 },
93 Name: fi.Name(),
94 Label: label,
95 Path: fn,
96 }
98 // Only add a link type if it was specified
99 // Otherwise the GitLab API will default to 'other' if it was omitted
100 if linkType != "" {
101 linkTypeVal := gitlab.LinkTypeValue(linkType)
102 rf.Type = &linkTypeVal
103 }
105 assets = append(assets, rf)
106 }
107 return assets, nil
110// AssetLinksFromJSON parses the value of --assets-links. A null element is
111// refused here, before the command sends any request, because it decodes to a
112// nil link and the release commands dereference every link.
113func AssetLinksFromJSON(assetLinksJSON string) ([]*upload.ReleaseAsset, error) {
114 var links []*upload.ReleaseAsset
115 if err := json.Unmarshal([]byte(assetLinksJSON), &links); err != nil {
116 return nil, fmt.Errorf("failed to parse JSON string: %w", err)
117 }
118 for i, link := range links {
119 if link == nil {
120 return nil, fmt.Errorf("failed to parse JSON string: the asset link at index %d is null", i)
121 }
122 }
123 return links, nil
126func CreateReleaseAssets(ctx context.Context, io *iostreams.IOStreams, client *gitlab.Client, assetFiles []*upload.ReleaseFile, assetLinks []*upload.ReleaseAsset, repoName, tagName, packageName string, usePackageRegistry bool) error {
127 if assetFiles == nil && assetLinks == nil {
128 return nil
129 }
131 uploadCtx := upload.Context{
132 IO: io,
133 Client: client,
134 AssetsLinks: assetLinks,
135 AssetFiles: assetFiles,
136 }
138 color := io.Color()
139 io.LogInfof("%s Uploading release assets %s=%s %s=%s\n",
140 color.ProgressIcon(),
141 color.Blue("repo"), repoName,
142 color.Blue("tag"), tagName)
144 if err := uploadCtx.UploadFiles(ctx, repoName, tagName, packageName, usePackageRegistry); err != nil {
145 return cmdutils.WrapError(err, "upload failed")
146 }
148 // create asset link for assets provided as json
149 if err := uploadCtx.CreateReleaseAssetLinks(ctx, repoName, tagName); err != nil {
150 return cmdutils.WrapError(err, "failed to create release link")
151 }
152 return nil
Diagnostics8 git calls · 233 ms
CallStatusSizeTime0233 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 · 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=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 · hit5 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=5
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 · 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=1857
git.response.cache=HIT
git.response.duration_ms=4
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 · 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=350
git.response.cache=HIT
git.response.duration_ms=3
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:0200145 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=145
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=fd939ecfee6b4c8fd9edfe7831322b170467757f
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=145
git.pkt.payload.max=118
git.sideband.band1.bytes=118
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=118
git.pack.trailer=659e45f50374d89b1e4735a4852bfdc2e0e55abc
Open pack map
fetch2001.7 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=1740
git.response.cache=MISS
git.response.duration_ms=219
git.fetch.wants=d3f5e59c48090476d503342254e5d4d212057146
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=1740
git.pkt.payload.max=1713
git.sideband.band1.bytes=1713
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
a5e2d2422914cf3a
Request
e29bf3b0…
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