@r4lrgx/gitmoji
Version:
🧱 My customized Gitmoji Config - a fork of https://github.com/arvinxx/gitmoji-commit-workflow - just with several bug fixes and a cleaner look.
52 lines (49 loc) • 1.47 kB
JavaScript
import fetch from 'sync-fetch';
// @r4lrgx/gitmoji v1.0.3
// MIT License
function gitHubLookup(email) {
const match = email.match(/^(\d*)\+?([a-zA-Z0-9\-]*)\.noreply\.github\.com$/);
let info = null;
if (match) {
const [_, id, username] = match;
info = { id, username };
} else {
try {
const res = fetch(`https://api.github.com/search/commits?q=author-email:${encodeURIComponent(email)}`, {
headers: {
Accept: "application/vnd.github.cloak-preview+json"
}
});
if (!res.ok) return null;
const data = res.json();
if (data.items && data.items.length > 0) {
const username = data.items[0]?.author?.login;
const id = data.items[0]?.author?.id;
if (id && username) info = { id, username };
}
} catch (_err) {
return null;
}
}
if (!info?.id || !info?.username) return null;
try {
const res = fetch(`https://api.github.com/users/${info.username}`, {
headers: {
Accept: "application/vnd.github.cloak-preview+json"
}
});
if (!res.ok) return null;
const user = res.json();
return {
authorName: info.username,
authorAvatar: user.avatar_url,
authorUrl: user.html_url,
authorEmail: `${info.id}+${info.username}.noreply.github.com`
};
} catch (_err) {
return null;
}
}
export { gitHubLookup };
//# sourceMappingURL=lookup.js.map
//# sourceMappingURL=lookup.js.map