parent
0f980518c4
commit
170464b795
@ -6,7 +6,7 @@ import {
|
|||||||
Ignored,
|
Ignored,
|
||||||
IgnoreLogic,
|
IgnoreLogic,
|
||||||
Parser,
|
Parser,
|
||||||
SubCategory
|
SubCategory,
|
||||||
} from "../../types/changelogTypes";
|
} from "../../types/changelogTypes";
|
||||||
import { modpackManifest } from "../../globals";
|
import { modpackManifest } from "../../globals";
|
||||||
import { parseCommitBody } from "./parser";
|
import { parseCommitBody } from "./parser";
|
||||||
|
@ -3,10 +3,11 @@ import { categories, defaultIndentation } from "./definitions";
|
|||||||
import { Category, ChangelogMessage, Commit } from "../../types/changelogTypes";
|
import { Category, ChangelogMessage, Commit } from "../../types/changelogTypes";
|
||||||
import { repoLink } from "./definitions";
|
import { repoLink } from "./definitions";
|
||||||
import { Octokit } from "@octokit/rest";
|
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 data: ChangelogData;
|
||||||
let octokit: Octokit;
|
let octokit: Octokit | undefined;
|
||||||
|
|
||||||
export default async function pushAll(inputData: ChangelogData): Promise<void> {
|
export default async function pushAll(inputData: ChangelogData): Promise<void> {
|
||||||
pushTitle(inputData);
|
pushTitle(inputData);
|
||||||
@ -41,12 +42,15 @@ export function pushTitle(inputData: ChangelogData): void {
|
|||||||
export async function pushChangelog(inputData: ChangelogData): Promise<void> {
|
export async function pushChangelog(inputData: ChangelogData): Promise<void> {
|
||||||
data = inputData;
|
data = inputData;
|
||||||
|
|
||||||
|
if (isEnvVariableSet("GITHUB_TOKEN")) {
|
||||||
octokit = new Octokit({
|
octokit = new Octokit({
|
||||||
auth: process.env.GITHUB_TOKEN,
|
auth: process.env.GITHUB_TOKEN,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Save Issue/PR Info to Cache
|
// 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}`, "");
|
data.builder.push(`# Changes Since ${data.since}`, "");
|
||||||
|
|
||||||
@ -119,6 +123,16 @@ async function pushCategory(category: Category) {
|
|||||||
hasValues = true;
|
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) {
|
if (hasValues) {
|
||||||
// Push Title
|
// Push Title
|
||||||
data.builder.push(`## ${category.categoryName}:`);
|
data.builder.push(`## ${category.categoryName}:`);
|
||||||
@ -179,10 +193,7 @@ export function sortCommitListReverse(list: Commit[]): void {
|
|||||||
*/
|
*/
|
||||||
async function formatChangelogMessage(changelogMessage: ChangelogMessage, subMessage = false): Promise<string> {
|
async function formatChangelogMessage(changelogMessage: ChangelogMessage, subMessage = false): Promise<string> {
|
||||||
const indentation = changelogMessage.indentation == undefined ? defaultIndentation : changelogMessage.indentation;
|
const indentation = changelogMessage.indentation == undefined ? defaultIndentation : changelogMessage.indentation;
|
||||||
let message = changelogMessage.commitMessage.trim();
|
const message = changelogMessage.commitMessage.trim();
|
||||||
|
|
||||||
// Transform PR and/or Issue tags into a link.
|
|
||||||
message = await transformTags(message);
|
|
||||||
|
|
||||||
if (changelogMessage.specialFormatting)
|
if (changelogMessage.specialFormatting)
|
||||||
return changelogMessage.specialFormatting.formatting(
|
return changelogMessage.specialFormatting.formatting(
|
||||||
@ -244,6 +255,9 @@ function formatCommit(commit: Commit): string {
|
|||||||
* Transforms PR/Issue Tags into Links.
|
* Transforms PR/Issue Tags into Links.
|
||||||
*/
|
*/
|
||||||
async function transformTags(message: string): Promise<string> {
|
async function transformTags(message: string): Promise<string> {
|
||||||
|
if (!octokit) return message;
|
||||||
|
|
||||||
|
const promises: Promise<string>[] = [];
|
||||||
if (message.search(/#\d+/) !== -1) {
|
if (message.search(/#\d+/) !== -1) {
|
||||||
const matched = message.match(/#\d+/g);
|
const matched = message.match(/#\d+/g);
|
||||||
for (const match of matched) {
|
for (const match of matched) {
|
||||||
@ -251,11 +265,11 @@ async function transformTags(message: string): Promise<string> {
|
|||||||
const digits = Number.parseInt(match.match(/\d+/)[0]);
|
const digits = Number.parseInt(match.match(/\d+/)[0]);
|
||||||
|
|
||||||
// Get PR/Issue Info (PRs are listed in the Issue API Endpoint)
|
// Get PR/Issue Info (PRs are listed in the Issue API Endpoint)
|
||||||
const url = await getIssueURL(digits, octokit);
|
promises.push(getIssueURL(digits, octokit).then((url) => message.replace(match, `[#${digits}](${url})`)));
|
||||||
if (url) {
|
|
||||||
message = message.replace(match, `[#${digits}](${url})`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve all Issue URL Replacements
|
||||||
|
await Promise.all(promises);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user