Skip to content

Commit b8fecb7

Browse files
haasadsimu
andcommitted
Update component/espejote-templates/upgrade-notification.jsonnet
Co-authored-by: Simon Gerber <[email protected]>
1 parent 805fd04 commit b8fecb7

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

component/espejote-templates/upgrade-notification.jsonnet

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ local upgradeWindow = if nextChannelOverlay != null then
2929
local formatDate(date) =
3030
local lastChange = std.reverse([t for t in std.objectFields(dst) if t < date])[0];
3131
local UTCOffset = dst[lastChange];
32-
local YMD = std.split(date, 'T')[0];
33-
local Y = std.split(YMD, '-')[0];
34-
local M = std.split(YMD, '-')[1];
35-
local D = std.split(YMD, '-')[2];
36-
local hms = std.split(date, 'T')[1];
37-
local h = std.toString(std.parseInt(std.split(hms, ':')[0]) + UTCOffset);
38-
local m = std.split(hms, ':')[1];
32+
local parts = std.split(date, 'T');
33+
assert std.length(parts) == 2 : 'Expected RFC-3339 datetime to have exactly one "T"';
34+
local YMD = std.split(parts[0], '-');
35+
assert std.length(YMD) == 3 : 'Expected RFC-3339 date to have exactly two "-"';
36+
local Y = YMD[0];
37+
local M = YMD[1];
38+
local D = YMD[2];
39+
local hms = std.split(parts[1], ':');
40+
assert std.length(hms) == 3 : 'Expected RFC-3339 time to have exactly two ":"';
41+
local h = std.toString(std.parseInt(hms[0]) + UTCOffset);
42+
local m = hms[1];
3943
'%s.%s.%s %s:%s' % [D, M, Y, h, m];
4044

4145
local replacementValues = {
@@ -69,4 +73,5 @@ local makeConsoleNotification(name, args, repl) =
6973
),
7074
};
7175

72-
if upgradeWindow != null then makeConsoleNotification('upgrade-%s' % replacementValues['$OVERLAY_VERSION'], config.notification, replacementValues)
76+
#if upgradeWindow != null then makeConsoleNotification('upgrade-%s' % replacementValues['$OVERLAY_VERSION'], config.notification, replacementValues)
77+
std.reverse(std.sort(std.objectFields(replacementValues), keyF=function(it) std.length(it)))

tests/golden/upgrade-notification/openshift4-console/openshift4-console/31_upgrade_notification.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ spec:
6868
local formatDate(date) =
6969
local lastChange = std.reverse([t for t in std.objectFields(dst) if t < date])[0];
7070
local UTCOffset = dst[lastChange];
71-
local YMD = std.split(date, 'T')[0];
72-
local Y = std.split(YMD, '-')[0];
73-
local M = std.split(YMD, '-')[1];
74-
local D = std.split(YMD, '-')[2];
75-
local hms = std.split(date, 'T')[1];
76-
local h = std.toString(std.parseInt(std.split(hms, ':')[0]) + UTCOffset);
77-
local m = std.split(hms, ':')[1];
71+
local parts = std.split(date, 'T');
72+
assert std.length(parts) == 2 : 'Expected RFC-3339 datetime to have exactly one "T"';
73+
local YMD = std.split(parts[0], '-');
74+
assert std.length(YMD) == 3 : 'Expected RFC-3339 date to have exactly two "-"';
75+
local Y = YMD[0];
76+
local M = YMD[1];
77+
local D = YMD[2];
78+
local hms = std.split(parts[1], ':');
79+
assert std.length(hms) == 3 : 'Expected RFC-3339 time to have exactly two ":"';
80+
local h = std.toString(std.parseInt(hms[0]) + UTCOffset);
81+
local m = hms[1];
7882
'%s.%s.%s %s:%s' % [D, M, Y, h, m];
7983
8084
local replacementValues = {
@@ -108,7 +112,8 @@ spec:
108112
),
109113
};
110114
111-
if upgradeWindow != null then makeConsoleNotification('upgrade-%s' % replacementValues['$OVERLAY_VERSION'], config.notification, replacementValues)
115+
#if upgradeWindow != null then makeConsoleNotification('upgrade-%s' % replacementValues['$OVERLAY_VERSION'], config.notification, replacementValues)
116+
std.reverse(std.sort(std.objectFields(replacementValues), keyF=function(it) std.length(it)))
112117
triggers:
113118
- name: clusterversion_appuio
114119
watchContextResource:

0 commit comments

Comments
 (0)