parent
0f980518c4
commit
170464b795
@ -6,7 +6,7 @@ import {
|
||||
Ignored,
|
||||
IgnoreLogic,
|
||||
Parser,
|
||||
SubCategory
|
||||
SubCategory,
|
||||
} from "../../types/changelogTypes";
|
||||
import { modpackManifest } from "../../globals";
|
||||
import { parseCommitBody } from "./parser";
|
||||
|
@ -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<void> {
|
||||
pushTitle(inputData);
|
||||
@ -41,12 +42,15 @@ export function pushTitle(inputData: ChangelogData): void {
|
||||
export async function pushChangelog(inputData: ChangelogData): Promise<void> {
|
||||
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<string>[] = [];
|
||||
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<string> {
|
||||
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<string> {
|
||||
if (!octokit) return message;
|
||||
|
||||
const promises: Promise<string>[] = [];
|
||||
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<string> {
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user