diff --git a/tools/package-lock.json b/tools/package-lock.json index d46a819..cab3951 100644 --- a/tools/package-lock.json +++ b/tools/package-lock.json @@ -1,21 +1,20 @@ { - "name": "nomifactory-buildtools", + "name": "nomi-ceu-build-tools", "version": "1.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "nomifactory-buildtools", + "name": "nomi-ceu-build-tools", "version": "1.2.2", "license": "LGPL-3.0", "dependencies": { "@actions/core": "^1.10.1", "@egjs/list-differ": "^1.0.1", - "@iarna/toml": "^2.2.5", - "@types/iarna__toml": "^2.0.5", "@types/json-stable-stringify-without-jsonify": "^1.0.1", "dedent-js": "^1.0.1", - "json-stable-stringify-without-jsonify": "^1.0.1" + "json-stable-stringify-without-jsonify": "^1.0.1", + "toml-v1": "^1.0.0" }, "devDependencies": { "@octokit/rest": "^18.3.5", @@ -265,11 +264,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "node_modules/@iarna/toml": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", - "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==" - }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", @@ -599,14 +593,6 @@ "@types/node": "*" } }, - "node_modules/@types/iarna__toml": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@types/iarna__toml/-/iarna__toml-2.0.5.tgz", - "integrity": "sha512-I55y+SxI0ayM4MBU6yfGJGmi4wRll6wtSeKiFYAZj+Z5Q1DVbMgBSVDYY+xQZbjIlLs/pN4fidnvR8faDrmxPg==", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/imagemin": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/@types/imagemin/-/imagemin-8.0.0.tgz", @@ -694,7 +680,8 @@ "node_modules/@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", - "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==" + "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==", + "dev": true }, "node_modules/@types/q": { "version": "1.5.5", @@ -1037,7 +1024,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -3520,8 +3506,7 @@ "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "node_modules/end-of-stream": { "version": "1.4.4", @@ -6673,7 +6658,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, "engines": { "node": ">=8" } @@ -10361,7 +10345,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -10405,7 +10388,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -10522,6 +10504,14 @@ "dev": true, "optional": true }, + "node_modules/super-sources": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/super-sources/-/super-sources-1.1.1.tgz", + "integrity": "sha512-urkv0ksWoPIdRQjiDRrMLLLZvZtsJqU6Txlh3cxi/NhpC+NzlC170owSe8ruOZRJN1eWZ+GdvNsh/QXqMizxtQ==", + "dependencies": { + "string-width": "^4.2.3" + } + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -10918,6 +10908,14 @@ "xtend": "~4.0.1" } }, + "node_modules/toml-v1": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toml-v1/-/toml-v1-1.0.0.tgz", + "integrity": "sha512-fMk7vzBrPNFeuAvpN1eLeC3QBvTAKmqD3XRvHj5Z2nGasQfF+b//S4OqByUYRGASwshXM2TBCmMXMNWbnm7EYA==", + "dependencies": { + "super-sources": "^1.1.1" + } + }, "node_modules/tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -12038,11 +12036,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "@iarna/toml": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", - "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==" - }, "@jridgewell/resolve-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", @@ -12349,14 +12342,6 @@ "@types/node": "*" } }, - "@types/iarna__toml": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@types/iarna__toml/-/iarna__toml-2.0.5.tgz", - "integrity": "sha512-I55y+SxI0ayM4MBU6yfGJGmi4wRll6wtSeKiFYAZj+Z5Q1DVbMgBSVDYY+xQZbjIlLs/pN4fidnvR8faDrmxPg==", - "requires": { - "@types/node": "*" - } - }, "@types/imagemin": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/@types/imagemin/-/imagemin-8.0.0.tgz", @@ -12444,7 +12429,8 @@ "@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", - "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==" + "integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==", + "dev": true }, "@types/q": { "version": "1.5.5", @@ -12688,8 +12674,7 @@ "ansi-regex": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==" }, "ansi-styles": { "version": "4.3.0", @@ -14681,8 +14666,7 @@ "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "end-of-stream": { "version": "1.4.4", @@ -17150,8 +17134,7 @@ "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" }, "is-gif": { "version": "3.0.0", @@ -20012,7 +19995,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "requires": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -20047,7 +20029,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "requires": { "ansi-regex": "^5.0.1" } @@ -20133,6 +20114,14 @@ "dev": true, "optional": true }, + "super-sources": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/super-sources/-/super-sources-1.1.1.tgz", + "integrity": "sha512-urkv0ksWoPIdRQjiDRrMLLLZvZtsJqU6Txlh3cxi/NhpC+NzlC170owSe8ruOZRJN1eWZ+GdvNsh/QXqMizxtQ==", + "requires": { + "string-width": "^4.2.3" + } + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -20470,6 +20459,14 @@ } } }, + "toml-v1": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toml-v1/-/toml-v1-1.0.0.tgz", + "integrity": "sha512-fMk7vzBrPNFeuAvpN1eLeC3QBvTAKmqD3XRvHj5Z2nGasQfF+b//S4OqByUYRGASwshXM2TBCmMXMNWbnm7EYA==", + "requires": { + "super-sources": "^1.1.1" + } + }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", diff --git a/tools/package.json b/tools/package.json index 9f80ad1..913044f 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,9 +1,9 @@ { - "name": "nomifactory-buildtools", + "name": "nomi-ceu-build-tools", "version": "1.2.2", - "description": "Nomifactory Server Builder.", + "description": "Nomifactory CEu Buildscript and Tools.", "main": "gulpfile.js", - "author": "NotMyWing", + "author": "Nomi-CEu Team", "license": "LGPL-3.0", "devDependencies": { "@octokit/rest": "^18.3.5", @@ -52,10 +52,9 @@ "dependencies": { "@actions/core": "^1.10.1", "@egjs/list-differ": "^1.0.1", - "@iarna/toml": "^2.2.5", - "@types/iarna__toml": "^2.0.5", "@types/json-stable-stringify-without-jsonify": "^1.0.1", "dedent-js": "^1.0.1", - "json-stable-stringify-without-jsonify": "^1.0.1" + "json-stable-stringify-without-jsonify": "^1.0.1", + "toml-v1": "^1.0.0" } } diff --git a/tools/tasks/changelog/changelogData.ts b/tools/tasks/changelog/changelogData.ts index a3aa569..a6968ac 100644 --- a/tools/tasks/changelog/changelogData.ts +++ b/tools/tasks/changelog/changelogData.ts @@ -16,9 +16,12 @@ export default class ChangelogData { // Map of a commit SHA to the commits which need to be added to its commit list. combineList: Map; - // Set of tags + // Set of tags before 'to' (Target) tags: Set; + // Set of tags before 'since' (Compare) + compareTags: Set; + // Map of project IDs to info text and/or details modInfoList: Map; @@ -59,6 +62,7 @@ export default class ChangelogData { this.combineList = new Map(); this.tags = new Set(await getTags(this.to)); + this.compareTags = new Set(await getTags(this.since)); this.modInfoList = new Map(); } @@ -79,8 +83,9 @@ export default class ChangelogData { /** * Setups the state for a iteration. Init must be called first. */ - setupIteration(compareTag: string): void { + async setupIteration(compareTag: string): Promise { this.since = compareTag; + this.compareTags = new Set(await getTags(this.since)); } /** @@ -96,6 +101,7 @@ export default class ChangelogData { this.modInfoList = new Map(); - // Tags list is fine because the `to` stays the same + // Tags list is fine because the 'to' (Target) stays the same + // Other Tags list is generated at setup } } diff --git a/tools/tasks/changelog/createChangelog.ts b/tools/tasks/changelog/createChangelog.ts index 00ab85a..29ef9e4 100644 --- a/tools/tasks/changelog/createChangelog.ts +++ b/tools/tasks/changelog/createChangelog.ts @@ -27,7 +27,7 @@ async function createChangelog(): Promise { for (const tag of tags) { const iteration = tags.indexOf(tag); log(`Iteration ${iteration + 1} of Changelog.`); - data.setupIteration(tag); + await data.setupIteration(tag); categoriesSetup(); specialParserSetup(data); diff --git a/tools/tasks/changelog/definitions.ts b/tools/tasks/changelog/definitions.ts index a05e954..8bbc9d5 100644 --- a/tools/tasks/changelog/definitions.ts +++ b/tools/tasks/changelog/definitions.ts @@ -31,6 +31,7 @@ export const fixUpList = "fixes"; export const ignoreKey = "[IGNORE]"; export const modInfoKey = "[MOD INFO]"; export const modInfoList = "infos"; +export const priorityKey = "[PRIORITY]"; /* Sub Category Keys */ // Mode Category Keys @@ -227,8 +228,10 @@ export const modChangesAllocations: Record // Ignore Allocations /* Ignore Checks */ -const beforeCheck: IgnoreCheck = (tag, data) => !data.tags.has(tag); -const afterCheck: IgnoreCheck = (tag, data) => data.tags.has(tag); +const targetBeforeCheck: IgnoreCheck = (tag, data) => !data.tags.has(tag); +const targetAfterCheck: IgnoreCheck = (tag, data) => data.tags.has(tag); +const compareBeforeCheck: IgnoreCheck = (tag, data) => !data.compareTags.has(tag); +const compareAfterCheck: IgnoreCheck = (tag, data) => data.compareTags.has(tag); const compareIsCheck: IgnoreCheck = (tag, data) => data.since === tag; const compareNotCheck: IgnoreCheck = (tag, data) => data.since !== tag; const targetIsCheck: IgnoreCheck = (tag, data) => data.to === tag; @@ -236,8 +239,10 @@ const targetNotCheck: IgnoreCheck = (tag, data) => data.to !== tag; /* Ignore Checks Map */ export const ignoreChecks: Record = { - before: beforeCheck, - after: afterCheck, + targetBefore: targetBeforeCheck, + targetAfter: targetAfterCheck, + compareBefore: compareBeforeCheck, + compareAfter: compareAfterCheck, compareIs: compareIsCheck, compareNot: compareNotCheck, targetIs: targetIsCheck, diff --git a/tools/tasks/changelog/parser.ts b/tools/tasks/changelog/parser.ts index c39c4bc..37526b7 100644 --- a/tools/tasks/changelog/parser.ts +++ b/tools/tasks/changelog/parser.ts @@ -8,8 +8,9 @@ import { ignoreKey, modInfoKey, noCategoryKey, + priorityKey, } from "./definitions"; -import { parseCombine, parseDetails, parseExpand, parseIgnore, parseModInfo } from "./specialParser"; +import { parseCombine, parseDetails, parseExpand, parseIgnore, parseModInfo, parsePriority } from "./specialParser"; import { getChangelog } from "../../util/util"; import ChangelogData from "./changelogData"; @@ -21,8 +22,17 @@ export default async function parseParser(data: ChangelogData, parser: Parser): if (data.commitFixes.has(commit.hash)) { const fixUpInfo = data.commitFixes.get(commit.hash); - commit.message = fixUpInfo.newTitle; - commit.body = fixUpInfo.newBody; + if (fixUpInfo.newTitle) commit.message = fixUpInfo.newTitle; + if (fixUpInfo.newBody) { + switch (fixUpInfo.mode) { + case "REPLACE": + commit.body = fixUpInfo.newBody; + break; + case "ADDITION": + commit.body = commit.body.concat(`\n\n${fixUpInfo.newBody}`); + break; + } + } } if (parser.skipCallback(commit, commit.message, commit.body)) { @@ -69,6 +79,20 @@ export async function parseCommitBody( // Only return if ignore is not undefined if (ignore) return ignore; } + + let newPriority = 0; + if (commitBody.includes(priorityKey)) { + const priority = await parsePriority(commitBody, commitObject); + + // Only set if priority is not undefined or 0 + if (priority) newPriority = priority; + } + // Copy commit if new priority (don't mess it up for other changelog messages when using expand) + if (commitObject.priority !== newPriority) { + commitObject = { ...commitObject }; + commitObject.priority = newPriority; + } + if (commitBody.includes(modInfoKey)) await parseModInfo(commitBody, commitObject); if (commitBody.includes(detailsKey)) { await parseDetails(commitMessage, commitBody, commitObject, parser); diff --git a/tools/tasks/changelog/pusher.ts b/tools/tasks/changelog/pusher.ts index 022b8de..148e531 100644 --- a/tools/tasks/changelog/pusher.ts +++ b/tools/tasks/changelog/pusher.ts @@ -146,6 +146,8 @@ function sortCommitList(list: T[], transform: (obj: T) => Commit | undefined, const dateA = new Date(commitA.date); const dateB = new Date(commitB.date); + // This is reversed, so higher priorities go on top + if (commitB.priority !== commitA.priority) return commitB.priority - commitA.priority; // This is reversed, so the newest commits go on top if (dateB.getTime() - dateA.getTime() !== 0) return dateB.getTime() - dateA.getTime(); if (backup) return backup(a, b); @@ -162,7 +164,9 @@ export function sortCommitListReverse(list: Commit[]): void { const dateA = new Date(a.date); const dateB = new Date(b.date); - if (dateB.getTime() - dateA.getTime() !== 0) return dateA.getTime() - dateB.getTime(); + // This is reversed, so higher priorities go on top + if (b.priority !== a.priority) return b.priority - a.priority; // Priority is still highest first + if (dateA.getTime() - dateB.getTime() !== 0) return dateA.getTime() - dateB.getTime(); return a.message.localeCompare(b.message); }); } diff --git a/tools/tasks/changelog/specialParser.ts b/tools/tasks/changelog/specialParser.ts index 25f9e59..48edbcf 100644 --- a/tools/tasks/changelog/specialParser.ts +++ b/tools/tasks/changelog/specialParser.ts @@ -9,10 +9,10 @@ import { ModInfo, ParsedModInfo, Parser, + PriorityInfo, } from "../../types/changelogTypes"; import dedent from "dedent-js"; import matter, { GrayMatterFile } from "gray-matter"; -import toml from "@iarna/toml"; import { combineKey, combineList, @@ -31,10 +31,12 @@ import { indentationLevel, modInfoKey, modInfoList, + priorityKey, } from "./definitions"; import { findCategories, findSubCategory } from "./parser"; import ChangelogData from "./changelogData"; import { error } from "fancy-log"; +import { parse } from "toml-v1"; let data: ChangelogData; @@ -42,6 +44,27 @@ export function specialParserSetup(inputData: ChangelogData): void { data = inputData; } +/** + * Reads a commit's priority. + */ +export async function parsePriority(commitBody: string, commitObject: Commit): Promise { + if (!commitBody.includes(priorityKey)) return undefined; + const info = await parseTOML(commitBody, commitObject, priorityKey); + if (!info) return undefined; + + if (!info.priority) { + error(dedent` + Priority Info in body: + \`\`\` + ${commitBody}\`\`\` + of commit object ${commitObject.hash} (${commitObject.message}) is missing priority info (key 'priority').`); + if (data.isTest) throw new Error("Failed to Parse Priority Info. See Above."); + return undefined; + } + + return info.priority; +} + /** * Checks a commit's ignore. * @commit The Commit Body. Does check whether the ignore key is there. @@ -58,6 +81,7 @@ export async function parseIgnore(commitBody: string, commitObject: Commit): Pro \`\`\` ${commitBody}\`\`\` of commit object ${commitObject.hash} (${commitObject.message}) is missing check info (key 'checks').`); + if (data.isTest) throw new Error("Failed to Parse Ignore Info. See Above."); return undefined; } @@ -135,8 +159,9 @@ export async function parseFixUp(commit: Commit): Promise { commit, fixUpKey, fixUpList, - (item) => !item.sha || !item.newTitle, + (item) => !item.sha || (!item.newTitle && !item.newBody), async (item) => { + if (!item.mode) item.mode = "REPLACE"; // Default Mode is Replace (Legacy Compat) // Only override if no other overrides, from newer commits, set if (!data.commitFixes.has(item.sha)) data.commitFixes.set(item.sha, item); }, @@ -145,6 +170,7 @@ export async function parseFixUp(commit: Commit): Promise { // Must override, even if newer commits specified changes, as need to remove fixup data data.commitFixes.set(commit.hash, { sha: commit.hash, + mode: "REPLACE", newTitle: commit.message, // Replace "\r\n" (Caused by editing on GitHub) with "\n", as the output matter has this done. newBody: commit.body.replace(/\r\n/g, "\n").replace(matter.matter.trim(), ""), @@ -205,8 +231,9 @@ export async function parseExpand(commitBody: string, commitObject: Commit, pars commitObject, expandKey, expandList, - (item) => !item.messageTitle, + (item) => !item.messageTitle && !item.messageBody, async (item) => { + if (!item.messageTitle) item.messageTitle = commitObject.message; const title = dedent(item.messageTitle); if (item.messageBody) { @@ -263,18 +290,26 @@ async function expandDetailsLevel( indentation = indentationLevel, ): Promise { const result: ChangelogMessage[] = []; - await parseTOMLWithRootToList( + await parseTOMLWithRootToList( commitBody, commitObject, detailsKey, detailsList, (item) => !item, async (item) => { - item = dedent(item).trim(); - if (item.includes(detailsKey)) { - result.push(...(await expandDetailsLevel(item, commitObject, `${indentation}${indentationLevel}`))); + // Nested Details + if (Array.isArray(item)) { + await addDetailsLevel(commitBody, commitObject, item as unknown[], `${indentation}${indentationLevel}`, result); + return; + } + let string = item as string; + string = dedent(string).trim(); + + // Legacy Nested Details + if (string.includes(detailsKey)) { + result.push(...(await expandDetailsLevel(string, commitObject, `${indentation}${indentationLevel}`))); } else { - result.push({ commitMessage: item, commitObject: commitObject, indentation: indentation }); + result.push({ commitMessage: string, commitObject: commitObject, indentation: indentation }); } }, (root) => root[detailsRoot] as string, @@ -282,6 +317,67 @@ async function expandDetailsLevel( return result; } +/** + * Adds Levels of Details through Arrays. + */ +async function addDetailsLevel( + commitBody: string, + commitObject: Commit, + details: unknown[], + indentation: string, + builder: ChangelogMessage[], +) { + const endMessage = getEndMessage(detailsKey); + for (const detail of details) { + // Nested Details + if (Array.isArray(detail)) { + await addDetailsLevel( + commitBody, + commitObject, + detail as unknown[], + `${indentation}${indentationLevel}`, + builder, + ); + continue; + } + + // Transform into String + let detailString: string; + if (typeof detail !== "string") { + try { + detailString = detail.toString(); + } catch (e) { + error(dedent` + Failed parsing Detail \`${detail}\` of Details Level: + \`\`\` + ${details}\`\`\` + of commit object ${commitObject.hash} (${commitObject.message}). + The value could not be converted into a string.`); + + if (commitObject.body && commitBody !== commitObject.body) { + error(dedent` + Original Body: + \`\`\` + ${commitObject.body}\`\`\``); + } + + error(`\n${endMessage}\n`); + if (data.isTest) throw e; + continue; + } + } else detailString = detail as string; + + detailString = dedent(detailString).trim(); + + // Legacy Nested Details + if (detailString.includes(detailsKey)) { + builder.push(...(await expandDetailsLevel(detailString, commitObject, `${indentation}${indentationLevel}`))); + } else { + builder.push({ commitMessage: detailString, commitObject: commitObject, indentation: indentation }); + } + } +} + /** * Parses a commit with 'combine'. */ @@ -331,7 +427,7 @@ async function parseTOML( delimiters: delimiter, engines: { toml: (input): Record => { - return toml.parse(input); + return parse(input) as Record; }, }, language: "toml", @@ -473,7 +569,7 @@ async function parseTOMLWithRootToList( } // No Valid Entry error(dedent` - Missing Requirements for root entry, & no list with list key ${listKey} detected in body: + Missing Requirements for root entry, & no list with list key '${listKey}' detected in body: \`\`\` ${commitBody}\`\`\` of commit object ${commitObject.hash} (${commitObject.message}).`); @@ -560,10 +656,9 @@ async function parseTOMLWithRootToList( } function getEndMessage(delimiter: string) { - if (data.isTest) { - return dedent` - Try checking the TOML syntax in https://www.toml-lint.com/, checking the object tree in https://www.convertsimple.com/convert-toml-to-json/, checking syntax in https://toml.io/en/v1.0.0, and looking through https://github.com/Nomi-CEu/Nomi-CEu/blob/main/CONTRIBUTING.md! + const normal = dedent` + Try checking the TOML syntax in https://www.toml-lint.com/, checking the object tree in https://www.convertsimple.com/convert-toml-to-json/, checking syntax in https://toml.io/en/v1.0.0, and looking through https://github.com/Nomi-CEu/Nomi-CEu/wiki/Part-2:-Maintainer-Information#62-create-changelog! Also check that you have surrounded the TOML in '${delimiter}'!`; - } - return "Skipping..."; + if (data.isTest) return normal; + return normal.concat("\nSkipping..."); } diff --git a/tools/types/changelogTypes.ts b/tools/types/changelogTypes.ts index 0337e7a..4bad55e 100644 --- a/tools/types/changelogTypes.ts +++ b/tools/types/changelogTypes.ts @@ -8,6 +8,7 @@ export interface Commit { body: string; author_name: string; author_email: string; + priority?: number; } /** @@ -256,8 +257,9 @@ export interface ExpandedMessage { export interface FixUpInfo { sha: string; - newTitle: string; + newTitle?: string; newBody?: string; + mode: FixUpMode; } export interface ModInfo { @@ -272,6 +274,12 @@ export interface ParsedModInfo { details?: ChangelogMessage[]; } +export interface PriorityInfo { + priority: number; +} + +export type FixUpMode = "REPLACE" | "ADDITION"; + export type InputReleaseType = "Release" | "Beta Release" | "Alpha Release" | "Cutting Edge Build"; export interface DeployReleaseType {