@@ -5,7 +5,8 @@ const debug = require('debug')('attempt-backport')
55const request = require ( 'request' )
66const node_repo = require ( '../lib/node-repo' )
77const updatePrWithLabels = node_repo . updatePrWithLabels
8- // const removeLabelFromPR = node_repo.removeLabelFromPR
8+ const removeLabelFromPR = node_repo . removeLabelFromPR
9+ const getBotPrLabels = node_repo . getBotPrLabels
910
1011const enabledRepos = [ 'node' ]
1112const nodeVersions = [
@@ -129,7 +130,23 @@ function attemptBackport (options, version, isLTS, cb) {
129130 const _cb = cb
130131 setImmediate ( ( ) => {
131132 options . logger . debug ( `backport to ${ version } failed` )
132- if ( ! isLTS ) updatePrWithLabels ( options , [ `dont-land-on-v${ version } .x` ] )
133+
134+ if ( ! isLTS ) {
135+ updatePrWithLabels ( options , [ `dont-land-on-v${ version } .x` ] )
136+ } else {
137+ getBotPrLabels ( options , ( err , ourLabels ) => {
138+ if ( err ) {
139+ options . logger . error ( err , 'Error fetching existing bot labels' )
140+ return
141+ }
142+
143+ const label = `lts-watch-v${ version } .x`
144+ if ( ! ourLabels . includes ( label ) ) return
145+
146+ removeLabelFromPR ( options , label )
147+ } )
148+ }
149+
133150 setImmediate ( ( ) => {
134151 inProgress = false
135152 _cb ( )
@@ -201,11 +218,21 @@ function attemptBackport (options, version, isLTS, cb) {
201218 // Success!
202219 if ( isLTS ) {
203220 updatePrWithLabels ( options , [ `lts-watch-v${ version } .x` ] )
204- } // else {
221+ } else {
205222 // TODO(Fishrock123): Re-enable this, but do a check first
206223 // to make sure the label was set by the bot only.
207- // removeLabelFromPR(options, `dont-land-on-v${version}.x`)
208- // }
224+ getBotPrLabels ( options , ( err , ourLabels ) => {
225+ if ( err ) {
226+ options . logger . error ( err , 'Error fetching existing bot labels' )
227+ return
228+ }
229+
230+ const label = `dont-land-on-v${ version } .x`
231+ if ( ! ourLabels . includes ( label ) ) return
232+
233+ removeLabelFromPR ( options , label )
234+ } )
235+ }
209236
210237 setImmediate ( ( ) => {
211238 options . logger . debug ( `backport to v${ version } successful` )
0 commit comments