Skip to content

Commit

Permalink
test(delete-branches): add groupName argument
Browse files Browse the repository at this point in the history
  • Loading branch information
espy authored and hulkoba committed Mar 26, 2018
1 parent 432360b commit a9a3062
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/delete-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/lib/delete-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
})
Expand Down

0 comments on commit a9a3062

Please sign in to comment.