From 14d5577bf815e136ab74097442731977f276f379 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 20 Nov 2018 14:57:50 +0100 Subject: [PATCH] Add duration to Slack notification. --- src/lib/Hydra/Plugin/SlackNotification.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/Hydra/Plugin/SlackNotification.pm b/src/lib/Hydra/Plugin/SlackNotification.pm index 07966683..cffb0d5f 100644 --- a/src/lib/Hydra/Plugin/SlackNotification.pm +++ b/src/lib/Hydra/Plugin/SlackNotification.pm @@ -7,6 +7,23 @@ use LWP::UserAgent; use Hydra::Helper::CatalystUtils; use JSON; +sub renderDuration { + my ($build) = @_; + my $duration = $build->stoptime - $build->starttime; + my $res = ""; + if ($duration >= 24*60*60) { + $res .= ($duration / (24*60*60)) . "d"; + } + if ($duration >= 60*60) { + $res .= (($duration / (60*60)) % 24) . "h"; + } + if ($duration >= 60) { + $res .= (($duration / 60) % 60) . "m"; + } + $res .= ($duration % 60) . "s"; + return $res; +} + sub buildFinished { my ($self, $build, $dependents) = @_; my $cfg = $self->{config}->{slack}; @@ -61,7 +78,7 @@ sub buildFinished { my $text = ""; $text .= "Job <$baseurl/job/${\$build->project->name}/${\$build->jobset->name}/${\$build->job->name}|${\showJobName($build)}>"; $text .= " (and ${\scalar @deps} others)" if scalar @deps > 0; - $text .= ": <$baseurl/build/${\$build->id}|" . showStatus($build) . ">"; + $text .= ": <$baseurl/build/${\$build->id}|" . showStatus($build) . ">". " in " . renderDuration($build); if (scalar keys %{$authors} > 0) { # FIXME: escaping