Skip to content

Commit

Permalink
fix: protect against '.updated_at' being null
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed May 31, 2024
1 parent 8793b1f commit 384e3ce
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions gh-notify
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@ get_notifs() {
def colored(text; color):
colors[color] + text + colors.reset;
.[] | {
updated_short: .updated_at | fromdateiso8601 | strftime("%Y-%m"),
updated_short:
# for some reason ".updated_at" can be null
if .updated_at then
.updated_at | fromdateiso8601 | strftime("%Y-%m")
else
# Github Discussion launched in 2020
# https://resources.github.com/devops/process/planning/discussions/
"2020"
end,
# UTC time ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
# https://docs.github.com/en/rest/overview/resources-in-the-rest-api#timezones
iso8601: now | strftime("%Y-%m-%dT%H:%M:%SZ"),
Expand All @@ -205,15 +213,21 @@ get_notifs() {
repo_full_name: .repository.full_name,
unread_symbol: colored((if .unread then "\u25cf" else "\u00a0" end); "magenta"),
# make sure each outcome has an equal number of fields separated by spaces
timefmt: colored(((if .unread then .last_read_at // .updated_at else .updated_at end) | fromdateiso8601) as $time_sec |
# difference is less than one hour
if ((now - $time_sec) / 3600) < 1 then
(now - $time_sec) / 60 | floor | tostring + "min ago"
# difference is less than 24 hours
elif ((now - $time_sec) / 3600) < 24 then
(now - $time_sec) / 3600 | floor | tostring + "h ago"
timefmt: colored(
# for some reason ".updated_at" can be null
if (.unread and .last_read_at) or .updated_at then
((if .unread then .last_read_at // .updated_at else .updated_at end) | fromdateiso8601) as $time_sec |
# difference is less than one hour
if ((now - $time_sec) / 3600) < 1 then
(now - $time_sec) / 60 | floor | tostring + "min ago"
# difference is less than 24 hours
elif ((now - $time_sec) / 3600) < 24 then
(now - $time_sec) / 3600 | floor | tostring + "h ago"
else
$time_sec | strflocaltime("%d/%b %H:%M")
end
else
$time_sec | strflocaltime("%d/%b %H:%M")
"Not available"
end; "gray"),
owner_abbreviated: colored(
if (.repository.owner.login | length) > 10 then
Expand Down

0 comments on commit 384e3ce

Please sign in to comment.