diff --git a/utils/issue-format-bot/.eslintrc.json b/utils/issue-format-bot/.eslintrc.json index da3ef079033a..7e41908676ac 100644 --- a/utils/issue-format-bot/.eslintrc.json +++ b/utils/issue-format-bot/.eslintrc.json @@ -120,7 +120,6 @@ "error", "never" ], - "object-property-newline": "error", "one-var": "off", "one-var-declaration-per-line": "error", "prefer-arrow-callback": "error", diff --git a/utils/issue-format-bot/lib/labeler.js b/utils/issue-format-bot/lib/labeler.js index f82a8d64cd3f..f0159016b2c9 100644 --- a/utils/issue-format-bot/lib/labeler.js +++ b/utils/issue-format-bot/lib/labeler.js @@ -1,17 +1,22 @@ -// Copyright 2017 AJ Jordan, AGPLv3+ +// Copyright 2017-2018 AJ Jordan, AGPLv3+ 'use strict'; const alexaLabels = ['top-100', 'top-1k', 'top-10k', 'top-100k', 'top-1m']; +const typeLabels = ['bug', 'enhancement', 'ruleset-bug', 'new-ruleset']; +const typeToLabel = { + 'code issue': 'bug', + 'feature request': 'enhancement', + 'ruleset issue': 'ruleset-bug', + 'new ruleset': 'new-ruleset' +}; module.exports = function label(context, data, alexa) { const alexaPosition = alexa.data.indexOf(data.domain); const labels = []; - // TODO remove existing labels in case of edits - if (alexaPosition === -1) { - return; + // Do nothing, we still need to label the type } else if (alexaPosition < 100) { labels.push('top-100'); } else if (alexaPosition < 1000) { @@ -24,8 +29,15 @@ module.exports = function label(context, data, alexa) { labels.push('top-1m'); } - // Every Alexa label *except* our new one - const toRemove = alexaLabels.filter(label => label !== labels[0]); + const typeLabel = typeToLabel[data.type] || null; + if (typeLabel) { + labels.push(typeLabel); + } + + // Every Alexa label *except* our new one, and the same for type labels + const toRemove = alexaLabels.filter(label => label !== labels[0] || '') + .concat(typeLabels.filter(label => label !== typeLabel)); // eslint-disable-line indent + toRemove.forEach(label => { const removalParams = context.issue({name: label}); // This is racy with addLabels() but honestly who cares diff --git a/utils/issue-format-bot/test/labeler-test.js b/utils/issue-format-bot/test/labeler-test.js index 5f494f517d14..b4ca10a57572 100644 --- a/utils/issue-format-bot/test/labeler-test.js +++ b/utils/issue-format-bot/test/labeler-test.js @@ -1,4 +1,4 @@ -// Copyright 2017 AJ Jordan, AGPLv3+ +// Copyright 2017-2018 AJ Jordan, AGPLv3+ 'use strict'; @@ -40,13 +40,13 @@ function addLabelsCalledOnce(err, context) { assert.isTrue(context.github.issues.addLabels.calledOnce); } -function assertWhichLabel(label) { +function assertWhichLabels(labels) { return function(err, context) { const args = context.github.issues.addLabels.args[0]; assert.isObject(args[0]); assert.isArray(args[0].labels); - assert.deepEqual(args[0].labels, [label]); + assert.deepEqual(args[0].labels.sort(), labels.sort()); }; } @@ -62,7 +62,7 @@ vows.describe('issue labeler module').addBatch(setup( topic: function(labeler) { const context = makeContext.issue(); // XXX should we test on the boundaries of different labels instead of in the middle? - labeler(context, {domain: 'domain10.com'}, alexa); + labeler(context, {type: 'new ruleset', domain: 'domain10.com'}, alexa); return context; }, teardown: resetSpies, @@ -70,15 +70,15 @@ vows.describe('issue labeler module').addBatch(setup( assert.ifError(err); }, 'it adds labels to the issue only once': addLabelsCalledOnce, - 'the label was the top-100 label': assertWhichLabel('top-100'), - 'all other labels were removed': assertOtherLabelsRemoved(['top-1k', 'top-10k', 'top-100k', 'top-1m']) + 'the labels were the top-100 and ruleset labels': assertWhichLabels(['top-100', 'new-ruleset']), + 'all other labels were removed': assertOtherLabelsRemoved(['top-1k', 'top-10k', 'top-100k', 'top-1m', 'bug', 'enhancement', 'ruleset-bug']) } )).addBatch(setup( 'and we pass it an issue in the top 1,000 domains', { topic: function(labeler) { const context = makeContext.issue(); // XXX should we test on the boundaries of different labels instead of in the middle? - labeler(context, {domain: 'domain500.com'}, alexa); + labeler(context, {type: 'new ruleset', domain: 'domain500.com'}, alexa); return context; }, teardown: resetSpies, @@ -86,7 +86,37 @@ vows.describe('issue labeler module').addBatch(setup( assert.ifError(err); }, 'it adds labels to the issue only once': addLabelsCalledOnce, - 'the label was the top-1k label': assertWhichLabel('top-1k'), - 'all other labels were removed': assertOtherLabelsRemoved(['top-100', 'top-10k', 'top-100k', 'top-1m']) + 'the labels were the top-1k and ruleset labels': assertWhichLabels(['top-1k', 'new-ruleset']), + 'all other labels were removed': assertOtherLabelsRemoved(['top-100', 'top-10k', 'top-100k', 'top-1m', 'bug', 'enhancement', 'ruleset-bug']) + } +)).addBatch(setup( + 'and we pass it a codebase issue', { + topic: function(labeler) { + const context = makeContext.issue(); + labeler(context, {type: 'code issue'}, alexa); + return context; + }, + teardown: resetSpies, + 'it works': function(err) { + assert.ifError(err); + }, + 'it adds labels to the issue only once': addLabelsCalledOnce, + 'the label was the bug label': assertWhichLabels(['bug']), + 'all other labels were removed': assertOtherLabelsRemoved(['top-100', 'top-1k', 'top-10k', 'top-100k', 'top-1m', 'enhancement', 'ruleset-bug', 'new-ruleset']) + } +)).addBatch(setup( + 'and we pass it a codebase issue with a domain', { + topic: function(labeler) { + const context = makeContext.issue(); + labeler(context, {type: 'code issue'}, alexa); + return context; + }, + teardown: resetSpies, + 'it works': function(err) { + assert.ifError(err); + }, + 'it adds labels to the issue only once': addLabelsCalledOnce, + 'the label was the bug label': assertWhichLabels(['bug']), + 'all other labels were removed': assertOtherLabelsRemoved(['top-100', 'top-1k', 'top-10k', 'top-100k', 'top-1m', 'enhancement', 'ruleset-bug', 'new-ruleset']) } )).export(module); diff --git a/utils/issue-format-bot/test/lib/handlerutil.js b/utils/issue-format-bot/test/lib/handlerutil.js index 3cee354bc473..c12ae1dbb913 100644 --- a/utils/issue-format-bot/test/lib/handlerutil.js +++ b/utils/issue-format-bot/test/lib/handlerutil.js @@ -143,7 +143,7 @@ function correctNewRuleset(issueText, text) { assert.isObject(args[0]); assert.isArray(args[0].labels); - assert.deepEqual(args[0].labels, ['top-100']); + assert.deepEqual(args[0].labels.sort(), ['top-100', 'new-ruleset'].sort()); } };