Skip to content

Commit 3a30e94

Browse files
mscdexphillipj
authored andcommitted
labels: add version labels
1 parent e2bf71b commit 3a30e94

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

lib/node-labels.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,27 @@ const exclusiveLabelsMap = new Map([
5555
[/^benchmark\//, 'benchmark']
5656
])
5757

58-
function resolveLabels (filepathsChanged, limitLib = true) {
58+
function resolveLabels (filepathsChanged, baseBranch, limitLib = true) {
5959
const exclusiveLabels = matchExclusiveSubSystem(filepathsChanged)
6060

61-
return (exclusiveLabels.length > 0)
62-
? exclusiveLabels
63-
: matchAllSubSystem(filepathsChanged, limitLib)
61+
if (typeof baseBranch !== 'string') {
62+
if (typeof baseBranch === 'boolean') {
63+
limitLib = baseBranch
64+
}
65+
baseBranch = ''
66+
}
67+
68+
const labels = (exclusiveLabels.length > 0)
69+
? exclusiveLabels
70+
: matchAllSubSystem(filepathsChanged, limitLib)
71+
72+
// Add version labels if PR is made against a version branch
73+
const m = /^(v\d+\.(?:\d+|x))(?:-|$)/.exec(baseBranch)
74+
if (m) {
75+
labels.push(m[1])
76+
}
77+
78+
return labels
6479
}
6580

6681
function hasAllSubsystems (arr) {

lib/node-repo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function resolveLabelsThenUpdatePr (options) {
1515
}
1616

1717
const filepathsChanged = res.map((fileMeta) => fileMeta.filename)
18-
updatePrWithLabels(options, resolveLabels(filepathsChanged))
18+
const labels = resolveLabels(filepathsChanged, options.baseBranch)
19+
updatePrWithLabels(options, labels)
1920
})
2021
}
2122

scripts/node-subsystem-label.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = function (app) {
1010
function handlePrCreated (event, owner, repo) {
1111
const prId = event.number
1212
const logger = event.logger
13+
const baseBranch = event.pull_request.base.ref
1314

1415
// subsystem labelling is for node core only
1516
if (repo !== 'node') return
@@ -18,6 +19,12 @@ module.exports = function (app) {
1819
// by not hard coding the owner repo to nodejs/node here,
1920
// we can test these this script in a different repo than
2021
// *actual* node core as long as the repo is named "node"
21-
nodeRepo.resolveLabelsThenUpdatePr({ owner, repo, prId, logger })
22+
nodeRepo.resolveLabelsThenUpdatePr({
23+
owner,
24+
repo,
25+
prId,
26+
logger,
27+
baseBranch
28+
})
2229
}
2330
}

test/unit/node-labels.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,59 @@ tap.test('label: not "doc" when other top-level files have been changed', (t) =>
241241

242242
t.end()
243243
})
244+
245+
tap.test('label: version labels (old)', (t) => {
246+
const labels = nodeLabels.resolveLabels([
247+
'common.gypi'
248+
], 'v0.12')
249+
250+
t.same(labels, ['build', 'v0.12'])
251+
252+
t.end()
253+
})
254+
255+
tap.test('label: version labels (old, staging)', (t) => {
256+
const labels = nodeLabels.resolveLabels([
257+
'common.gypi'
258+
], 'v0.12-staging')
259+
260+
t.same(labels, ['build', 'v0.12'])
261+
262+
t.end()
263+
})
264+
265+
tap.test('label: version labels (new)', (t) => {
266+
const labels = nodeLabels.resolveLabels([
267+
'deps/v8/include/v8-version.h',
268+
'deps/v8/src/crankshaft/hydrogen.cc',
269+
'deps/v8/test/mjsunit/regress/regress-5033.js'
270+
], 'v6.x')
271+
272+
t.same(labels, ['v8', 'v6.x'])
273+
274+
t.end()
275+
})
276+
277+
tap.test('label: version labels (new, staging)', (t) => {
278+
const labels = nodeLabels.resolveLabels([
279+
'deps/v8/include/v8-version.h',
280+
'deps/v8/src/crankshaft/hydrogen.cc',
281+
'deps/v8/test/mjsunit/regress/regress-5033.js'
282+
], 'v6.x-staging')
283+
284+
t.same(labels, ['v8', 'v6.x'])
285+
286+
t.end()
287+
})
288+
289+
tap.test('label: no version labels (master)', (t) => {
290+
const labels = nodeLabels.resolveLabels([
291+
'deps/v8/include/v8-version.h',
292+
'deps/v8/src/crankshaft/hydrogen.cc',
293+
'deps/v8/test/mjsunit/regress/regress-5033.js'
294+
], 'master')
295+
296+
t.same(labels, ['v8'])
297+
298+
t.end()
299+
})

0 commit comments

Comments
 (0)