-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
46 lines (38 loc) · 1.15 KB
/
extension.js
File metadata and controls
46 lines (38 loc) · 1.15 KB
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
const vscode = require('vscode');
const editor = vscode.window.activeTextEditor;
const rp = require('request-promise')
async function CreateGist () {
const text = editor.document.getText(editor.selection)
// User Input to name Gist file
const gistName = await vscode.window.showInputBox({
placeHolder: 'Name Your GistTest'
})
const options = {
method: 'POST',
uri: 'https://api.github.com/gists',
headers: {
'User-Agent': 'Request-Promise'
},
body: {
'description': 'the description for this gist',
'public': true,
'files': {}
},
json: true
}
options.body.files[gistName] = {content: text}
rp(options).then(r => {
const parsedUrl = vscode.Uri.parse(r.html_url)
vscode.commands.executeCommand('vscode.open', parsedUrl)
})
}
function activate(context) {
let disposable = vscode.commands.registerCommand('extension.createGist', function () {
CreateGist()
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;