generated from actions/javascript-action
/
index.js
46 lines (43 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const core = require('@actions/core');
const exec = require('@actions/exec')
const github = require('@actions/github')
const fs = require('fs')
const path = require('path')
const token = core.getInput('repotoken')
const octokit = github.getOctokit(token);
async function run() {
try {
// jscpd detect
const p = path.resolve('./jscpdrs-cli')
await exec.exec(`${p} --output ${path.resolve('./', 'results.json')}`, [], {
listeners: {
stderr: (data) => {
core.warning(data.toString('utf-8'))
}
}
})
let content = fs.readFileSync(`${path.resolve('./', 'results.json')}`).toString('utf8')
const renderItem = (item) => {
return [
`[${item.duplication_a.source_id}](${item.duplication_a.source_id})`,
'```ts\n' + item.duplication_a.fragement + '\n```',
`[${item.duplication_a.source_id}](${item.duplication_b.source_id})`,
'```ts\n' + item.duplication_b.fragement + '\n```'
].join('\n')
}
// create issue
content = JSON.parse(content)
detected = content.map(item => {
return renderItem(item)
}).join('\n')
const context = github.context;
await octokit.issues.create({
...context.repo,
title: 'Found copied',
body: `${detected}`
});
} catch (error) {
core.setFailed(error.message);
}
}
run();