1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-26 21:12:59 +02:00

Tools: Improved git changelog

This commit is contained in:
Laurent Cozic 2020-01-24 22:43:55 +00:00
parent 715253da2f
commit 5b28f6b25f
2 changed files with 26 additions and 18 deletions

View File

@ -26,7 +26,7 @@ async function gitLog(sinceTag) {
author: {
email: authorEmail,
name: authorName,
login: await githubUsername(authorEmail),
login: await githubUsername(authorEmail, authorName),
},
});
}

View File

@ -122,35 +122,43 @@ async function saveGitHubUsernameCache(cache) {
await fs.writeFile(path, JSON.stringify(cache));
}
toolUtils.githubUsername = async function(email) {
toolUtils.githubUsername = async function(email, name) {
const cache = await loadGitHubUsernameCache();
if (email in cache) return cache[email];
const cacheKey = `${email}:${name}`;
if (cacheKey in cache) return cache[cacheKey];
let output = null;
const oauthToken = await toolUtils.githubOauthToken();
const response = await fetch(`https://api.github.com/search/users?q=${encodeURI(email)}+in:email`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${oauthToken}`,
},
});
const urlsToTry = [
`https://api.github.com/search/users?q=${encodeURI(email)}+in:email`,
`https://api.github.com/search/users?q=user:${encodeURI(name)}`,
];
const responseText = await response.text();
for (const url of urlsToTry) {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `token ${oauthToken}`,
},
});
const responseText = await response.text();
if (!response.ok) continue;
if (response.ok) {
const responseJson = JSON.parse(responseText);
if (!responseJson || !responseJson.items || responseJson.items.length !== 1) {
output = null;
} else {
output = responseJson.items[0].login;
}
if (!responseJson || !responseJson.items || responseJson.items.length !== 1) continue;
output = responseJson.items[0].login;
break;
}
cache[email] = output;
cache[cacheKey] = output;
await saveGitHubUsernameCache(cache);
return output;
};