Repository navigation
Expand file tree
/
Copy pathUpdateChannelModel.js
More file actions
103 lines (87 loc) · 3.03 KB
/
Copy pathUpdateChannelModel.js
File metadata and controls
103 lines (87 loc) · 3.03 KB
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
.pragma library
var repositoryUrl = "https://github.com/basecamp/omarchy"
function normalizeChannel(value) {
var channel = String(value || "").trim().toLowerCase()
return ["stable", "rc", "edge", "dev"].indexOf(channel) !== -1
? channel
: "unknown"
}
function branchFor(channel, devBranch) {
var normalized = normalizeChannel(channel)
if (normalized === "rc") return "rc"
if (normalized === "dev") {
var checkoutBranch = String(devBranch || "").trim()
return checkoutBranch || "quattro"
}
return "quattro"
}
function contentOptions(channel) {
var normalized = normalizeChannel(channel)
var label = normalized === "unknown" ? "Omarchy" : normalized
return [
{ value: "changelog", label: "View " + label + " changelog" },
{ value: "pulls", label: "View " + label + " pull requests" },
{ value: "issues", label: "View " + label + " issues" }
]
}
function destination(channel, content, devBranch) {
var normalized = normalizeChannel(channel)
var kind = String(content || "changelog")
var branch = branchFor(normalized, devBranch)
if (kind === "pulls") {
return repositoryUrl + "/pulls?q=is%3Apr+is%3Aopen+base%3A"
+ encodeURIComponent(branch)
}
if (kind === "issues") return repositoryUrl + "/issues"
if (normalized === "stable") return repositoryUrl + "/releases/latest"
return repositoryUrl + "/commits/" + encodeURIComponent(branch)
}
function normalizeVisibility(value) {
var mode = String(value || "").trim()
return ["updates", "hidden", "always"].indexOf(mode) !== -1
? mode
: "updates"
}
function normalizePersistentVisibility(value) {
var mode = normalizeVisibility(value)
return mode === "hidden" ? "updates" : mode
}
function isHexColor(value) {
return /^#[0-9a-fA-F]{6}$/.test(String(value || "").trim())
}
function normalizeColor(value, fallback) {
var color = String(value || "").trim().toLowerCase()
var fallbackColor = String(fallback || "#a77bd8").trim().toLowerCase()
return isHexColor(color) ? color : fallbackColor
}
function presetForColor(value, presets, fallback) {
var color = normalizeColor(value, fallback)
for (var index = 0; index < presets.length; index++) {
if (String(presets[index].value).toLowerCase() === color) return color
}
return "custom"
}
function updateCommand(assumeYes) {
return assumeYes === true ? "omarchy update -y" : "omarchy update"
}
function channelCommand(channel) {
var normalized = normalizeChannel(channel)
return normalized === "unknown" ? "" : "omarchy channel set " + normalized
}
function normalizeSettings(
values,
currentVisibility,
fallbackColor
) {
var source = values || {}
var requestedVisibility = normalizeVisibility(source.visibilityMode)
var persistedVisibility = requestedVisibility === "hidden"
? normalizePersistentVisibility(currentVisibility)
: requestedVisibility
return {
assumeYes: source.assumeYes === true,
pulseColor: normalizeColor(source.pulseColor, fallbackColor),
visibilityMode: persistedVisibility,
hideRequested: requestedVisibility === "hidden"
}
}