Skip to content

Commit

Permalink
Labels: use "lib / src" when 5+ JS Subsystems
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishrock123 committed May 12, 2016
1 parent 60faaf4 commit 35657c0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
39 changes: 32 additions & 7 deletions lib/node-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ const subSystemLabelsMap = new Map([
[/^lib\/internal\/(\w+)$/, '$1'] // internal subfolders
])

const jsSubsystemList = [
'debugger', 'assert', 'buffer', 'child_process', 'cluster', 'console',
'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'module',
'net', 'os', 'path', 'process', 'querystring', 'readline', 'repl', 'stream',
'timers', 'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib'
]

const exclusiveLabelsMap = new Map([
[/^test\//, 'test'],
[/^doc\//, 'doc'],
[/^benchmark\//, 'benchmark']
])

function resolveLabels (filepathsChanged) {
function resolveLabels (filepathsChanged, limitLib = true) {
const exclusiveLabels = matchExclusiveSubSystem(filepathsChanged)

return (exclusiveLabels.length > 0)
? exclusiveLabels
: matchAllSubSystem(filepathsChanged)
: matchAllSubSystem(filepathsChanged, limitLib)
}

function matchExclusiveSubSystem (filepathsChanged) {
Expand All @@ -53,19 +60,37 @@ function matchExclusiveSubSystem (filepathsChanged) {
return (isExclusive && labels.length === 1) ? labels : []
}

function matchAllSubSystem (filepathsChanged) {
return matchSubSystemsByRegex(subSystemLabelsMap, filepathsChanged)
function matchAllSubSystem (filepathsChanged, limitLib) {
return matchSubSystemsByRegex(
subSystemLabelsMap, filepathsChanged, limitLib)
}

function matchSubSystemsByRegex (rxLabelsMap, filepathsChanged) {
function matchSubSystemsByRegex (rxLabelsMap, filepathsChanged, limitLib) {
const jsLabelCount = []
// by putting matched labels into a map, we avoid duplicate labels
const labelsMap = filepathsChanged.reduce((map, filepath) => {
const mappedSubSystem = mappedSubSystemForFile(rxLabelsMap, filepath)

if (mappedSubSystem) {
map[mappedSubSystem] = true
if (!mappedSubSystem) {
// short-circuit
return map
}

if (limitLib && jsSubsystemList.includes(mappedSubSystem)) {
if (jsLabelCount.length >= 4) {
for (const jsLabel of jsLabelCount) {
delete map[jsLabel]
}
map['lib / src'] = true
// short-circuit
return map
} else {
jsLabelCount.push(mappedSubSystem)
}
}

map[mappedSubSystem] = true

return map
}, {})

Expand Down
6 changes: 3 additions & 3 deletions test/node-js-subsystem-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tap.test('label: lib oddities', (t) => {
'lib/internal/v8_prof_processor.js'
]

const labels = nodeLabels.resolveLabels(libFiles)
const labels = nodeLabels.resolveLabels(libFiles, false)

t.same(labels, [
'debugger', // _debug_agent
Expand Down Expand Up @@ -106,7 +106,7 @@ tap.test('label: lib normal without "lib / src" limiting', (t) => {
'lib/zlib.js'
]

const labels = nodeLabels.resolveLabels(libFiles)
const labels = nodeLabels.resolveLabels(libFiles, false)

t.same(labels, libFiles.map((path) => /lib\/(_)?(\w+)\.js/.exec(path)[2]))

Expand All @@ -125,7 +125,7 @@ tap.test('label: lib internals without "lib / src" limiting', (t) => {
'lib/internal/util.js'
]

const labels = nodeLabels.resolveLabels(libFiles)
const labels = nodeLabels.resolveLabels(libFiles, false)

t.same(labels, libFiles.map((path) => /lib\/internal\/(\w+)\.js/.exec(path)[1]))

Expand Down
18 changes: 15 additions & 3 deletions test/node-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,29 @@ tap.test('label: "repl" when ./lib/repl.js has been changed', (t) => {
t.end()
})

tap.test('label: "lib / src" when more than 5 sub-systems has been changed', (t) => {
tap.test('label: "lib / src" when 5 or more JS sub-systems have been changed', (t) => {
const labels = nodeLabels.resolveLabels([
'lib/assert.js',
'lib/dns.js',
'lib/repl.js',
'lib/process.js',
'src/async-wrap.cc',
'lib/module.js'
])

t.same(labels, ['lib / src'], { todo: true })
t.same(labels, ['lib / src'])

t.end()
})

tap.test('label: "JS sub-systems when less than 5 sub-systems have changed', (t) => {
const labels = nodeLabels.resolveLabels([
'lib/assert.js',
'lib/dns.js',
'lib/repl.js',
'lib/process.js'
])

t.same(labels, ['assert', 'dns', 'repl', 'process'])

t.end()
})
Expand Down

0 comments on commit 35657c0

Please sign in to comment.