From b36f11846bc884acb6463685ddb54b7531727990 Mon Sep 17 00:00:00 2001 From: Radek Stepan Date: Thu, 15 Aug 2013 15:25:42 +0100 Subject: [PATCH] a simple model for mapping closed issues into a chart --- README.md | 4 ---- src/chart.coffee | 9 +++++++++ src/issues.coffee | 1 + test/chart.coffee | 20 ++++++++++++++++++++ test/issues.coffee | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/chart.coffee create mode 100644 test/chart.coffee diff --git a/README.md b/README.md index 8519e76..f48c505 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,6 @@ [ ![Codeship Status for radekstepan/github-burndown-chart](https://www.codeship.io/projects/d69f4420-e5b0-0130-bbae-1632ddfb80f8/status?branch=rework)](https://www.codeship.io/projects/5855) -##Next - -Map closed tasks to a range of dates while maintaining the points remaining stats. - ##Project Charter The app is to display a burndown chart from a set of GitHub issues in a milestone. diff --git a/src/chart.coffee b/src/chart.coffee new file mode 100644 index 0000000..0b31067 --- /dev/null +++ b/src/chart.coffee @@ -0,0 +1,9 @@ +#!/usr/bin/env coffee +{ _ } = require 'lodash' + +module.exports = + # Map closed issues ready to be visualized. + # Assumes collection has been `filter`ed and is ordered. + 'closed': (collection, total, cb) -> + cb null, _.map collection, ({ closed_at, size }) -> + { x: +new Date(closed_at), y: total -= size } \ No newline at end of file diff --git a/src/issues.coffee b/src/issues.coffee index 017c116..b342677 100644 --- a/src/issues.coffee +++ b/src/issues.coffee @@ -4,6 +4,7 @@ async = require 'async' req = require './request' reg = require './regex' +dates = require './dates' module.exports = # Used on an initial fetch of issues for a repo. diff --git a/test/chart.coffee b/test/chart.coffee new file mode 100644 index 0000000..22d9324 --- /dev/null +++ b/test/chart.coffee @@ -0,0 +1,20 @@ +#!/usr/bin/env coffee +assert = require 'assert' +path = require 'path' + +chart = require path.resolve __dirname, '../src/chart.coffee' + +module.exports = + 'chartize closed issues': (done) -> + a = { number: 2, closed_at: '2013-05-09T09:04:53Z', size: 6 } + b = { number: 1, closed_at: '2013-05-09T10:04:53Z', size: 4 } + c = { number: 3, closed_at: '2013-05-12T09:04:53Z', size: 2 } + + chart.closed [ a, b, c ], 20, (err, data) -> + assert.ifError err + assert.deepEqual data, [ + { x: 1368090293000, y: 14 } + { x: 1368093893000, y: 10 } + { x: 1368349493000, y: 8 } + ] + done.call null \ No newline at end of file diff --git a/test/issues.coffee b/test/issues.coffee index 7a0acfb..b8da0c5 100644 --- a/test/issues.coffee +++ b/test/issues.coffee @@ -8,7 +8,7 @@ req = {} issues = proxy path.resolve(__dirname, '../src/issues.coffee'), './request': req -module.exports = +module.exports = 'all empty': (done) -> called = 0 req.all_issues = (opts, cb) ->