Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion utils/issue-format-bot/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
"error",
"never"
],
"object-property-newline": "error",
"one-var": "off",
"one-var-declaration-per-line": "error",
"prefer-arrow-callback": "error",
Expand Down
24 changes: 18 additions & 6 deletions utils/issue-format-bot/lib/labeler.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
Expand Down
48 changes: 39 additions & 9 deletions utils/issue-format-bot/test/labeler-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 AJ Jordan, AGPLv3+
// Copyright 2017-2018 AJ Jordan, AGPLv3+

'use strict';

Expand Down Expand Up @@ -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());
};
}

Expand All @@ -62,31 +62,61 @@ 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,
'it works': function(err) {
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,
'it works': function(err) {
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);
2 changes: 1 addition & 1 deletion utils/issue-format-bot/test/lib/handlerutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};

Expand Down