Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: thalles <lopthalles@gmail.com>
  • Loading branch information
thalleslmF committed Jul 28, 2021
0 parents commit 0aa26f1
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
dist

.idea

.DS_Store

.scannerwork

coverage/
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Check License and date from prs files'
description: 'Check License and date from prs files'
inputs:
token: # id da entrada
description: 'Github token'
required: true
owner: # id da entrada
description: 'Github token'
required: true
repo: # id da entrada
description: 'Github token'
required: true
outputs:
time: # id da saída
description: 'The time we greeted you'
runs:
using: 'node12'
main: 'main.js'
31 changes: 31 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"copyright": [
"Copyright",
"ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA",
"Licensed under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License.",
"You may obtain a copy of the License at",
"http://www.apache.org/licenses/LICENSE-2.0",
"Unless required by applicable law or agreed to in writing, software",
"distributed under the License is distributed on an \"AS IS\" BASIS,",
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"See the License for the specific language governing permissions and",
"limitations under the License."
],
"ignore": [
"node_modules/**",
".md",
".json",
".png",
".idea",
".github",
".git",
".gitignore",
".vscode",
"dist/",
"coverage/**",
"upgrades/**",
".storybook",
".svg"
]
}
75 changes: 75 additions & 0 deletions licence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2020, 2021 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const core = require('@actions/core')
const github = require('@actions/github')
const fs = require("fs");

function getExtensionCommentPattern(extension) {
let result = ''
switch(extension) {

case "yaml" : case "sh": case "properties":
result = "#"
break;
case "sql":
result = "--"
default:
result = "/*"
}
return result
}

const checkLicense = async (fileNames, copyrightContent) => {
const token = core.getInput('token')
const octokit = github.getOctokit(token)
const prNumber = github.context.payload.pull_request.number
const owner = github.context.payload.repository.owner
const repo = github.context.payload.repository.name
const response = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}', ({
owner: owner,
repo: repo,
pull_number: prNumber
}))
console.log(response)
for( let name of fileNames) {
fs.open(name, 'r', (status,fd) => {
var buffer = new Buffer(8000)
fs.read(fd, buffer, 0, 8000, 0, (err) => {
if (err) {
console.error(`Error reading file ${err}`)
}
const copyrightFile = buffer.toString('utf-8')
const allCopyrightIncluded = copyrightContent.every(
line => copyrightFile.includes(line)
)

if (!allCopyrightIncluded) {
console.error(`File ${name} :No copyright header!`)
} else {
console.error(`File ${name} :ok!`)
}
})
})
}



}



exports.checkLicense = checkLicense
8 changes: 8 additions & 0 deletions license-check.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
20 changes: 20 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { checkLicense } = require("./licence");
fs = require('fs');
glob = require('glob')
let file = "config.json"
const data = fs.readFileSync(file, 'utf-8');
let dataObject = JSON.parse(data)
let copyrightContent = dataObject.copyright
let ignore = dataObject.ignore
glob(
"**/*.*",{cwd: process.cwd(), ignore: ignore }, (err,fileNames) => {
if (err) {
console.log(err)
}
checkLicense(fileNames, copyrightContent).then(r =>
console.log(r))
.catch(
err => console.error(err)
)
}
)
Loading

0 comments on commit 0aa26f1

Please sign in to comment.