Allow Specifying Co-Authors in Changelog (#1037)

[SKIP]
This commit is contained in:
Integer Limit 2024-10-07 13:57:42 +11:00 committed by GitHub
parent 9087ef2b62
commit 134146f585
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 76 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import {
AuthorInfo,
Commit,
FixUpInfo,
InputReleaseType,
@ -30,6 +31,9 @@ export default class ChangelogData {
// Map of project IDs to info text and/or details
modInfoList: Map<number, ParsedModInfo>;
// Map of commit sha to specified coauthors for that commit
coAuthorList: Map<string, AuthorInfo[]>;
/**
* Constructor. Non-Async Inits are performed here.
*/
@ -70,6 +74,7 @@ export default class ChangelogData {
this.combineList = new Map<string, Commit[]>();
this.modInfoList = new Map<number, ParsedModInfo>();
this.coAuthorList = new Map<string, AuthorInfo[]>();
// Init Tag Sets for Now, so we don't have to deal with nullable params
this.tags = new Set<string>();
@ -116,6 +121,7 @@ export default class ChangelogData {
this.combineList = new Map<string, Commit[]>();
this.modInfoList = new Map<number, ParsedModInfo>();
this.coAuthorList = new Map<string, AuthorInfo[]>();
// Tags list is fine because the 'to' (Target) stays the same
// Other Tags list is generated at setup

View File

@ -41,6 +41,8 @@ export const ignoreKey = "[IGNORE]";
export const modInfoKey = "[MOD INFO]";
export const modInfoList = "infos";
export const priorityKey = "[PRIORITY]";
export const coAuthorsKey = "[AUTHORS]";
export const coAuthorsList = "authors";
/* Sub Category Keys */
// Mode Category Keys

View File

@ -8,6 +8,7 @@ import {
} from "#types/changelogTypes.ts";
import {
categories,
coAuthorsKey,
combineKey,
defaultIndentation,
detailsKey,
@ -18,6 +19,7 @@ import {
priorityKey,
} from "./definitions.ts";
import {
parseCoAuthor,
parseCombine,
parseDetails,
parseExpand,
@ -111,6 +113,9 @@ export async function parseCommitBody(
if (commitBody.includes(modInfoKey))
await parseModInfo(commitBody, commitObject);
if (commitBody.includes(coAuthorsKey))
await parseCoAuthor(commitBody, commitObject);
if (commitBody.includes(expandKey)) {
await parseExpand(commitBody, commitObject, parser);
return true;

View File

@ -287,43 +287,57 @@ export async function formatMessage(
return `${indentation}* ${message} - ${author} (${formattedCommit})`;
}
// Sort original array so newest commits appear at the end instead of start of commit string
sortCommitListReverse(commits);
const formattedCommits: string[] = [];
const authors: string[] = [];
const retrievedAuthors: { commit: Commit; formatted: string }[] =
const retrievedAuthors: { commit: Commit; name: string; email: string }[] =
await Promise.all(
commits.map((commit) =>
formatAuthor(commit).then((formatted) => {
return { commit, formatted };
formatAuthor(commit).then((name) => {
return { commit, name, email: commit.author_email };
}),
),
);
const processedSHAs: Set<string> = new Set<string>();
sortCommitList(commits, (commit) => commit);
// Co-Authors for Each Commit, Format Commits
commits.forEach((commit) => {
if (processedSHAs.has(commit.hash)) return;
formattedCommits.push(
`[\`${commit.hash.substring(0, 7)}\`](${repoLink}commit/${commit.hash})`,
);
processedSHAs.add(commit.hash);
const authors = data.coAuthorList.get(commit.hash);
if (!authors || authors.length === 0) return;
retrievedAuthors.push(
...authors.map((author) => {
return { commit, name: `@${author.name}`, email: author.email };
}),
);
});
const processedAuthors: Set<string> = new Set<string>();
const processedEmails: Set<string> = new Set<string>();
const processedSHAs: Set<string> = new Set<string>();
sortCommitList(
retrievedAuthors,
(author) => author.commit,
(a, b) => a.formatted.localeCompare(b.formatted),
(a, b) => a.name.localeCompare(b.name),
);
retrievedAuthors.forEach((pAuthor) => {
if (processedSHAs.has(pAuthor.commit.hash)) return;
// Author
if (
!processedAuthors.has(pAuthor.formatted) &&
!processedEmails.has(pAuthor.commit.author_email)
!processedAuthors.has(pAuthor.name) &&
!processedEmails.has(pAuthor.email)
) {
authors.push(pAuthor.formatted);
processedAuthors.add(pAuthor.formatted);
processedEmails.add(pAuthor.commit.author_email);
authors.push(pAuthor.name);
processedAuthors.add(pAuthor.name);
processedEmails.add(pAuthor.email);
}
formattedCommits.push(
`[\`${pAuthor.commit.hash.substring(0, 7)}\`](${repoLink}commit/${pAuthor.commit.hash})`,
);
processedSHAs.add(pAuthor.commit.hash);
});
// Delete all Formatted Commits after MaxIncludeCommits elements, replace with '...'

View File

@ -1,4 +1,5 @@
import {
AuthorInfo,
ChangelogMessage,
Commit,
ExpandedMessage,
@ -14,6 +15,8 @@ import {
import dedent from "dedent-js";
import matter, { GrayMatterFile } from "gray-matter";
import {
coAuthorsKey,
coAuthorsList,
combineKey,
combineList,
combineRoot,
@ -165,6 +168,29 @@ export async function parseIgnore(
return undefined;
}
/**
* Parses a commit with coauthor info.
*/
export async function parseCoAuthor(
commitBody: string,
commitObject: Commit,
): Promise<void> {
if (!commitBody.includes(coAuthorsKey)) return;
await parseTOMLWithRootToList<AuthorInfo>(
commitBody,
commitObject,
coAuthorsKey,
coAuthorsList,
(item) => !item.email || !item.name,
async (item) => {
const authors = data.coAuthorList.get(commitObject.hash) ?? [];
authors.push(item);
data.coAuthorList.set(commitObject.hash, authors);
},
(item) => item as unknown as AuthorInfo,
);
}
/**
* Parses a commit with 'Fixup'.
*/

View File

@ -301,6 +301,11 @@ export interface PriorityInfo {
priority: number;
}
export interface AuthorInfo {
name: string;
email: string;
}
export type FixUpMode = "REPLACE" | "ADDITION";
export type InputReleaseType =