Skip to content

Commit

Permalink
labels: fix labeling for non-subsystem API docs (nodejs#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex authored and phillipj committed Feb 14, 2017
1 parent 4508301 commit 7e3c4d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/node-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,27 @@ function hasAllSubsystems (arr) {
})
}

// This function is needed to help properly identify when a PR should always
// (just) be labeled as 'doc' when it is all changes in doc/api/ that do not
// match subsystem names (e.g. _toc.md, all.md)
function hasAllDocChanges (arr) {
return arr.every((val) => {
return /^doc\//.test(val)
})
}

function matchExclusiveSubSystem (filepathsChanged) {
const isExclusive = filepathsChanged.every(matchesAnExclusiveLabel)
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)) {
if (hasAllSubsystems(nonDocLabels) || hasAllDocChanges(filepathsChanged)) {
labels = ['doc']
} else {
labels = []
Expand Down
11 changes: 11 additions & 0 deletions test/unit/node-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,14 @@ tap.test('label: dont-land-on labels for WHATWG URL', (t) => {

t.end()
})

tap.test('label: doc label for non-subsystem API doc changes', (t) => {
const labels = nodeLabels.resolveLabels([
'doc/api/_toc.md',
'doc/api/all.md'
])

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

t.end()
})

0 comments on commit 7e3c4d3

Please sign in to comment.