Skip to content

Commit

Permalink
Merge pull request #29 from thalleslmF/pr-203
Browse files Browse the repository at this point in the history
Pr 203
  • Loading branch information
thalleslmF authored Jul 30, 2021
2 parents 50bfb87 + b7e019a commit 3b5d4fe
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions licence.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const github = require('@actions/github')
const fs = require("fs");
const util = require("util");
const chalk = require("chalk");
async function hasCorrectCopyrightDate(copyrightFile, file, startDateLicense) {
function hasCorrectCopyrightDate(copyrightFile, file, startDateLicense) {
let requiredDate = ''
console.log(file.year)
if (file.status === 'modified'){
Expand Down Expand Up @@ -51,7 +51,7 @@ async function checkLicenseFile(file, config, fd) {
let buffer = new Buffer(8000)
return await new Promise(
(resolve, reject) => {
fs.read(fd, buffer, 0, 8000, 0, async (err) => {
fs.read(fd, buffer, 0, 8000, 0, (err) => {
if (err) {
console.error(`Error reading file ${err}`)
}
Expand All @@ -65,7 +65,7 @@ async function checkLicenseFile(file, config, fd) {
reject(file.name)
} else {

const correctDate = await hasCorrectCopyrightDate(copyrightFile, file, config.startDateLicense)
const correctDate = hasCorrectCopyrightDate(copyrightFile, file, config.startDateLicense)
if (correctDate) {
console.log('File ' + chalk.yellow(file.name+": ") + chalk.green('ok!'))
resolve()
Expand Down Expand Up @@ -110,9 +110,7 @@ async function getCreationYear(file, config) {
const commitsDates = response.data.map(
data => new Date(data.commit.author.date)
)
console.log(commitsDates)
const creationDate = Math.min.apply(null, commitsDates)
console.log(creationDate)
return new Date(creationDate).getFullYear()
}

Expand Down Expand Up @@ -149,14 +147,15 @@ const checkLicense = async (fileNames, config) => {
}
)
const filesFiltered = removeIgnoredFiles(filesPr, fileNames)
await filesFiltered.map(
(file) => {
const filesWithYear = await Promise.all(filesFiltered.map(
(file) => {
return {
...file,
year : getCreationYear(file, config)
year : getCreationYear(file, config)
}
})
return await checkFilesLicense(filesFiltered, config)
}))
console.log(filesWithYear)
return await checkFilesLicense(filesWithYear, config)

}

Expand Down

0 comments on commit 3b5d4fe

Please sign in to comment.