Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
attempt-backport: unlabel previous bot labels
  • Loading branch information
Fishrock123 committed Jan 4, 2017
commit daacca18313062992b265818e1f55fd37d6ede68
35 changes: 35 additions & 0 deletions lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,48 @@ function fetchLabelPages (options, startPageNum, cb) {
})
}

function getBotPrLabels (options, cb) {

This comment was marked as off-topic.

githubClient.issues.getEvents({
owner: options.owner,
repo: options.repo,
page: 1,
per_page: 100, // we probably won't hit this
issue_number: options.prId
}, (err, events) => {
if (err) {
return cb(err)
}

const ourLabels = []

for (const event of events) {
if (event.event === 'unlabeled') {
const index = ourLabels.indexOf(event.label.name)
if (index === -1) continue

ourLabels.splice(index, 1)
} else if (event.event === 'labeled') {
const index = ourLabels.indexOf(event.label.name)
if (index > -1) continue

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.


if (event.actor.login === 'nodejs-github-bot') {
ourLabels.push(event.label.name)
}
}
}

cb(null, ourLabels)
})
}

function stringsInCommon (arr1, arr2) {
const loweredArr2 = arr2.map((str) => str.toLowerCase())
// we want the original string cases in arr1, therefore we don't lowercase them
// before comparing them cause that would wrongly make "V8" -> "v8"
return arr1.filter((str) => loweredArr2.indexOf(str.toLowerCase()) !== -1)
}

exports.getBotPrLabels = getBotPrLabels
exports.removeLabelFromPR = removeLabelFromPR
exports.updatePrWithLabels = updatePrWithLabels
exports.resolveLabelsThenUpdatePr = deferredResolveLabelsThenUpdatePr
Expand Down
37 changes: 32 additions & 5 deletions scripts/attempt-backport.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const debug = require('debug')('attempt-backport')
const request = require('request')
const node_repo = require('../lib/node-repo')
const updatePrWithLabels = node_repo.updatePrWithLabels
// const removeLabelFromPR = node_repo.removeLabelFromPR
const removeLabelFromPR = node_repo.removeLabelFromPR
const getBotPrLabels = node_repo.getBotPrLabels

const enabledRepos = ['node']
const nodeVersions = [
Expand Down Expand Up @@ -129,7 +130,23 @@ function attemptBackport (options, version, isLTS, cb) {
const _cb = cb
setImmediate(() => {
options.logger.debug(`backport to ${version} failed`)
if (!isLTS) updatePrWithLabels(options, [`dont-land-on-v${version}.x`])

if (!isLTS) {
updatePrWithLabels(options, [`dont-land-on-v${version}.x`])
} else {
getBotPrLabels(options, (err, ourLabels) => {
if (err) {
options.logger.error(err, 'Error fetching existing bot labels')
return
}

const label = `lts-watch-v${version}.x`
if (!ourLabels.includes(label)) return

removeLabelFromPR(options, label)
})
}

setImmediate(() => {
inProgress = false
_cb()
Expand Down Expand Up @@ -207,11 +224,21 @@ function attemptBackport (options, version, isLTS, cb) {
// Success!
if (isLTS) {
updatePrWithLabels(options, [`lts-watch-v${version}.x`])
}// else {
} else {
// TODO(Fishrock123): Re-enable this, but do a check first
// to make sure the label was set by the bot only.

This comment was marked as off-topic.

This comment was marked as off-topic.

// removeLabelFromPR(options, `dont-land-on-v${version}.x`)
// }
getBotPrLabels(options, (err, ourLabels) => {
if (err) {
options.logger.error(err, 'Error fetching existing bot labels')
return
}

const label = `dont-land-on-v${version}.x`
if (!ourLabels.includes(label)) return

removeLabelFromPR(options, label)
})
}

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