Skip to content

Commit

Permalink
fix(create-group-version-branch): get latest version for each monorep…
Browse files Browse the repository at this point in the history
…o release dependency
  • Loading branch information
Realtin committed Aug 16, 2018
1 parent 18003c7 commit b4d38e0
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 41 deletions.
17 changes: 12 additions & 5 deletions jobs/create-group-version-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = async function (
let relevantDependencies = []
const groupName = Object.keys(group)[0]

const { installations, repositories } = await dbs()
const { installations, repositories, npm } = await dbs()
const logs = dbs.getLogsDb()
const installation = await installations.get(accountId)
const repository = await repositories.get(repositoryId)
Expand Down Expand Up @@ -191,30 +191,37 @@ module.exports = async function (

async function createTransformsArray (monorepo) {
return Promise.all(dependencyGroup.map(async depName => {
// get version for each dependency
const npmDoc = await npm.get(depName)
const latestDependencyVersion = npmDoc['distTags']['latest']

return Promise.all(monorepo.map(async pkgRow => {
const pkg = pkgRow.value

if (!pkg.type) return
if (_.includes(config.ignore, depName)) return
if (_.includes(config.groups[groupName].ignore, depName)) return

if (!_.get(repository, `packages['${pkg.filename}'].${pkg.type}.${depName}`)) return
const oldPkgVersion = _.get(repository, `packages['${pkg.filename}'].${pkg.type}.${depName}`)
if (!oldPkgVersion) return
console.log('oldPkgVersion', oldPkgVersion)
if (semver.ltr(latestDependencyVersion, oldPkgVersion)) return // no downgrades

const commitMessageKey = !satisfies && pkg.type === 'dependencies'
? 'dependencyUpdate'
: 'devDependencyUpdate'
const commitMessageValues = { dependency: depName, version }
const commitMessageValues = { dependency: depName, version: latestDependencyVersion }
let commitMessage = getMessage(config.commitMessages, commitMessageKey, commitMessageValues)

if (!satisfies && openPR) {
await upsert(repositories, openPR._id, {
comments: [...(openPR.comments || []), version]
comments: [...(openPR.comments || []), latestDependencyVersion]
})
commitMessage += getMessage(config.commitMessages, 'closes', {number: openPR.number})
}
log.info('commit message created', {commitMessage})
return {
transform: createTransformFunction(pkg.type, depName, version, log),
transform: createTransformFunction(pkg.type, depName, latestDependencyVersion, log),
path: pkg.filename,
message: commitMessage
}
Expand Down
Loading

0 comments on commit b4d38e0

Please sign in to comment.