generated from bitprj/cabin
-
Notifications
You must be signed in to change notification settings - Fork 24
/
functions.js
66 lines (57 loc) · 1.72 KB
/
functions.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
const fs = require('fs') //get the methods in the fs package
const fetch = require('node-fetch');
const validateResponseStatus = (resp, uri) => {
if (resp.status == 404) {
throw new Error(`Your function could not be found at '${uri}' check function url secret`);
process.exit(1)
}
if (resp.status == 500) {
throw new Error("Your function has an error and could not be run ");
process.exit(1)
}
}
const queryString = (uri) => {
if (uri.indexOf("?") === -1) {
uri = uri + "?x=1"
}
return uri
}
const checkSecret = (secret, secretName) => {
if (!secret || !secret.trim()) {
throw new Error(`You forgot to add your '${secretName}' secret!`);
process.exit(1)
}
}
const checkCommit = (commit_file) => {
for (var i = 0; i < commit_file.length; i++) {
var a = commit_file[i];
fs.access(commit_file[i], err => {
if (err) {
throw new Error("You did not commit '" + a + "'")
process.exit(1)
}
})
}
}
const throwError = async (error, user, repo) => {
console.log(user)
console.log(repo)
const endpoint = "https://counselorbot.azurewebsites.net/api/hasuraErrorUpdate?code=qL2oUjo1aUIBdfJe3VhEF41qRQBSnShZwPGr3dujRwvtOGa855fLoA==";
options = {
method: "POST",
headers: {
user,
repo,
error
}
}
await fetch(endpoint, options)
console.log("fetch has been made")
process.exit(1)
}
exports.throwError = throwError
exports.queryString = queryString
exports.validateResponseStatus = validateResponseStatus
exports.checkSecret = checkSecret
exports.checkCommit = checkCommit
exports.throwError = throwError