-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.js
45 lines (36 loc) · 1.16 KB
/
main.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
const core = require("@actions/core");
const github = require("@actions/github");
const axios = require("axios");
const fs = require("fs");
async function main() {
try {
let file = core.getInput('file', {required: false}) || 'package.json';
let packageJson = fs.readFileSync(file, 'utf8');
packageJson = JSON.parse(packageJson);
let githubUsername = github.context.repo.owner;
let githubRepository = github.context.repo.repo;
let gitUrl = `https://github.com/${githubUsername}/${githubRepository}`
try {
await axios.head(gitUrl);
} catch (e) {
core.setFailed('Private GitHub repositories are not supported at the moment');
return;
}
let data = {
'git_url': gitUrl,
'package_json': packageJson
}
await axios.post("https://api.chainalert.dev/v1/subscriptions", data)
} catch (err) {
console.error(err)
}
}
if (require.main === module) {
main()
.then(() => process.exit(0))
.catch(e => {
console.error(e);
process.exit(1);
});
}
module.exports.main = main;