forked from varsha5595/constable-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
129 lines (118 loc) · 2.9 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const core = require('@actions/core');
const github = require('@actions/github')
const fs = require('fs');
const table = require('markdown-table')
const issueChecker = require('./src/issue-checker')
var readme_present = 0;
var contributions_present = 0;
var conduct_present = 0;
var license_present = 0;
var gitignore_present = 0;
var citations_present = 0;
var issue_score = 0;
var total_score = 0;
const token = process.env.GITHUB_TOKEN
const octoClient = github.getOctokit(token)
const repo = github.context.repo
function fileCheck() {
try {
fs.readdirSync('.').forEach(file => {
if(file == 'README.md') {
readme_present = 1;
total_score = total_score+1;
}
if(file == 'CONTRIBUTING.md') {
contributions_present = 1;
total_score = total_score+1;
}
if(file == 'CODE_OF_CONDUCT.md') {
conduct_present = 1;
total_score = total_score+1;
}
if(file == 'LICENSE') {
license_present = 1;
total_score = total_score+1;
}
if(file == 'CITATION.md') {
citations_present = 1;
total_score = total_score+1;
}
if(file == '.gitignore') {
gitignore_present = 1;
total_score = total_score+1;
}
});
} catch (error) {
core.setFailed(error.message);
}
}
/*
Grades Range:
A+ : 95+
A : 90-94
B+ : 85-89
B : 80-84
C+ : 75-79
C : 70-74
D+ : 65-69
D : 60-64
Redo: 0-59
*/
function calculateGrade(score) {
let grade = 'F'
if(score >= 95) {
grade = 'A+'
}
if(score >= 90 && score <= 94) {
grade = 'A'
}
if(score >=85 && score <= 89) {
grade = 'B+'
}
if(score >=80 && score <= 84) {
grade = 'B'
}
if(score >=75 && score <= 79) {
grade = 'C+'
}
if(score >=70 && score <= 74) {
grade = 'C'
}
if(score >=65 && score <= 69) {
grade = 'D+'
}
if(score >=60 && score <= 64) {
grade = 'D'
}
return grade
}
const repository = `${repo.owner}/${repo.repo}`
async function issueCheck() {
issue_score = await issueChecker.check(repository, octoClient)
total_score+=issue_score
}
async function run() {
// Check Files
fileCheck()
await issueCheck()
const score = (total_score/8)*100;
core.info(`Score for this repo = ` + score);
core.setOutput('score', score)
const grade = calculateGrade(score);
core.info(`Grade for this repo = ` + grade);
core.setOutput('grade', grade)
var report = table([
['Item', 'Weight', 'Score'],
['README.md','1', readme_present],
['CONTRIBUTING.md','1', contributions_present],
['CODE_OF_CONDUCT.md','1', conduct_present],
['LICENSE.md','1', license_present],
['CITATION.md','1', citations_present],
['.gitignore','1', gitignore_present],
['issues closed (last 30 days)', '1', issue_score],
['**Total Score**', `**${total_score}**`, `**${score}**`]
]);
console.log(report)
core.setOutput('report', report)
}
run();