Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Version 1.3.0: Replace spdx-license-list ~> choosealicense-list
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Nov 8, 2018
1 parent 0c3a065 commit 9226986
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
50 changes: 31 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -9,12 +9,22 @@ module.exports = app => {
]

const createFile = async (github, params, license, author) => {
var licenseRaw = license.licenseText.replace(
'<year>', new Date().getFullYear()
var licenseRaw = license.body.replace(
/\[year\]/gi, new Date().getFullYear()
).replace(
'<copyright holders>', 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,
Expand All @@ -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',
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <TiagoDanin@outlook.com>",
"license": "MIT",
Expand All @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9226986

Please sign in to comment.