-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (53 loc) · 1.72 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
/* eslint-disable no-magic-numbers */
'use strict';
const core = require('@actions/core');
const { Octokit } = require('@octokit/core');
// const github = require('@actions/github');
const { execSync } = require('child_process');
const fs = require('fs/promises');
const main = async () => {
try {
const token = core.getInput('token', { required: true }); // to be used when introducing GH Action YAML
/*
* const {GH_TOKEN} = process.env;
* const token = GH_TOKEN;
*/
const octokit = new Octokit({ auth: token });
const getRepos = execSync('npx repo-report ls', {
encoding: 'utf-8', env: {
...process.env,
GH_TOKEN: token,
},
});
const repositories = getRepos.slice(0, getRepos.length - 1).split('\n');
const repoOSSF = {};
repositories.reduce(async (prev, repository) => {
await prev;
console.log(repository);
const cmd = `scorecard --repo=github.com/${repository} | grep Aggregate`;
const output = execSync(cmd, {
encoding: 'utf-8', env: {
...process.env,
GITHUB_AUTH_TOKEN: token,
},
});
const getRateLimit = await octokit.request('GET /rate_limit');
console.log(getRateLimit.data.rate);
const writeOSSF = async () => {
repoOSSF[repository] = await output.slice(17).replace('\n', '');
console.log('42', repoOSSF);
};
const callwriteOSSF = await writeOSSF();
console.log(callwriteOSSF);
console.log('Aggregate score for', repository, ': ', output.slice(17));
}, Promise.resolve()).then(() => {
console.log('48', repoOSSF);
const json = JSON.stringify(repoOSSF, null, 4);
const result = fs.writeFile('metadata-ossf-score.json', json, 'utf8');
console.log(result);
});
} catch (error) {
core.setFailed(error.message);
}
};
main();