From a9a306273328342c4e159c918f157e256fc9e595 Mon Sep 17 00:00:00 2001 From: Alex Feyerke Date: Fri, 2 Mar 2018 11:21:15 +0100 Subject: [PATCH] test(delete-branches): add groupName argument --- lib/delete-branches.js | 27 +++++++++++++++++---------- test/lib/delete-branches.js | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/delete-branches.js b/lib/delete-branches.js index 91efe93e..9937031a 100644 --- a/lib/delete-branches.js +++ b/lib/delete-branches.js @@ -8,7 +8,7 @@ const githubQueue = require('./github-queue') // TODO: needs to take an optional `groupName` param module.exports = async function ( { installationId, fullName, repositoryId }, - { change, after, dependency, dependencyType } + { change, after, dependency, dependencyType, groupName } ) { if (change !== 'removed' && !semver.validRange(after)) return const { repositories } = await dbs() @@ -25,17 +25,24 @@ module.exports = async function ( 'doc' ) - // TODO: needs to filter branchDocs by optional `groupName` param, - // which is part of `branchDoc.head` - const branchDocs = await Promise.all( _(branches) - .filter( - branch => - change === 'removed' || - semver.satisfies(branch.version, after) || - semver.ltr(branch.version, after) - ) + .filter( + branch => + change === 'removed' || // include branch if dependency was removed + semver.satisfies(branch.version, after) || // include branch if update version satisfies branch version (branch is outdated) + semver.ltr(branch.version, after)// include branch if is not satisfied, but later (eg. update is an out of range major update) + ) + .filter( + branch => { + // if groupName is passed in, only include branches of that group + // branch.head = 'greenkeeper/${groupName}/${dependency}' + if (groupName) { + return branch.head.includes(`greenkeeper/${groupName}/`) + } else { + return true + } + }) .map(async branch => { let referenceDeleted = false try { diff --git a/test/lib/delete-branches.js b/test/lib/delete-branches.js index 6fb32078..d06a4b22 100644 --- a/test/lib/delete-branches.js +++ b/test/lib/delete-branches.js @@ -189,6 +189,7 @@ test('delete-branches in monorepo', async () => { }) .delete('/repos/brot/lecker/git/refs/heads/greenkeeper/backend/standard-9.0.0') .reply(200, () => { + // should not delete this one expect(true).toBeFalsy() return {} })