jccp_a/vuepress/node_modules/@vuepress/plugin-git/lib/node/resolveChangelog.js
hellcat ac91e1fbe4 1
2025-11-12 17:57:30 +08:00

57 lines
1.6 KiB
JavaScript

import { getContributorInfo, getUserNameWithNoreplyEmail, sanitizeHTML, } from './utils/index.js';
const RE_CLEAN_REFS = /[()]/g;
const parseTagName = (refs) => {
if (!refs)
return;
const tags = refs
.replace(RE_CLEAN_REFS, '')
.split(',')
.map((tag) => tag.trim());
return tags[0]?.includes('tag:') ? tags[0].replace('tag:', '').trim() : '';
};
/**
* Resolve changelog
*
* 解析变更日志
*
* @param app - VuePress app instance
*
* VuePress 应用实例
*
* @param commits - Git commits
*
* Git 提交记录
*
* @param options - Changelog options
*
* 变更日志选项
*
* @param contributors - Contributor info
*
* 贡献者信息
*/
export const resolveChangelog = (app, commits, options, contributors) => {
const result = [];
const sliceCommits = options.maxCount
? commits.slice(0, options.maxCount)
: commits;
for (const commit of sliceCommits) {
const { hash, message, time, author, email, refs, coAuthors } = commit;
const tag = parseTagName(refs);
const contributor = getContributorInfo({ name: getUserNameWithNoreplyEmail(email) ?? author, email }, contributors);
const resolved = {
hash,
time,
email: contributor?.email || email,
author: contributor?.name ?? contributor?.username ?? author,
message: sanitizeHTML(app.markdown.renderInline(message)),
};
if (coAuthors.length)
resolved.coAuthors = coAuthors;
if (tag)
resolved.tag = tag;
result.push(resolved);
}
return result;
};