-
Notifications
You must be signed in to change notification settings - Fork 223
/
release.go
58 lines (48 loc) · 1.3 KB
/
release.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
package presenters
import (
"fmt"
"strings"
"github.com/superfly/flyctl/api"
)
type Releases struct {
Releases []api.Release
Release *api.Release
}
func (p *Releases) FieldNames() []string {
return []string{"Version", "Stable", "Type", "Status", "Description", "User", "Date"}
}
func (p *Releases) Records() []map[string]string {
out := []map[string]string{}
if p.Release != nil {
p.Releases = append(p.Releases, *p.Release)
}
for _, release := range p.Releases {
out = append(out, map[string]string{
"Version": fmt.Sprintf("v%d", release.Version),
"Stable": fmt.Sprintf("%t", release.Stable),
"Status": release.Status,
"Type": formatReleaseReason(release.Reason),
"Description": formatReleaseDescription(release),
"User": release.User.Email,
"Date": formatRelativeTime(release.CreatedAt),
})
}
return out
}
func formatReleaseReason(reason string) string {
switch reason {
case "change_image":
return "Image"
case "change_secrets":
return "Secrets"
case "change_code", "change_source": // nodeproxy
return "Code Change"
}
return reason
}
func formatReleaseDescription(r api.Release) string {
if r.Reason == "change_image" && strings.HasPrefix(r.Description, "deploy image ") {
return r.Description[13:]
}
return r.Description
}