From f3d9e7a749e99e35a85e7c3edaa0e9d78fbebec0 Mon Sep 17 00:00:00 2001 From: Mitchell Grice Date: Mon, 13 Jun 2016 12:21:08 +1000 Subject: [PATCH] Changed calcuation of 'Back to normal' time #225 --- .../java/jenkins/plugins/slack/ActiveNotifier.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java index 03ab2ecd..b0c6067a 100755 --- a/src/main/java/jenkins/plugins/slack/ActiveNotifier.java +++ b/src/main/java/jenkins/plugins/slack/ActiveNotifier.java @@ -372,14 +372,17 @@ public MessageBuilder appendCustomMessage() { } private String createBackToNormalDurationString(){ + // This status code guarantees that the previous build fails and has been successful before + // The back to normal time is the time since the build first broke Run previousSuccessfulBuild = build.getPreviousSuccessfulBuild(); - long previousSuccessStartTime = previousSuccessfulBuild.getStartTimeInMillis(); - long previousSuccessDuration = previousSuccessfulBuild.getDuration(); - long previousSuccessEndTime = previousSuccessStartTime + previousSuccessDuration; + Run initialFailureAfterPreviousSuccessfulBuild = previousSuccessfulBuild.getNextBuild(); + long initialFailureStartTime = initialFailureAfterPreviousSuccessfulBuild.getStartTimeInMillis(); + long initialFailureDuration = initialFailureAfterPreviousSuccessfulBuild.getDuration(); + long initialFailureEndTime = initialFailureStartTime + initialFailureDuration; long buildStartTime = build.getStartTimeInMillis(); long buildDuration = build.getDuration(); long buildEndTime = buildStartTime + buildDuration; - long backToNormalDuration = buildEndTime - previousSuccessEndTime; + long backToNormalDuration = buildEndTime - initialFailureEndTime; return Util.getTimeSpanString(backToNormalDuration); }