-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfly.js
executable file
·49 lines (42 loc) · 1.42 KB
/
fly.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
const needle = require('needle');
const opener = require('opener');
const GitHubApi = require('github');
module.exports.fly = function(type, repo) {
const github = new GitHubApi({
// Optional args
protocol: 'https',
host: 'api.github.com', // Should be api.github.com for GitHub
headers: {
'user-agent': 'adamsiwiec' // GitHub is happy with a unique user agent
},
followRedirects: false, // Default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects
timeout: 5000
});
if (type === 'person') {
github.users.getForUser({
username: repo
}, (err, res) => {
if (err) {
console.log(err);
}
const user = JSON.stringify(res);
});
var person = type;
var requestUrl = 'users';
} else if (type === 'repo') {
var person = type;
var requestUrl = 'repos';
}
const url = 'https://api.github.com/' + requestUrl + '/' + repo;
needle.get(url, (err, res) => {
if (!err && res.statusCode === 200) {
const link = 'https://github.com/' + repo;
opener(link);
process.exit();
} else {
console.log('This ' + person + ' does not exist');
process.exit();
}
});
return true;
};