Skip to content

Commit

Permalink
Fetch user info & add to co-authors file
Browse files Browse the repository at this point in the history
This works at a simple level but not all users have emails available. This is needed to co-author commits.

#15
  • Loading branch information
rkotze committed Sep 19, 2020
1 parent 8edb53b commit 6c7abe3
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/commands/github-authors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const vscode = require("vscode");
const { get } = require("../github/github-api");
// const { addRepoAuthor } = require("../git/commands");
// const { GitExt } = require("../vscode-git-extension/git-ext");
const { addRepoAuthor } = require("../git/commands");

function searchGithubAuthors() {
// const { mobAuthors } = coAuthorProvider;
return vscode.commands.registerCommand(
"gitmob.searchGithubAuthors",
async function () {
Expand All @@ -17,10 +15,26 @@ function searchGithubAuthors() {
return null;
},
});
const result = await get("search/users?q=" + searchText);
console.log(result);
const searchUsers = await get("search/users?q=" + searchText);
const users = await Promise.all(
searchUsers.data.items.map((item) => get(item.url))
);
const selectedAuthor = await quickPickAuthors(users);
if (selectedAuthor) {
addRepoAuthor(selectedAuthor.repoAuthor);
await vscode.commands.executeCommand("gitmob.reload");
}
}
);
}

async function quickPickAuthors(repoAuthors) {
const authorTextArray = repoAuthors.map(({ data }) => ({
label: `${data.name} ${data.login}`,
description: `<${data.email}>`,
repoAuthor: { ...data, commandKey: data.login },
}));
return await vscode.window.showQuickPick(authorTextArray);
}

exports.searchGithubAuthors = searchGithubAuthors;

0 comments on commit 6c7abe3

Please sign in to comment.