mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Tools: Add developer names to changelog
This commit is contained in:
parent
22a93994aa
commit
6f8c634756
1
Tools/.gitignore
vendored
1
Tools/.gitignore
vendored
@ -1 +1,2 @@
|
||||
*-kct.*
|
||||
github_username_cache.json
|
||||
|
@ -6,21 +6,28 @@
|
||||
|
||||
require('app-module-path').addPath(`${__dirname}/../ReactNativeClient`);
|
||||
|
||||
const { execCommand } = require('./tool-utils.js');
|
||||
const { execCommand, githubUsername } = require('./tool-utils.js');
|
||||
|
||||
async function gitLog(sinceTag) {
|
||||
let lines = await execCommand(`git log --pretty=format:"%H:%s" ${sinceTag}..HEAD`);
|
||||
let lines = await execCommand(`git log --pretty=format:"%H::::DIV::::%ae::::DIV::::%an::::DIV::::%s" ${sinceTag}..HEAD`);
|
||||
lines = lines.split('\n');
|
||||
|
||||
const output = [];
|
||||
for (const line of lines) {
|
||||
const splitted = line.split(':');
|
||||
const splitted = line.split('::::DIV::::');
|
||||
const commit = splitted[0];
|
||||
const message = line.substr(commit.length + 1).trim();
|
||||
const authorEmail = splitted[1];
|
||||
const authorName = splitted[2];
|
||||
const message = splitted[3].trim();
|
||||
|
||||
output.push({
|
||||
commit: commit,
|
||||
message: message,
|
||||
author: {
|
||||
email: authorEmail,
|
||||
name: authorName,
|
||||
login: await githubUsername(authorEmail),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -73,7 +80,7 @@ function filterLogs(logs, platform) {
|
||||
return output;
|
||||
}
|
||||
|
||||
function formatCommitMessage(msg) {
|
||||
function formatCommitMessage(msg, author) {
|
||||
let output = '';
|
||||
|
||||
const splitted = msg.split(':');
|
||||
@ -169,6 +176,20 @@ function formatCommitMessage(msg) {
|
||||
if (output.indexOf(formattedIssueNum) < 0) output += ` ${formattedIssueNum}`;
|
||||
}
|
||||
|
||||
let authorMd = null;
|
||||
if (author && (author.login || author.name) && author.login !== 'laurent22') {
|
||||
if (author.login) {
|
||||
const escapedLogin = author.login.replace(/\]/g, '');
|
||||
authorMd = `[@${escapedLogin}](https://github.com/${encodeURI(author.login)})`;
|
||||
} else {
|
||||
authorMd = `${author.name}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (authorMd) {
|
||||
output = output.replace(/\((#[0-9]+)\)$/, `($1 by ${authorMd})`);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -176,7 +197,7 @@ function createChangeLog(logs) {
|
||||
const output = [];
|
||||
|
||||
for (const log of logs) {
|
||||
output.push(formatCommitMessage(log.message));
|
||||
output.push(formatCommitMessage(log.message, log.author));
|
||||
}
|
||||
|
||||
return output;
|
||||
|
@ -1,3 +1,6 @@
|
||||
const fetch = require('node-fetch');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const toolUtils = {};
|
||||
|
||||
toolUtils.execCommand = function(command) {
|
||||
@ -103,6 +106,54 @@ toolUtils.fileExists = async function(filePath) {
|
||||
});
|
||||
};
|
||||
|
||||
async function loadGitHubUsernameCache() {
|
||||
const path = `${__dirname}/github_username_cache.json`;
|
||||
|
||||
if (await fs.exists(path)) {
|
||||
const jsonString = await fs.readFile(path);
|
||||
return JSON.parse(jsonString);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
async function saveGitHubUsernameCache(cache) {
|
||||
const path = `${__dirname}/github_username_cache.json`;
|
||||
await fs.writeFile(path, JSON.stringify(cache));
|
||||
}
|
||||
|
||||
toolUtils.githubUsername = async function(email) {
|
||||
const cache = await loadGitHubUsernameCache();
|
||||
if (email in cache) return cache[email];
|
||||
|
||||
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 responseText = await response.text();
|
||||
|
||||
if (response.ok) {
|
||||
const responseJson = JSON.parse(responseText);
|
||||
if (!responseJson || !responseJson.items || responseJson.items.length !== 1) {
|
||||
output = null;
|
||||
} else {
|
||||
output = responseJson.items[0].login;
|
||||
}
|
||||
}
|
||||
|
||||
cache[email] = output;
|
||||
await saveGitHubUsernameCache(cache);
|
||||
return output;
|
||||
};
|
||||
|
||||
toolUtils.githubOauthToken = async function() {
|
||||
const fs = require('fs-extra');
|
||||
const r = await fs.readFile(`${__dirname}/github_oauth_token.txt`);
|
||||
@ -115,8 +166,6 @@ toolUtils.githubRelease = async function(project, tagName, options = null) {
|
||||
isPreRelease: false,
|
||||
}, options);
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
const oauthToken = await toolUtils.githubOauthToken();
|
||||
|
||||
const response = await fetch(`https://api.github.com/repos/laurent22/${project}/releases`, {
|
||||
|
Loading…
Reference in New Issue
Block a user