-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (58 loc) · 2.26 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const core = require('@actions/core');
const github = require('@actions/github');
const execa = require('execa');
const fs = require('fs');
function run_command(options) {
const options_array = options.split(' ');
try {
execa.sync('cloc', options_array);
console.log(`command run`);
} catch (error) {
core.setFailed(`Error in running the command: ${error.message}`);
}
}
const comment_report = async (context, github_token, issue_number, message) => {
console.log("commenting");
const author = context.payload.sender.login;
const octokit = github.getOctokit(github_token);
const comment = await octokit.issues.createComment({
issue_number: issue_number,
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
body: message
});
core.debug(`Sucessfully commented on the target issue`);
}
const run = async () => {
const github_token = core.getInput('GITHUB_TOKEN', { required: true });
const issue_number = core.getInput('issue_number', { required: true });
const options = core.getInput('options', { required: true });
const context = github.context;
run_command(options);
var report_text = "";
try {
report_text = fs.readFileSync('report.md', 'utf-8');
} catch (error) {
core.setFailed(`Error in reading the file: ${error.message}`);
}
var lines = report_text.split('\n');
lines.splice(0, 3);
report_text = lines.join('\n');
const fixed_footer = `
Horribly commented code averages 0-5% comment ratio.
Poorly commented code has a 5-10% comment ratio.
Average code has a 10-15% comment ratio.
Good code has a 15-25% comment ratio.
Excellent code has a > 25% comment ratio.
Use [this action](https://github.com/deep5050/comment-to-code-ratio-action) on your projects to generate a report like this.`;
var modified_data = `#### comment-to-code-ratio analysis report for the last push :tada:
${report_text}
${fixed_footer}`;
try {
fs.writeFileSync('report.md', modified_data,'utf-8')
} catch (error) {
core.setFailed(`Error in writing the file: ${error.message}`);
}
await comment_report(context, github_token, issue_number, modified_data);
}
run();