carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "net/http"
5 "sort"
6)
7
8type deploymentTarget struct {
9 Channel string
10 Target string
11 TargetErr string
12 HasHistory bool
13 Total int
14 Unknown int
15 Versions []deploymentObservedVersion
16}
17type deploymentObservedVersion struct {
18 Version string
19 Count int
20}
21type deploymentsCopyStrings struct{ Title, History, NoTarget, Instances, Target, Observed, NoChannels string }
22
23var deploymentsCopy = deploymentsCopyStrings{
24 Title: "Deployments",
25 History: "Release history",
26 NoTarget: "No target published",
27 Instances: "View instances",
28 Target: "Target version",
29 Observed: "Observed versions",
30 NoChannels: "Open Release history for the commands to publish your first version.",
31}
32
33func (p page) DeploymentsCopy() deploymentsCopyStrings { return deploymentsCopy }
34
35func assembleDeploymentTargets(view *AppView, account string) []deploymentTarget {
36 groups := map[string]*deploymentTarget{}
37 for _, ch := range view.Channels {
38 groups[ch.Name] = &deploymentTarget{Channel: ch.Name, Target: ch.Version, TargetErr: ch.Err, HasHistory: ch.HasHistory}
39 }
40 versions := map[string]map[string]int{}
41 for _, rt := range view.Routes {
42 if rt.Account != account || rt.Platform {
43 continue
44 }
45 ch := rt.Channel
46 if ch == "" {
47 ch = "stable"
48 }
49 if groups[ch] == nil {
50 groups[ch] = &deploymentTarget{Channel: ch}
51 }
52 group := groups[ch]
53 group.Total++
54 if (rt.Kind != "" && rt.Kind != "instance") || rt.Version == "" {
55 group.Unknown++
56 continue
57 }
58 if versions[ch] == nil {
59 versions[ch] = map[string]int{}
60 }
61 versions[ch][rt.Version]++
62 }
63 var names []string
64 for name := range groups {
65 names = append(names, name)
66 }
67 sort.Strings(names)
68 out := make([]deploymentTarget, 0, len(names))
69 for _, name := range names {
70 group := groups[name]
71 var vs []string
72 for v := range versions[name] {
73 vs = append(vs, v)
74 }
75 sort.Strings(vs)
76 for _, v := range vs {
77 group.Versions = append(group.Versions, deploymentObservedVersion{Version: v, Count: versions[name][v]})
78 }
79 out = append(out, *group)
80 }
81 return out
82}
83
84func releaseBackTab(r *http.Request) string {
85 switch r.FormValue("back") {
86 case "releases":
87 return "releases"
88 case "deployments":
89 return "deployments"
90 }
91 return ""
92}
93