Skip to content

Commit

Permalink
fix(create-version-branch): get latest version for each monorepo rele…
Browse files Browse the repository at this point in the history
…ase dependency

because they can be different
  • Loading branch information
Realtin committed Aug 16, 2018
1 parent 70b3f44 commit 18003c7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions jobs/create-version-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = async function (
let monorepoGroup = ''
let relevantDependencies = []

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 @@ -177,26 +177,30 @@ module.exports = async function (
return null
}

if (semver.ltr(version, oldPkgVersion)) { // no downgrades
log.warn(`exited: ${dependency} ${version} would be a downgrade from ${oldPkgVersion}`, {newVersion: version, oldVersion: oldPkgVersion})
// get version for each dependency
const npmDoc = await npm.get(depName)
const latestDependencyVersion = npmDoc['distTags']['latest']

if (semver.ltr(latestDependencyVersion, oldPkgVersion)) { // no downgrades
log.warn(`exited: ${dependency} ${latestDependencyVersion} would be a downgrade from ${oldPkgVersion}`, {newVersion: latestDependencyVersion, oldVersion: oldPkgVersion})
return null
}

const commitMessageKey = !satisfies && dependencyType === '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(dependencyType, depName, version, log),
transform: createTransformFunction(dependencyType, depName, latestDependencyVersion, log),
path: 'package.json',
message: commitMessage
}
Expand Down

0 comments on commit 18003c7

Please sign in to comment.