diff --git a/jobs/create-group-version-branch.js b/jobs/create-group-version-branch.js index 0bee7ee3..42ad08ea 100644 --- a/jobs/create-group-version-branch.js +++ b/jobs/create-group-version-branch.js @@ -18,7 +18,8 @@ const { generateGitHubCompareURL, hasTooManyPackageJSONs, getSatisfyingVersions, - getOldVersionResolved + getOldVersionResolved, + getLicenseAndAuthorFromVersions } = require('../utils/utils') const { isPartOfMonorepo, @@ -361,9 +362,7 @@ module.exports = async function ( const dependencyLink = getFormattedDependencyURL({ repositoryURL: transforms[0].repoURL }) - const license = versions[version].license - const licenseHasChanged = oldVersionResolved ? versions[oldVersionResolved].license !== license : false - const publisher = versions[version]['_npmUser'].name + const { license, licenseHasChanged, publisher } = getLicenseAndAuthorFromVersions({ versions, version, oldVersionResolved }) // maybe adapt PR body const body = prContent({ diff --git a/jobs/create-version-branch.js b/jobs/create-version-branch.js index a2473afc..13f6d32b 100644 --- a/jobs/create-version-branch.js +++ b/jobs/create-version-branch.js @@ -22,7 +22,8 @@ const { createTransformFunction, generateGitHubCompareURL, hasTooManyPackageJSONs, getSatisfyingVersions, - getOldVersionResolved + getOldVersionResolved, + getLicenseAndAuthorFromVersions } = require('../utils/utils') const prContent = require('../content/update-pr') @@ -336,9 +337,7 @@ module.exports = async function ( dependency: dependencyKey, prTitles: config.prTitles }) - const license = versions[version].license - const licenseHasChanged = versions[oldVersionResolved].license !== license - const publisher = versions[version]['_npmUser'].name + const { license, licenseHasChanged, publisher } = getLicenseAndAuthorFromVersions({ versions, version, oldVersionResolved }) const body = prContent({ dependencyLink, diff --git a/utils/utils.js b/utils/utils.js index 7f5b6384..eeb0535e 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -323,6 +323,16 @@ const hasTooManyPackageJSONs = function (repo) { return repo.packages && Object.keys(repo.packages).length > 300 } +const getLicenseAndAuthorFromVersions = function ({ versions, version, oldVersionResolved }) { + const license = versions[version].license + return { + license, + licenseHasChanged: versions[oldVersionResolved].license !== license, + publisher: versions[version]['_npmUser'].name + + } +} + module.exports = { compactArray, seperateNormalAndMonorepos, @@ -341,5 +351,6 @@ module.exports = { updateNodeVersionToNvmrc, addNewLowestAndDeprecate, hasTooManyPackageJSONs, - getLockfilePath + getLockfilePath, + getLicenseAndAuthorFromVersions }