Skip to content

Instantly share code, notes, and snippets.

@ramsaylanier
Created February 20, 2018 20:57
Show Gist options
  • Save ramsaylanier/4887fef783373a90f2289b68714ad664 to your computer and use it in GitHub Desktop.
Save ramsaylanier/4887fef783373a90f2289b68714ad664 to your computer and use it in GitHub Desktop.
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) {
// this code runs whenever your click 'Create Gist' from the context menu in your browser.
let disposable = vscode.commands.registerCommand(
"extension.createGist",
function() {
CreateGist();
}
);
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {}
exports.deactivate = deactivate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment