diff --git a/tools/tasks/changelog/definitions.ts b/tools/tasks/changelog/definitions.ts index c2be497..b7d6e9b 100644 --- a/tools/tasks/changelog/definitions.ts +++ b/tools/tasks/changelog/definitions.ts @@ -6,7 +6,7 @@ import { Ignored, IgnoreLogic, Parser, - SubCategory + SubCategory, } from "../../types/changelogTypes"; import { modpackManifest } from "../../globals"; import { parseCommitBody } from "./parser"; diff --git a/tools/tasks/changelog/pusher.ts b/tools/tasks/changelog/pusher.ts index 148e531..3013b52 100644 --- a/tools/tasks/changelog/pusher.ts +++ b/tools/tasks/changelog/pusher.ts @@ -3,10 +3,11 @@ import { categories, defaultIndentation } from "./definitions"; import { Category, ChangelogMessage, Commit } from "../../types/changelogTypes"; import { repoLink } from "./definitions"; import { Octokit } from "@octokit/rest"; -import { getIssueURL, getNewestIssueURLs } from "../../util/util"; +import { getIssueURL, getNewestIssueURLs, isEnvVariableSet } from "../../util/util"; +import log from "fancy-log"; let data: ChangelogData; -let octokit: Octokit; +let octokit: Octokit | undefined; export default async function pushAll(inputData: ChangelogData): Promise { pushTitle(inputData); @@ -41,12 +42,15 @@ export function pushTitle(inputData: ChangelogData): void { export async function pushChangelog(inputData: ChangelogData): Promise { data = inputData; - octokit = new Octokit({ - auth: process.env.GITHUB_TOKEN, - }); + if (isEnvVariableSet("GITHUB_TOKEN")) { + octokit = new Octokit({ + auth: process.env.GITHUB_TOKEN, + }); + } // Save Issue/PR Info to Cache - await getNewestIssueURLs(octokit); + if (octokit) await getNewestIssueURLs(octokit); + else log("Skipping Transforming Issue/PR URLs! 'GITHUB_TOKEN' Not Set!"); data.builder.push(`# Changes Since ${data.since}`, ""); @@ -119,6 +123,16 @@ async function pushCategory(category: Category) { hasValues = true; } } + const promises: Promise[] = []; + for (let i = 0; i < categoryLog.length; i++) { + const categoryFormatted = categoryLog[i]; + // Transform PR and/or Issue tags into a link. + promises.push( + transformTags(categoryFormatted).then((categoryTransformed) => (categoryLog[i] = categoryTransformed)), + ); + } + // Apply all Link Changes + await Promise.all(promises); if (hasValues) { // Push Title data.builder.push(`## ${category.categoryName}:`); @@ -179,10 +193,7 @@ export function sortCommitListReverse(list: Commit[]): void { */ async function formatChangelogMessage(changelogMessage: ChangelogMessage, subMessage = false): Promise { const indentation = changelogMessage.indentation == undefined ? defaultIndentation : changelogMessage.indentation; - let message = changelogMessage.commitMessage.trim(); - - // Transform PR and/or Issue tags into a link. - message = await transformTags(message); + const message = changelogMessage.commitMessage.trim(); if (changelogMessage.specialFormatting) return changelogMessage.specialFormatting.formatting( @@ -244,6 +255,9 @@ function formatCommit(commit: Commit): string { * Transforms PR/Issue Tags into Links. */ async function transformTags(message: string): Promise { + if (!octokit) return message; + + const promises: Promise[] = []; if (message.search(/#\d+/) !== -1) { const matched = message.match(/#\d+/g); for (const match of matched) { @@ -251,11 +265,11 @@ async function transformTags(message: string): Promise { const digits = Number.parseInt(match.match(/\d+/)[0]); // Get PR/Issue Info (PRs are listed in the Issue API Endpoint) - const url = await getIssueURL(digits, octokit); - if (url) { - message = message.replace(match, `[#${digits}](${url})`); - } + promises.push(getIssueURL(digits, octokit).then((url) => message.replace(match, `[#${digits}](${url})`))); } } + + // Resolve all Issue URL Replacements + await Promise.all(promises); return message; }