From 99534404dfc82dd587f965f282a1abfafbe73c17 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Wed, 6 Aug 2014 19:56:39 -0700 Subject: [PATCH] added todos task --- TODOS.md | 34 ++++++++++++++++ package.json | 2 +- tasks/todos.js | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 TODOS.md create mode 100644 tasks/todos.js diff --git a/TODOS.md b/TODOS.md new file mode 100644 index 000000000000..2d5a640ae257 --- /dev/null +++ b/TODOS.md @@ -0,0 +1,34 @@ +# TODO items +> Automatically extracted + + - **src/kibana/apps/dashboard/directives/grid.js** + - change this from event based to calling a method on dashboardApp – [L68](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/dashboard/directives/grid.js#L68) + - **src/kibana/apps/discover/controllers/discover.js** + - Switch this to watching time.string when we implement it – [L148](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/discover/controllers/discover.js#L148) + - On array fields, negating does not negate the combination, rather all terms – [L431](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/discover/controllers/discover.js#L431) + - Move to utility class – [L496](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/discover/controllers/discover.js#L496) + - Move to utility class – [L506](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/discover/controllers/discover.js#L506) + - **src/kibana/apps/settings/sections/indices/_create.js** + - we should probably display a message of some kind – [L111](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/settings/sections/indices/_create.js#L111) + - **src/kibana/apps/visualize/controllers/editor.js** + - Switch this to watching time.string when we implement it – [L189](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/controllers/editor.js#L189) + - **src/kibana/apps/visualize/saved_visualizations/_adhoc_vis.js** + - Should we abtract out the agg building stuff? – [L58](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/saved_visualizations/_adhoc_vis.js#L58) + - Should this be abstracted somewhere? Its a copy/paste from _saved_vis.js – [L89](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/saved_visualizations/_adhoc_vis.js#L89) + - **src/kibana/apps/visualize/saved_visualizations/_type_defs.js** + - We need to be able to get ahold of angular services here – [L16](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/saved_visualizations/_type_defs.js#L16) + - We need to be able to get ahold of angular services here – [L88](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/saved_visualizations/_type_defs.js#L88) + - **src/kibana/apps/visualize/saved_visualizations/bucket_aggs/terms.js** + - We need more just _count here. – [L26](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/apps/visualize/saved_visualizations/bucket_aggs/terms.js#L26) + - **src/kibana/components/index_patterns/_mapper.js** + - Change index to be the resolved in some way, last three months, last hour, last year, whatever – [L49](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/components/index_patterns/_mapper.js#L49) + - **src/kibana/components/state_management/state.js** + - Change all the references to onUpdate to the actual fetch_with_changes event – [L72](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/components/state_management/state.js#L72) + - **src/kibana/directives/rows.js** + - It would be better to actually check the type of the field, but we don't have – [L38](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/directives/rows.js#L38) + - **src/kibana/services/timefilter.js** + - This should be disabled on route change, apps need to enable it explicitly – [L12](https://github.com/elasticsearch/kibana4/blob/master/src/kibana/services/timefilter.js#L12) + - **test/unit/specs/apps/dashboard/directives/panel.js** + - This should not be needed, timefilter is only included here – [L14](https://github.com/elasticsearch/kibana4/blob/master/test/unit/specs/apps/dashboard/directives/panel.js#L14) + - **test/unit/specs/directives/timepicker.js** + - This should not be needed, timefilter is only included here, it should move – [L17](https://github.com/elasticsearch/kibana4/blob/master/test/unit/specs/directives/timepicker.js#L17) \ No newline at end of file diff --git a/package.json b/package.json index 951e1bd45e4e..ad6ce22cee48 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "scripts": { "test": "grunt test", "server": "grunt server", - "precommit": "grunt jshint" + "precommit": "grunt jshint todos" }, "repository": { "type": "git", diff --git a/tasks/todos.js b/tasks/todos.js new file mode 100644 index 000000000000..a31a9c4f023c --- /dev/null +++ b/tasks/todos.js @@ -0,0 +1,103 @@ +module.exports = function (grunt) { + var _ = require('lodash'); + var Promise = require('bluebird'); + var readFileAsync = Promise.promisify(require('fs').readFile); + var spawnAsync = Promise.promisify(grunt.util.spawn); + var path = require('path'); + var absolute = _.partial(path.join, path.join(__dirname, '..')); + + var TODO_RE = /[\s\/\*]+(TODO|FIXME):?\s*(.+)/; + var NEWLINE_RE = /\r?\n/; + var TODO_FILENAME = 'TODOS.md'; + var TYPE_PRIORITIES = { + 'FIXME': 1 + }; + + grunt.registerTask('todos', function () { + var files = grunt.file.expand([ + 'src/kibana/**/*.js', + 'test/unit/specs/**/*.js' + ]); + var matches = []; + + var currentFile = null; + if (grunt.file.exists(TODO_FILENAME)) { + currentFile = grunt.file.read(TODO_FILENAME); + } + + Promise.map(files, function (path) { + // grunt passes back these file names relative to the root... not + // what we want when we are calling fs.readFile + var absPath = absolute(path); + + return readFileAsync(absPath, 'utf8') + .then(function (file) { + return file.split(NEWLINE_RE); + }) + .each(function (line, i) { + var match = line.match(TODO_RE); + if (!match) return; + + matches.push({ + type: match[1], + msg: match[2], + path: path, + line: i + 1 + }); + }); + }, { concurrency: 50 }) + .then(function () { + var newFileLines = [ + '# TODO items', + '> Automatically extracted', + '' + ]; + + var groupedByPath = _.groupBy(matches, 'path'); + + Object.keys(groupedByPath) + .sort(function (a, b) { + var aChunks = a.split(path.sep); + var bChunks = b.split(path.sep); + + // compare the paths chunk by chunk + for (var i = 0; i < aChunks.length; i++) { + if (aChunks[i] === bChunks[i]) continue; + return aChunks[i].localeCompare(bChunks[i] || ''); + } + }) + .forEach(function (path) { + newFileLines.push(' - **' + path + '**'); + + _(groupedByPath[path]) + .sortBy(function (match) { + return TYPE_PRIORITIES[match.type] || 0; + }) + .each(function (match) { + var priority = TYPE_PRIORITIES[match.type] || 0; + + newFileLines.push( + ' - ' + (priority ? match.type + ' – ' : '') + + match.msg + ' – ' + + '[L' + match.line + ']' + + '(https://github.com/elasticsearch/kibana4/blob/master/' + match.path + '#L' + match.line + ')' + ); + }); + }); + + var newFile = newFileLines.join('\n'); + + if (newFile !== currentFile) { + grunt.log.ok('Committing updated TODO.md'); + grunt.file.write(TODO_FILENAME, newFile); + return spawnAsync({ + cmd: 'git', + args: ['add', absolute(TODO_FILENAME)] + }); + } else { + grunt.log.ok('No changes to commit to TODO.md'); + } + }) + .nodeify(this.async()); + }); +}; \ No newline at end of file