Skip to content

Commit

Permalink
feat(utils): put license&author-get to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
hulkoba authored and Realtin committed Jul 4, 2019
1 parent 41984f4 commit 514469b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
7 changes: 3 additions & 4 deletions jobs/create-group-version-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const {
generateGitHubCompareURL,
hasTooManyPackageJSONs,
getSatisfyingVersions,
getOldVersionResolved
getOldVersionResolved,
getLicenseAndAuthorFromVersions
} = require('../utils/utils')
const {
isPartOfMonorepo,
Expand Down Expand Up @@ -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({
Expand Down
7 changes: 3 additions & 4 deletions jobs/create-version-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const { createTransformFunction,
generateGitHubCompareURL,
hasTooManyPackageJSONs,
getSatisfyingVersions,
getOldVersionResolved
getOldVersionResolved,
getLicenseAndAuthorFromVersions
} = require('../utils/utils')

const prContent = require('../content/update-pr')
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -341,5 +351,6 @@ module.exports = {
updateNodeVersionToNvmrc,
addNewLowestAndDeprecate,
hasTooManyPackageJSONs,
getLockfilePath
getLockfilePath,
getLicenseAndAuthorFromVersions
}

0 comments on commit 514469b

Please sign in to comment.