Skip to content
Closed
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
23 changes: 19 additions & 4 deletions lib/node-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,27 @@ const exclusiveLabelsMap = new Map([
[/^benchmark\//, 'benchmark']
])

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

return (exclusiveLabels.length > 0)
? exclusiveLabels
: matchAllSubSystem(filepathsChanged, limitLib)
if (typeof baseBranch !== 'string') {
if (typeof baseBranch === 'boolean') {
limitLib = baseBranch
}
baseBranch = ''
}

const labels = (exclusiveLabels.length > 0)
? exclusiveLabels
: matchAllSubSystem(filepathsChanged, limitLib)

// Add version labels if PR is made against a version branch
const m = /^(v\d+\.(?:\d+|x))(?:-|$)/.exec(baseBranch)

This comment was marked as off-topic.

if (m) {
labels.push(m[1])
}

return labels
}

function hasAllSubsystems (arr) {
Expand Down
3 changes: 2 additions & 1 deletion lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function resolveLabelsThenUpdatePr (options) {
}

const filepathsChanged = res.map((fileMeta) => fileMeta.filename)
updatePrWithLabels(options, resolveLabels(filepathsChanged))
const labels = resolveLabels(filepathsChanged, options.baseBranch)
updatePrWithLabels(options, labels)
})
}

Expand Down
9 changes: 8 additions & 1 deletion scripts/node-subsystem-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = function (app) {
function handlePrCreated (event, owner, repo) {
const prId = event.number
const logger = event.logger
const baseBranch = event.pull_request.base.ref

// subsystem labelling is for node core only
if (repo !== 'node') return
Expand All @@ -18,6 +19,12 @@ module.exports = function (app) {
// by not hard coding the owner repo to nodejs/node here,
// we can test these this script in a different repo than
// *actual* node core as long as the repo is named "node"
nodeRepo.resolveLabelsThenUpdatePr({ owner, repo, prId, logger })
nodeRepo.resolveLabelsThenUpdatePr({
owner,
repo,
prId,
logger,
baseBranch
})
}
}
56 changes: 56 additions & 0 deletions test/node-labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,59 @@ tap.test('label: not "doc" when other top-level files have been changed', (t) =>

t.end()
})

tap.test('label: version labels (old)', (t) => {
const labels = nodeLabels.resolveLabels([
'common.gypi'
], 'v0.12')

t.same(labels, ['build', 'v0.12'])

t.end()
})

tap.test('label: version labels (old, staging)', (t) => {
const labels = nodeLabels.resolveLabels([
'common.gypi'
], 'v0.12-staging')

t.same(labels, ['build', 'v0.12'])

t.end()
})

tap.test('label: version labels (new)', (t) => {
const labels = nodeLabels.resolveLabels([
'deps/v8/include/v8-version.h',
'deps/v8/src/crankshaft/hydrogen.cc',
'deps/v8/test/mjsunit/regress/regress-5033.js'
], 'v6.x')

t.same(labels, ['v8', 'v6.x'])

t.end()
})

tap.test('label: version labels (new, staging)', (t) => {
const labels = nodeLabels.resolveLabels([
'deps/v8/include/v8-version.h',
'deps/v8/src/crankshaft/hydrogen.cc',
'deps/v8/test/mjsunit/regress/regress-5033.js'
], 'v6.x-staging')

t.same(labels, ['v8', 'v6.x'])

t.end()
})

tap.test('label: no version labels (master)', (t) => {
const labels = nodeLabels.resolveLabels([
'deps/v8/include/v8-version.h',
'deps/v8/src/crankshaft/hydrogen.cc',
'deps/v8/test/mjsunit/regress/regress-5033.js'
], 'master')

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

t.end()
})