Skip to content
Open
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
7 changes: 3 additions & 4 deletions lib/resolve-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function matchAllSubSystem (filepathsChanged, subSystemLabelsMap) {

function matchSubSystemsByRegex (rxLabelsMap, filepathsChanged) {
const labelsCountLimit = process.env.MAX_LABELS_LIMIT || 4
const labelCount = []
const labelCount = new Set()

// by putting matched labels into a map, we avoid duplicate labels
const labelsMap = filepathsChanged.reduce((map, filepath) => {
Expand All @@ -102,16 +102,15 @@ function matchSubSystemsByRegex (rxLabelsMap, filepathsChanged) {
for (let i = 0; i < mappedSubSystems.length; ++i) {
const mappedSubSystem = mappedSubSystems[i]
if (hasLibOrSrcChanges(filepathsChanged)) {
if (labelCount.length >= labelsCountLimit) {
labelCount.add(mappedSubSystem)
if (labelCount.size > labelsCountLimit) {
for (const label of labelCount) {
// don't delete the `c++` or `needs-ci` labels as we always want those if they have matched
if (label !== 'c++' && label !== 'needs-ci') delete map[label]
}
map['lib / src'] = true
// short-circuit
return map
} else {
labelCount.push(mappedSubSystem)
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/resolve-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ tap.test('label: "lib / src" when 4 or more JS sub-systems have been changed', (
t.end()
})

tap.test('labels: retain fewer than four distinct subsystems despite repeated matches', (t) => {
const labels = resolveLabels([
'lib/internal/crypto/keys.js',
'lib/internal/crypto/cipher.js',
'lib/internal/crypto/hash.js',
'lib/dns.js',
'lib/repl.js',
'lib/v8.js'
])

t.same(labels, ['needs-ci', 'crypto', 'dns', 'repl', 'v8'])

t.end()
})

// https://github.com/nodejs/node/pull/12366 should have been labelled "lib / src"
// https://github.com/nodejs/github-bot/issues/137
tap.test('label: "lib / src" when 4 or more native files have been changed', (t) => {
Expand Down
Loading