Skip to content

Commit

Permalink
fix(branches-to-delete): use the branch prefix from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin authored and hulkoba committed Mar 26, 2018
1 parent 73d699d commit ebde6a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jobs/github-event/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
}))
Expand Down
10 changes: 5 additions & 5 deletions lib/branches-to-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions test/lib/branches-to-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('getDependencyChanges', () => {
})

describe('getDependencyBranchesToDelete', () => {
const config = { branchPrefix: 'greenkeeper/' }
test('not a monorepo', async () => {
const { repositories } = await dbs()

Expand Down Expand Up @@ -100,7 +101,8 @@ describe('getDependencyBranchesToDelete', () => {
before: '^8.0.0',
after: '^10.0.0',
groupName: null } } },
repositories
repositories,
config
}
)

Expand Down Expand Up @@ -150,7 +152,8 @@ describe('getDependencyBranchesToDelete', () => {
before: '^8.0.0',
after: '^10.0.0',
groupName: 'frontend' } } },
repositories
repositories,
config
}
)

Expand Down

0 comments on commit ebde6a0

Please sign in to comment.