From ebde6a0aa405574ea324efcb7311d5f416461500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julia=20Kr=C3=BCger?= Date: Fri, 16 Mar 2018 13:30:03 +0100 Subject: [PATCH] fix(branches-to-delete): use the branch prefix from the config --- jobs/github-event/push.js | 2 +- lib/branches-to-delete.js | 10 +++++----- test/lib/branches-to-delete.js | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/jobs/github-event/push.js b/jobs/github-event/push.js index ac6f725c..fea3bef6 100644 --- a/jobs/github-event/push.js +++ b/jobs/github-event/push.js @@ -171,7 +171,7 @@ async function getDependencyBranchesForAllGroups ({pkg, oldPkg, config, reposito // this can only happen if a package.json was modified const dependencyDiff = diff(oldPkg[path], pkg[path], groupName) if (!_.isEmpty(dependencyDiff)) { - return getDependencyBranchesToDelete({changes: dependencyDiff, repositories, repositoryId}) + return getDependencyBranchesToDelete({changes: dependencyDiff, repositories, repositoryId, config}) } return [] })) diff --git a/lib/branches-to-delete.js b/lib/branches-to-delete.js index f40d98e9..8234fcc6 100644 --- a/lib/branches-to-delete.js +++ b/lib/branches-to-delete.js @@ -27,15 +27,15 @@ function getDependencyChanges (changes) { return dependencyChanges } -async function getDependencyBranchesToDelete ({changes, repositories, repositoryId}) { +async function getDependencyBranchesToDelete ({changes, repositories, repositoryId, config}) { const dependencyChanges = getDependencyChanges(changes) return Promise.all(dependencyChanges.map(async dependencyChange => { - return getSingleDependencyBranchesToDelete({changes: dependencyChange, repositories, repositoryId}) + return getSingleDependencyBranchesToDelete({changes: dependencyChange, repositories, repositoryId, config}) })) } -async function getSingleDependencyBranchesToDelete ({changes, repositories, repositoryId}) { +async function getSingleDependencyBranchesToDelete ({changes, repositories, repositoryId, config}) { const { change, after, dependency, dependencyType, groupName } = changes let branches = [] @@ -65,10 +65,10 @@ async function getSingleDependencyBranchesToDelete ({changes, repositories, repo // if groupName is passed in, only include branches of that group // branch.head = 'greenkeeper/${groupName}/${dependency}' if (groupName) { - return branch.head.includes(`greenkeeper/${groupName}/`) + return branch.head.includes(`${config.branchPrefix}${groupName}/`) } else { // If there's no groupName, only return branches that don’t belong to groups - return branch.head.includes(`greenkeeper/${dependency}`) + return branch.head.includes(`${config.branchPrefix}${dependency}`) } }) .value() diff --git a/test/lib/branches-to-delete.js b/test/lib/branches-to-delete.js index 4b83ca0e..a0a813c0 100644 --- a/test/lib/branches-to-delete.js +++ b/test/lib/branches-to-delete.js @@ -57,6 +57,7 @@ describe('getDependencyChanges', () => { }) describe('getDependencyBranchesToDelete', () => { + const config = { branchPrefix: 'greenkeeper/' } test('not a monorepo', async () => { const { repositories } = await dbs() @@ -100,7 +101,8 @@ describe('getDependencyBranchesToDelete', () => { before: '^8.0.0', after: '^10.0.0', groupName: null } } }, - repositories + repositories, + config } ) @@ -150,7 +152,8 @@ describe('getDependencyBranchesToDelete', () => { before: '^8.0.0', after: '^10.0.0', groupName: 'frontend' } } }, - repositories + repositories, + config } )