Skip to content

Commit

Permalink
feat(push): respect groups when cleaning up branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Realtin authored and hulkoba committed Mar 26, 2018
1 parent 3bc7bb0 commit f880eb3
Show file tree
Hide file tree
Showing 4 changed files with 469 additions and 32 deletions.
31 changes: 19 additions & 12 deletions jobs/github-event/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async function (data) {
const repositoryId = String(repository.id)

let repoDoc = await repositories.get(repositoryId)
const config = getConfig(repoDoc.doc)
const config = getConfig(repoDoc)
const isMonorepo = !!_.get(config, ['groups'])
// if greenkeeper.json with at least one file in a group
// updated repoDoc with new .greenkeeperrc
Expand All @@ -46,8 +46,8 @@ module.exports = async function (data) {
const oldPkg = _.get(repoDoc, ['packages'])
await updateRepoDoc(installation.id, repoDoc)
const pkg = _.get(repoDoc, ['packages'])
if (!pkg) return disableRepo({ repositories, repository, repoDoc })
if (!isMonorepo) {
if (!pkg || _.isEmpty(pkg)) return disableRepo({ repositories, repository, repoDoc })
if (!isMonorepo) { // does this make sense??
if (!Object.keys(pkg).length) {
return disableRepo({ repositories, repository, repoDoc })
}
Expand Down Expand Up @@ -77,9 +77,18 @@ module.exports = async function (data) {
// delete all branches for modified or deleted dependencies
// do diff + getBranchesToDelete per file for each group

// TODO: for Tuesday -> deleting a package.json needs to be detected!!
const branches = []
Object.keys(pkg).forEach((key) => {
const changes = diff(oldPkg[key], pkg[key])
Object.keys(pkg).forEach((path) => {
let groupName = null
if (config.groups) {
Object.keys(config.groups).map((group) => {
if (config.groups[group].packages.includes(path)) {
groupName = group
}
})
}
const changes = diff(oldPkg[path], pkg[path], groupName)
branches.push(getBranchesToDelete(changes))
})

Expand All @@ -89,18 +98,16 @@ module.exports = async function (data) {
const branches = getBranchesToDelete(changes)
*/
console.log('branches to be deleted!!', branches)
// console.log('branches to be deleted!!', branches)
// do this per group, if groups, else once

// MONDAY CONTINUE HERE

// TODO: config includes no groups
console.log('config', config)
// Object.keys(config.groups).map((group, key) => {
// console.log('group, key', group, key)
// })
// console.log('config', config)

await Promise.mapSeries(
_.flatten(branches), // TODO: UNIQ!
_.uniqWith(_.flatten(branches), _.isEqual),
deleteBranches.bind(null, {
installationId: installation.id,
fullName: repository.full_name,
Expand Down Expand Up @@ -137,7 +144,7 @@ function hasRelevantChanges (commits, files) {
}

async function disableRepo ({ repositories, repoDoc, repository }) {
console.log('disableRepo')
// console.log('disableRepo')
repoDoc.enabled = false
await updateDoc(repositories, repository, repoDoc)
if (!env.IS_ENTERPRISE) {
Expand Down
10 changes: 6 additions & 4 deletions lib/delete-branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const dbs = require('../lib/dbs')
const updatedAt = require('../lib/updated-at')
const githubQueue = require('./github-queue')

// TODO: needs to take an optional `groupName` param
module.exports = async function (
{ installationId, fullName, repositoryId },
{ change, after, dependency, dependencyType, groupName }
Expand All @@ -29,9 +28,12 @@ module.exports = async function (
_(branches)
.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)
// include branch if dependency was removed
change === 'removed' ||
// include branch if update version satisfies branch version (branch is outdated)
semver.satisfies(branch.version, after) ||
// include branch if is not satisfied, but later (eg. update is an out of range major update)
semver.ltr(branch.version, after)
)
.filter(
branch => {
Expand Down
5 changes: 3 additions & 2 deletions lib/diff-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const types = [
'peerDependencies'
]

module.exports = function (a, b) {
module.exports = function (a, b, groupName) {
const changes = {}
types.forEach(type => {
_.keys(_.get(a, type)).forEach(dep => {
Expand All @@ -19,7 +19,8 @@ module.exports = function (a, b) {
_.set(changes, [type, dep], {
change,
before,
after
after,
groupName
})
})
_.keys(_.get(b, type)).forEach(dep => {
Expand Down
Loading

0 comments on commit f880eb3

Please sign in to comment.