Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labels: add subsystem label for API doc #47

Merged
merged 1 commit into from
Jun 21, 2016
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
83 changes: 57 additions & 26 deletions lib/node-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const jsSubsystemList = [

const exclusiveLabelsMap = new Map([
[/^test\//, 'test'],
// automatically tag subsystem-specific API doc changes
[/^doc\/api\/(\w+).md$/, ['doc', '$1']],
[/^doc\//, 'doc'],
[/^benchmark\//, 'benchmark']
])
Expand All @@ -53,10 +55,29 @@ function resolveLabels (filepathsChanged, limitLib = true) {
: matchAllSubSystem(filepathsChanged, limitLib)
}

function hasAllSubsystems (arr) {
return arr.every((val) => {
return jsSubsystemList.includes(val)
})
}

function matchExclusiveSubSystem (filepathsChanged) {
const isExclusive = filepathsChanged.every(matchesAnExclusiveLabel)
const labels = matchSubSystemsByRegex(exclusiveLabelsMap, filepathsChanged)
return (isExclusive && labels.length === 1) ? labels : []
var labels = matchSubSystemsByRegex(exclusiveLabelsMap, filepathsChanged)
// if there are multiple API doc changes, do not apply subsystem tags for now
if (isExclusive &&
labels.includes('doc') &&
labels.length > 2) {
const nonDocLabels = labels.filter((val) => {
return val !== 'doc'
})
if (hasAllSubsystems(nonDocLabels)) {
labels = ['doc']
} else {
labels = []
}
}
return isExclusive ? labels : []
}

function matchAllSubSystem (filepathsChanged, limitLib) {
Expand All @@ -68,56 +89,66 @@ 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)
const mappedSubSystems = mappedSubSystemsForFile(rxLabelsMap, filepath)

if (!mappedSubSystem) {
if (!mappedSubSystems) {
// short-circuit
return map
}

if (limitLib && jsSubsystemList.includes(mappedSubSystem)) {
if (jsLabelCount.length >= 4) {
for (const jsLabel of jsLabelCount) {
delete map[jsLabel]
for (var i = 0; i < mappedSubSystems.length; ++i) {
const mappedSubSystem = mappedSubSystems[i]
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['lib / src'] = true
// short-circuit
return map
} else {
jsLabelCount.push(mappedSubSystem)
}
}

map[mappedSubSystem] = true
map[mappedSubSystem] = true
}

return map
}, {})

return Object.keys(labelsMap)
}

function mappedSubSystemForFile (labelsMap, filepath) {
function mappedSubSystemsForFile (labelsMap, filepath) {
for (const [regex, label] of labelsMap) {
const matches = regex.exec(filepath)

if (matches === null) {
continue
}

// label names starting with $ means we want to extract a matching
// group from the regex we've just matched against
if (label.startsWith('$')) {
const wantedMatchGroup = label.substr(1)
return matches[wantedMatchGroup]
}

// use label name as is when label doesn't look like a regex matching group
return label
const ret = []
const labels = Array.isArray(label) ? label : [label]
labels.forEach((label) => {
// label names starting with $ means we want to extract a matching
// group from the regex we've just matched against
if (label.startsWith('$')) {
const wantedMatchGroup = label.substr(1)
label = matches[wantedMatchGroup]
}
if (!label) {
return
}
// use label name as is when label doesn't look like a regex matching group
ret.push(label)
})
return ret
}
}

function matchesAnExclusiveLabel (filepath) {
return mappedSubSystemForFile(exclusiveLabelsMap, filepath) !== undefined
return mappedSubSystemsForFile(exclusiveLabelsMap, filepath) !== undefined
}

exports.resolveLabels = resolveLabels
22 changes: 22 additions & 0 deletions test/node-js-subsystem-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,25 @@ tap.test('label: lib internals without "lib / src" limiting', (t) => {

t.end()
})

tap.test('label: add subsystem when ./doc/api/<subsystem>.md has been changed', (t) => {
const labels = nodeLabels.resolveLabels([
'doc/api/fs.md'
], false)

t.same(labels, ['doc', 'fs'])

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


t.end()
})

tap.test('label: only "doc" with multiple API doc files changed', (t) => {
const labels = nodeLabels.resolveLabels([
'doc/api/fs.md',
'doc/api/stream.md'
], false)

t.same(labels, ['doc'])

t.end()
})

2 changes: 1 addition & 1 deletion test/node-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ tap.test('label: "v8" when ./deps/v8/ files has been changed', (t) => {
t.end()
})

tap.test('label: "libuv" when ./deps/ub/ files has been changed', (t) => {
tap.test('label: "libuv" when ./deps/uv/ files has been changed', (t) => {
const labels = nodeLabels.resolveLabels([
'deps/uv/src/fs-poll.c'
])
Expand Down