-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathutils.js
34 lines (33 loc) · 947 Bytes
/
utils.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
const request = require('request-promise-native');
const vm = require('vm');
module.exports = {
async getGitHintFile(owner, repo, branch) {
try {
let data = await request({
url: `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/.ghint.json`,
method: 'GET'
});
return { data: JSON.parse(data) };
} catch (error) {
try {
let data = await request({
url: `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/.githint.json`,
method: 'GET'
});
return { data: JSON.parse(data) };
} catch (error) {
return { error };
}
}
},
async runScript(source, scope) {
try {
const script = new vm.Script(`(function(){${source}})()`);
const context = new vm.createContext(scope);
let data = script.runInContext(context);
return { data };
} catch (error) {
return { error };
}
}
}