diff --git a/index.js b/index.js index 7293df2..cef64a0 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const spdxLicenseList = require('spdx-license-list/full') +const choosealicense = require('choosealicense-list') module.exports = app => { app.log('Yay, the app was loaded!') const files = [ @@ -9,12 +9,22 @@ module.exports = app => { ] const createFile = async (github, params, license, author) => { - var licenseRaw = license.licenseText.replace( - '', new Date().getFullYear() + var licenseRaw = license.body.replace( + /\[year\]/gi, new Date().getFullYear() ).replace( - '', author + /\[fullname\]/gi, author + ).replace( + /\[login\]/gi, author + ).replace( + /\s\(\[email\]\)/gi, '' + ).replace( + /\[project\]/gi, params.repo + ).replace( + /\[description\]/gi, '' + ).replace( + /\[projecturl\]/gi, `https://github.com/${params.owner}/${params.repo}` ) - + app.log('License:', licenseRaw) app.log('Create file', params) return await github.repos.createFile({ ...params, @@ -23,12 +33,13 @@ module.exports = app => { content: Buffer.from(licenseRaw).toString('base64') }).then(async (res) => { if (res && res.data) { + app.log('Create commit comment', params) return github.repos.createCommitComment({ ...params, sha: res.data.commit.sha, body: `**License Info.** Author: \`${author}\` -License type: ${license.name} +License type: ${license.title} Repository owner: @${params.owner} `, path: 'LICENSE', @@ -59,22 +70,23 @@ Repository owner: @${params.owner} app.log('Invalid package.json', params) return e } - var licenseType = (content.license || '').toString().toLocaleLowerCase() + var licenseType = (content.license || '').toString() var author = (content.author || params.owner).toString() app.log('Package.json', licenseType, author) - for (var license in spdxLicenseList) { - if (license.toLocaleLowerCase() == licenseType) { - return await createFile( - github, - { - owner: params.owner, - repo: params.repo - }, - spdxLicenseList[license], - author - ) - } + + var license = choosealicense.find(licenseType) + if (license) { + return await createFile( + github, + { + owner: params.owner, + repo: params.repo + }, + license, + author + ) } + return 'Not found license' } }).catch((e) => e) } diff --git a/package.json b/package.json index d8f5ea0..fe53fe3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "add-license-bot", - "version": "1.2.0", + "version": "1.3.0", "description": "Generate LICENSE file from package.json", "author": "TiagoDanin ", "license": "MIT", @@ -22,7 +22,7 @@ }, "dependencies": { "probot": "7.3.1", - "spdx-license-list": "4.1.0" + "choosealicense-list": "1.0.0" }, "devDependencies": { "jest": "23.6.0", diff --git a/yarn.lock b/yarn.lock index 06f3e36..c9f912a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -654,6 +654,10 @@ chokidar@^2.0.4: optionalDependencies: fsevents "^1.2.2" +choosealicense-list@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/choosealicense-list/-/choosealicense-list-1.0.0.tgz#0c724cf84be1c589c1306be72a43f5ce46e6bef0" + chownr@^1.0.1: version "1.1.1" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494" @@ -3753,10 +3757,6 @@ spdx-license-ids@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz#e2a303236cac54b04031fa7a5a79c7e701df852f" -spdx-license-list@4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/spdx-license-list/-/spdx-license-list-4.1.0.tgz#29cfa3248a45fdf314b9a82974c06fb3b9352b89" - split-string@^3.0.1, split-string@^3.0.2: version "3.1.0" resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"