This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
releaseutils.go
107 lines (91 loc) · 2.65 KB
/
releaseutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package releaseutils
import (
"fmt"
"io"
"os"
"strings"
"github.com/profclems/glab/internal/glinstance"
"github.com/profclems/glab/internal/glrepo"
"github.com/profclems/glab/commands/release/releaseutils/upload"
"github.com/profclems/glab/pkg/iostreams"
"github.com/profclems/glab/pkg/tableprinter"
"github.com/profclems/glab/pkg/utils"
"github.com/xanzy/go-gitlab"
)
func DisplayAllReleases(io *iostreams.IOStreams, releases []*gitlab.Release, repoName string) string {
c := io.Color()
table := tableprinter.NewTablePrinter()
for _, r := range releases {
table.AddRow(r.Name, r.TagName, c.Gray(utils.TimeToPrettyTimeAgo(*r.CreatedAt)))
}
return table.Render()
}
func RenderReleaseAssertLinks(assets []*gitlab.ReleaseLink) string {
if len(assets) == 0 {
return "There are no assets for this release"
}
t := tableprinter.NewTablePrinter()
for _, asset := range assets {
t.AddRow(asset.Name, asset.DirectAssetURL)
//assetsPrint += asset.DirectAssetURL + "\n"
}
return t.String()
}
func DisplayRelease(io *iostreams.IOStreams, r *gitlab.Release, repo glrepo.Interface) string {
c := io.Color()
duration := utils.TimeToPrettyTimeAgo(*r.CreatedAt)
description, err := utils.RenderMarkdown(r.Description, io.BackgroundColor())
if err != nil {
description = r.Description
}
var assetsSources string
for _, asset := range r.Assets.Sources {
assetsSources += asset.URL + "\n"
}
url := fmt.Sprintf("%s://%s/%s/-/releases/%s",
glinstance.OverridableDefaultProtocol(), glinstance.OverridableDefault(),
repo.FullName(), r.TagName)
footer := fmt.Sprintf(c.Gray("View this release on GitLab at %s"), url)
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
c.Bold(r.Name), r.Author.Name, duration, r.Commit.ShortID, r.TagName, description, c.Bold("ASSETS"),
RenderReleaseAssertLinks(r.Assets.Links), c.Bold("SOURCES"), assetsSources, footer,
)
}
func AssetsFromArgs(args []string) (assets []*upload.ReleaseFile, err error) {
for _, arg := range args {
var label string
var linkType string
fn := arg
if arr := strings.SplitN(arg, "#", 3); len(arr) > 0 {
fn = arr[0]
if len(arr) > 1 {
label = arr[1]
}
if len(arr) > 2 {
linkType = arr[2]
}
}
var fi os.FileInfo
fi, err = os.Stat(fn)
if err != nil {
return
}
if label == "" {
label = fi.Name()
}
var linkTypeVal gitlab.LinkTypeValue
if linkType != "" {
linkTypeVal = gitlab.LinkTypeValue(linkType)
}
assets = append(assets, &upload.ReleaseFile{
Open: func() (io.ReadCloser, error) {
return os.Open(fn)
},
Name: fi.Name(),
Label: label,
Path: fn,
Type: &linkTypeVal,
})
}
return
}