UNPKG

git-release-manager

Version:

A tool to generate release notes from git commit history

48 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.profileUrlCache = void 0; exports.prepareProfileUrlsByEMail = prepareProfileUrlsByEMail; exports.getGitHubProfileUrl = getGitHubProfileUrl; exports.profileUrlCache = new Map(); async function prepareProfileUrlsByEMail(email) { if (!email) { return undefined; } if (!exports.profileUrlCache.has(email)) { let profileUrl = null; if (process.env.GITHUB_TOKEN) { profileUrl = await getGitHubProfileUrl(email, process.env.GITHUB_TOKEN); } exports.profileUrlCache.set(email, profileUrl !== null && profileUrl !== void 0 ? profileUrl : `mailto:${email}`); } return exports.profileUrlCache.get(email); } async function getGitHubProfileUrl(email, token) { const url = `https://api.github.com/search/users?q=${email}`; try { const response = await fetch(url, { headers: token ? { Authorization: `token ${token}`, } : {}, }); if (!response.ok) { console.error('API Request Failed:', response.statusText); return null; } const data = await response.json(); if (data.total_count > 0 && data.items[0].html_url) { return data.items[0].html_url; } else { console.warn('No GitHub profile found for email:', email); return null; } } catch (error) { console.error('Error fetching GitHub profile:', error); return null; } } //# sourceMappingURL=profileHandler.js.map