Last active
July 4, 2018 17:32
-
-
Save kijart/9f4d4ae07ce605ae3199c96133e5222d to your computer and use it in GitHub Desktop.
Get GitHub emails from current repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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