-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.js
60 lines (50 loc) · 1.35 KB
/
github.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
const octokit = require('@octokit/rest')();
const Configstore = require('configstore');
const pkg = require('./package.json');
const _ = require('lodash');
const CLI = require('clui');
const Spinner = CLI.Spinner;
const chalk = require('chalk');
const inquirer = require('inquirer');
const conf = new Configstore(pkg.name);
module.exports = {
getInstance: () => {
return octokit;
},
getStoredGithubToken: () => {
return conf.get('github.token');
},
setGithubCredentials: async () => {
},
registerNewToken: async () => {
const credentials = await inquirer.askGithubCredentials();
octokit.authenticate(
_.extend({
type: 'basic',
},
credentials
)
);
},
registerNewToken: async () => {
const status = new Spinner('Authenticating you, please wait...');
status.start();
try {
const response = await octokit.authorization.create({
scopes: ['user', 'public_repo', 'repo', 'repo:status'],
note: 'Myst release, the app for releaseing myst'
});
const token = response.data.token;
if (token) {
conf.set('github.token', token);
return token;
} else {
throw new Error("Missing Token", "GitHub token was not found in the response");
}
} catch (err) {
throw err;
} finally {
status.stop();
}
}
}