Skip to content

Commit

Permalink
Setup fetch to query GitHub api for users
Browse files Browse the repository at this point in the history
  • Loading branch information
rkotze committed Aug 28, 2020
1 parent a0ee8bf commit b38b65f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"onCommand:gitmob.tweet",
"onCommand:gitmob.reload",
"onCommand:gitmob.searchRepositoryUsers",
"onCommand:gitmob.searchGithubAuthors",
"onCommand:gitmob.addRepoAuthorToCoAuthors",
"onCommand:gitmob.solo",
"onCommand:gitmob.searchGitEmojis",
Expand Down Expand Up @@ -126,6 +127,11 @@
"dark": "resources/icons/dark/search.svg"
}
},
{
"command": "gitmob.searchGithubAuthors",
"title": "Search Github users",
"category": "Git Mob"
},
{
"command": "gitmob.changePrimaryAuthor",
"title": "Change primary author",
Expand Down
17 changes: 17 additions & 0 deletions src/commands/github-authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const vscode = require("vscode");
const { fetch } = require("../github/fetch");
// const { addRepoAuthor } = require("../git/commands");
// const { GitExt } = require("../vscode-git-extension/git-ext");

function searchGithubAuthors() {
// const { mobAuthors } = coAuthorProvider;
return vscode.commands.registerCommand(
"gitmob.searchGithubAuthors",
async function () {
const result = await fetch("search/users?q=richard kotze");
console.log(JSON.parse(result));
}
);
}

exports.searchGithubAuthors = searchGithubAuthors;
33 changes: 33 additions & 0 deletions src/github/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const https = require("https");

function fetch(path) {
return new Promise(function (fulfil, reject) {
https
.get(
"https://api.github.com/" + path,
{
headers: {
"User-Agent": "vs-code-git-mob",
Accept: "application/vnd.github.v3+json",
Authorization: "token <tokenhere>",
},
},
(response) => {
let data = "";

response.on("data", (chunk) => {
data += chunk;
});

response.on("end", () => {
fulfil(data);
});
}
)
.on("error", (error) => {
reject(error);
});
});
}

exports.fetch = fetch;
2 changes: 2 additions & 0 deletions src/setup-git-mob.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
replaceCoAuthors,
} = require("./vscode-git-extension/format-scm-input-text");
const { soloAfterCommit } = require("./ext-config/solo-after-commit");
const { searchGithubAuthors } = require("./commands/github-authors");

const MAX_RETRIES = 5;

Expand Down Expand Up @@ -70,6 +71,7 @@ function bootGitMob(context, gitExt) {
soloCommand({ coAuthorProvider }),
searchGitEmojis(),
changePrimaryAuthor({ coAuthorProvider }),
searchGithubAuthors({ coAuthorProvider }),
];

disposables.forEach((dispose) => context.subscriptions.push(dispose));
Expand Down

0 comments on commit b38b65f

Please sign in to comment.