Skip to content

Commit 39cf0d7

Browse files
committed
attempt-backport: enable label removal for Current lines
Refs: #77 PR-URL: #90
1 parent 3a4c594 commit 39cf0d7

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/node-repo.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ function updatePrWithLabels (options, labels) {
6161
})
6262
}
6363

64+
function removeLabelFromPR (options, label) {
65+
// no need to request github if we didn't resolve a label
66+
if (!label) {
67+
return
68+
}
69+
70+
options.logger.debug('Trying to remove label: ' + label)
71+
72+
githubClient.issues.removeLabel({
73+
user: options.owner,
74+
repo: options.repo,
75+
number: options.prId,
76+
name: label
77+
}, (err) => {
78+
if (err) {
79+
if (err.code === 404) return options.logger.info('Label to remove did not exist, bailing ' + label)
80+
81+
return options.logger.error(err, 'Error while removing a label')
82+
}
83+
84+
options.logger.info('Removed a label ' + label)
85+
})
86+
}
87+
6488
function fetchExistingLabels (options, cb) {
6589
const cacheKey = `${options.owner}:${options.repo}`
6690

@@ -93,6 +117,7 @@ function itemsInCommon (arr1, arr2) {
93117
return arr1.filter((item) => arr2.indexOf(item) !== -1)
94118
}
95119

120+
exports.removeLabelFromPR = removeLabelFromPR
96121
exports.updatePrWithLabels = updatePrWithLabels
97122
exports.resolveLabelsThenUpdatePr = deferredResolveLabelsThenUpdatePr
98123

scripts/attempt-backport.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
const child_process = require('child_process')
44
const debug = require('debug')('attempt-backport')
55
const request = require('request')
6-
const updatePrWithLabels = require('../lib/node-repo').updatePrWithLabels
6+
const node_repo = require('../lib/node-repo')
7+
const updatePrWithLabels = node_repo.updatePrWithLabels
8+
const removeLabelFromPR = node_repo.removeLabelFromPR
79

810
const enabledRepos = ['node']
911
const queue = []
@@ -193,7 +195,11 @@ function attemptBackport(options, version, isLTS, cb) {
193195
options.logger.debug(`attempting a backport to v${version}...`)
194196
const cp = wrapCP('git', ['am'], { stdio: 'pipe' }, function done() {
195197
// Success!
196-
if (isLTS) updatePrWithLabels(options, [`lts-watch-v${version}.x`])
198+
if (isLTS) {
199+
updatePrWithLabels(options, [`lts-watch-v${version}.x`])
200+
} else {
201+
removeLabelFromPR(options, `dont-land-on-v${version}.x`)
202+
}
197203

198204
setImmediate(() => {
199205
options.logger.debug(`backport to v${version} successful`)

0 commit comments

Comments
 (0)