Skip to content

Commit 384e3ce

Browse files
committed
fix: protect against '.updated_at' being null
1 parent 8793b1f commit 384e3ce

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

gh-notify

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,15 @@ get_notifs() {
195195
def colored(text; color):
196196
colors[color] + text + colors.reset;
197197
.[] | {
198-
updated_short: .updated_at | fromdateiso8601 | strftime("%Y-%m"),
198+
updated_short:
199+
# for some reason ".updated_at" can be null
200+
if .updated_at then
201+
.updated_at | fromdateiso8601 | strftime("%Y-%m")
202+
else
203+
# Github Discussion launched in 2020
204+
# https://resources.github.com/devops/process/planning/discussions/
205+
"2020"
206+
end,
199207
# UTC time ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
200208
# https://docs.github.com/en/rest/overview/resources-in-the-rest-api#timezones
201209
iso8601: now | strftime("%Y-%m-%dT%H:%M:%SZ"),
@@ -205,15 +213,21 @@ get_notifs() {
205213
repo_full_name: .repository.full_name,
206214
unread_symbol: colored((if .unread then "\u25cf" else "\u00a0" end); "magenta"),
207215
# make sure each outcome has an equal number of fields separated by spaces
208-
timefmt: colored(((if .unread then .last_read_at // .updated_at else .updated_at end) | fromdateiso8601) as $time_sec |
209-
# difference is less than one hour
210-
if ((now - $time_sec) / 3600) < 1 then
211-
(now - $time_sec) / 60 | floor | tostring + "min ago"
212-
# difference is less than 24 hours
213-
elif ((now - $time_sec) / 3600) < 24 then
214-
(now - $time_sec) / 3600 | floor | tostring + "h ago"
216+
timefmt: colored(
217+
# for some reason ".updated_at" can be null
218+
if (.unread and .last_read_at) or .updated_at then
219+
((if .unread then .last_read_at // .updated_at else .updated_at end) | fromdateiso8601) as $time_sec |
220+
# difference is less than one hour
221+
if ((now - $time_sec) / 3600) < 1 then
222+
(now - $time_sec) / 60 | floor | tostring + "min ago"
223+
# difference is less than 24 hours
224+
elif ((now - $time_sec) / 3600) < 24 then
225+
(now - $time_sec) / 3600 | floor | tostring + "h ago"
226+
else
227+
$time_sec | strflocaltime("%d/%b %H:%M")
228+
end
215229
else
216-
$time_sec | strflocaltime("%d/%b %H:%M")
230+
"Not available"
217231
end; "gray"),
218232
owner_abbreviated: colored(
219233
if (.repository.owner.login | length) > 10 then

0 commit comments

Comments
 (0)