Skip to content

Instantly share code, notes, and snippets.

@kijart
Last active July 4, 2018 17:32
Show Gist options
  • Save kijart/9f4d4ae07ce605ae3199c96133e5222d to your computer and use it in GitHub Desktop.
Save kijart/9f4d4ae07ce605ae3199c96133e5222d to your computer and use it in GitHub Desktop.
Get GitHub emails from current repository
javascript: (() => {
const regex = /^https:\/\/github\.com\/([a-zA-Z0-9-_.]+\/[a-zA-Z0-9-_.]+)/g;
const regexMatch = regex.exec(window.location.href);
if (!regexMatch) {
alert('Wrong site, use this script in a URL like: https://github.com/user/repository-name');
return;
}
const userName = regexMatch[1];
fetch(`https://api.github.com/repos/${userName}/branches`)
.then(response => response.json())
.then(data => {
const urls = data.map(branch => `https://api.github.com/repos/${userName}/commits/${branch.name}`);
Promise.all(urls.map(url => fetch(url)))
.then(responses => Promise.all(
responses.map(response => response.json())
))
.then(result => {
const emails = result.map((obj) => obj.commit.author.email);
const emailList = emails.filter(function(email, index) {
return emails.indexOf(email) === index;
}).join(', ');
alert(emailList);
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment