Only Grab URL Cache Once & Fix URL Transforming on GitHub (#717)
[SKIP]
This commit is contained in:
parent
170464b795
commit
daa9508e3b
@ -9,7 +9,7 @@ import { parsers } from "./definitions";
|
||||
import parse from "./parser";
|
||||
import { specialParserSetup } from "./specialParser";
|
||||
import generateModChanges from "./generateModChanges";
|
||||
import pushAll, { pushChangelog, pushSeperator, pushTitle } from "./pusher";
|
||||
import pushAll, { pushChangelog, pushSeperator, pushSetup, pushTitle } from "./pusher";
|
||||
import log from "fancy-log";
|
||||
|
||||
/**
|
||||
@ -19,6 +19,7 @@ async function createChangelog(): Promise<ChangelogData> {
|
||||
const data: ChangelogData = new ChangelogData();
|
||||
|
||||
await data.init();
|
||||
await pushSetup();
|
||||
|
||||
// Handle Iterations
|
||||
if (data.shouldIterate()) {
|
||||
|
@ -3,17 +3,25 @@ import { categories, defaultIndentation } from "./definitions";
|
||||
import { Category, ChangelogMessage, Commit } from "../../types/changelogTypes";
|
||||
import { repoLink } from "./definitions";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { getIssueURL, getNewestIssueURLs, isEnvVariableSet } from "../../util/util";
|
||||
import log from "fancy-log";
|
||||
import { getIssueURL, getNewestIssueURLs } from "../../util/util";
|
||||
|
||||
let data: ChangelogData;
|
||||
let octokit: Octokit | undefined;
|
||||
let octokit: Octokit;
|
||||
|
||||
export default async function pushAll(inputData: ChangelogData): Promise<void> {
|
||||
pushTitle(inputData);
|
||||
await pushChangelog(inputData);
|
||||
}
|
||||
|
||||
export async function pushSetup(): Promise<void> {
|
||||
octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
|
||||
// Save Issue/PR Info to Cache
|
||||
await getNewestIssueURLs(octokit);
|
||||
}
|
||||
|
||||
export function pushTitle(inputData: ChangelogData): void {
|
||||
data = inputData;
|
||||
|
||||
@ -42,16 +50,6 @@ export function pushTitle(inputData: ChangelogData): void {
|
||||
export async function pushChangelog(inputData: ChangelogData): Promise<void> {
|
||||
data = inputData;
|
||||
|
||||
if (isEnvVariableSet("GITHUB_TOKEN")) {
|
||||
octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
}
|
||||
|
||||
// Save Issue/PR Info to Cache
|
||||
if (octokit) await getNewestIssueURLs(octokit);
|
||||
else log("Skipping Transforming Issue/PR URLs! 'GITHUB_TOKEN' Not Set!");
|
||||
|
||||
data.builder.push(`# Changes Since ${data.since}`, "");
|
||||
|
||||
// Push Sections of Changelog
|
||||
@ -123,16 +121,7 @@ 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);
|
||||
await transformAllIssueURLs(categoryLog);
|
||||
if (hasValues) {
|
||||
// Push Title
|
||||
data.builder.push(`## ${category.categoryName}:`);
|
||||
@ -251,12 +240,25 @@ function formatCommit(commit: Commit): string {
|
||||
return `* [\`${shortSHA}\`](${repoLink}commit/${commit.hash}): ${formattedCommit}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms PR/Issue Tags in all strings of the generated changelog.
|
||||
* @param changelog The list to transform all PR/Issue Tags of.
|
||||
*/
|
||||
async function transformAllIssueURLs(changelog: string[]) {
|
||||
const promises: Promise<string>[] = [];
|
||||
for (let i = 0; i < changelog.length; i++) {
|
||||
const categoryFormatted = changelog[i];
|
||||
// Transform PR and/or Issue tags into a link.
|
||||
promises.push(transformTags(categoryFormatted).then((categoryTransformed) => (changelog[i] = categoryTransformed)));
|
||||
}
|
||||
// Apply all Link Changes
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user