From 919282cd873b88f34be3317aa73346b8a178aa06 Mon Sep 17 00:00:00 2001 From: Nicola Date: Mon, 10 Jul 2017 12:45:54 +0200 Subject: [PATCH] Fix: first build has started_at = null --- .../travis-builds-reporter-core/src/builds-utils.js | 11 +++++++---- packages/travis-builds-reporter-core/test/builds.json | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/travis-builds-reporter-core/src/builds-utils.js b/packages/travis-builds-reporter-core/src/builds-utils.js index a73dcd8..fb2ff37 100644 --- a/packages/travis-builds-reporter-core/src/builds-utils.js +++ b/packages/travis-builds-reporter-core/src/builds-utils.js @@ -38,12 +38,15 @@ module.exports = { // key will be date only (YYYY-MM-DD), value will be array of builds with that started_at date const dateKeysMap = new Map(); let build; - const filterFunc = entry => ( - extractDateOnly(entry.started_at) === extractDateOnly(build.started_at) - ); + const filterFunc = (entry) => { + // pick one that hopefully isn't null + const entryDate = entry.started_at || entry.finished_at; + const buildDate = build.started_at || build.finished_at; + return extractDateOnly(entryDate) === extractDateOnly(buildDate); + }; for (let i = 0; i < builds.length; i += 1) { build = builds[i]; - const buildDateTime = extractDateOnly(build.started_at); + const buildDateTime = extractDateOnly(build.started_at || build.finished_at); // if the key is present, its return value will be != null and we can skip insertion in map if (dateKeysMap.get(buildDateTime) == null) { dateKeysMap.set(buildDateTime, builds.filter(filterFunc)); diff --git a/packages/travis-builds-reporter-core/test/builds.json b/packages/travis-builds-reporter-core/test/builds.json index 815a208..91b1678 100644 --- a/packages/travis-builds-reporter-core/test/builds.json +++ b/packages/travis-builds-reporter-core/test/builds.json @@ -154,7 +154,7 @@ "pull_request_number": null, "config": [], "state": "passed", - "started_at": "2017-03-28T07:23:38Z", + "started_at": null, "finished_at": "2017-03-28T07:25:44Z", "duration": 126, "job_ids": []