mirror of
https://github.com/darksaid98/auto-changelog.git
synced 2026-12-02 22:16:06 +00:00
refactor: improve changelog logic (#197)
* refactor: improve changelog logic Signed-off-by: Ardalan Amini <[email protected]> * chore: update license comment formatting across all files Replaced `/*` with `/**` for correct JSDoc-style license comments in all files. This ensures consistency and compatibility with documentation tools that rely on JSDoc conventions. Signed-off-by: Ardalan Amini <[email protected]> * test: add unit tests for inputs Signed-off-by: Ardalan Amini <[email protected]> * test: add unit tests for utils Signed-off-by: Ardalan Amini <[email protected]> * test: add unit tests for outputs Signed-off-by: Ardalan Amini <[email protected]> * test: add unit tests for nodes Signed-off-by: Ardalan Amini <[email protected]> * test: add missing unit tests Signed-off-by: Ardalan Amini <[email protected]> * chore: address PR comments Signed-off-by: Ardalan Amini <[email protected]> * chore: address PR comments Signed-off-by: Ardalan Amini <[email protected]> --------- Signed-off-by: Ardalan Amini <[email protected]>
This commit is contained in:
1 parent
3c1177539c
commit
9bd6b8698c
95 files changed
+4381
-302
No files matched your search
+21
-168
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2025 Ardalan Amini
|
||||
@@ -20,193 +20,46 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { debug } from "@actions/core";
|
||||
import {
|
||||
commitTypes,
|
||||
defaultCommitType,
|
||||
includeCommitLinks,
|
||||
includePRLinks,
|
||||
mentionAuthors,
|
||||
octokit,
|
||||
parseCommitMessage,
|
||||
repository,
|
||||
sha,
|
||||
useGithubAutolink,
|
||||
} from "./utils/index.js";
|
||||
|
||||
interface TypeGroupI {
|
||||
scopes: ScopeGroupI[];
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface ScopeGroupI {
|
||||
logs: LogI[];
|
||||
scope: string;
|
||||
}
|
||||
|
||||
interface LogI {
|
||||
breaking: boolean;
|
||||
description: string;
|
||||
references: string[];
|
||||
}
|
||||
|
||||
function trim<T extends string | undefined>(value: T): T {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (value == null) return value;
|
||||
|
||||
return value.trim().replace(/ {2,}/g, " ") as never;
|
||||
}
|
||||
|
||||
function unique(value: string[]): string[] {
|
||||
return [...new Set(value)];
|
||||
}
|
||||
|
||||
function sortBy<T>(array: T[], property: keyof T): T[] {
|
||||
return array.sort((a, b) => (a[property] as string).localeCompare(b[property] as string));
|
||||
}
|
||||
import { ChangelogNode } from "./nodes/index.js";
|
||||
import { iterateCommits, parseCommitMessage, repository, trim } from "./utils/index.js";
|
||||
|
||||
export async function generateChangelog(lastSha?: string): Promise<string> {
|
||||
const { paginate, rest } = octokit();
|
||||
const { owner, repo, url } = repository();
|
||||
const defaultType = defaultCommitType();
|
||||
const typeMap = commitTypes();
|
||||
const shouldIncludePRLinks = includePRLinks();
|
||||
const shouldIncludeCommitLinks = includeCommitLinks();
|
||||
const shouldMentionAuthors = mentionAuthors();
|
||||
const shouldUseGithubAutolink = useGithubAutolink();
|
||||
const { owner, repo } = repository();
|
||||
|
||||
const iterator = paginate.iterator(
|
||||
rest.repos.listCommits,
|
||||
{
|
||||
per_page: 100,
|
||||
sha : sha(),
|
||||
owner,
|
||||
repo,
|
||||
},
|
||||
);
|
||||
const changelogNode = (new ChangelogNode);
|
||||
|
||||
const typeGroups: TypeGroupI[] = [];
|
||||
for await (const commit of iterateCommits(owner, repo, lastSha)) {
|
||||
const message = commit.commit.message.split("\n")[0];
|
||||
|
||||
paginator: for await (const { data } of iterator) {
|
||||
for (const commit of data) {
|
||||
if (commit.sha === lastSha) break paginator;
|
||||
debug(`commit message -> ${ message }`);
|
||||
|
||||
const message = commit.commit.message.split("\n")[0];
|
||||
let { type, scope, description, pr, flag, breaking } = parseCommitMessage(message);
|
||||
|
||||
debug(`commit message -> ${ message }`);
|
||||
description = trim(description);
|
||||
|
||||
let { type, scope, description, pr, flag, breaking } = parseCommitMessage(message);
|
||||
if (!description) continue;
|
||||
|
||||
if (!description) continue;
|
||||
flag = trim(flag);
|
||||
|
||||
description = trim(description);
|
||||
if (flag === "ignore") continue;
|
||||
|
||||
flag = trim(flag);
|
||||
const typeNode = changelogNode.addType(type);
|
||||
|
||||
if (flag === "ignore") continue;
|
||||
const scopeNode = typeNode.addScope(scope);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
type = typeMap[trim(type ?? "")] ?? defaultType;
|
||||
const commitNote = scopeNode.addCommit(description, breaking);
|
||||
|
||||
let typeGroup = typeGroups.find(record => record.type === type);
|
||||
const authorNode = commitNote.addAuthor(commit.author?.login);
|
||||
|
||||
if (typeGroup == null) {
|
||||
typeGroup = {
|
||||
type,
|
||||
scopes: [],
|
||||
};
|
||||
|
||||
typeGroups.push(typeGroup);
|
||||
}
|
||||
|
||||
scope = trim(scope ?? "");
|
||||
|
||||
let scopeGroup = typeGroup.scopes.find(record => record.scope === scope);
|
||||
|
||||
if (scopeGroup == null) {
|
||||
scopeGroup = {
|
||||
scope,
|
||||
logs: [],
|
||||
};
|
||||
|
||||
typeGroup.scopes.push(scopeGroup);
|
||||
}
|
||||
|
||||
let log = scopeGroup.logs.find(record => record.description === description);
|
||||
|
||||
if (log == null) {
|
||||
log = {
|
||||
breaking,
|
||||
description,
|
||||
references: [],
|
||||
};
|
||||
|
||||
scopeGroup.logs.push(log);
|
||||
}
|
||||
|
||||
const reference: string[] = [];
|
||||
|
||||
if (pr && shouldIncludePRLinks) reference.push(shouldUseGithubAutolink ? `#${ pr }` : `[#${ pr }](${ url }/issues/${ pr })`);
|
||||
else if (shouldIncludeCommitLinks) reference.push(shouldUseGithubAutolink ? commit.sha : `\`[${ commit.sha }](${ url }/commit/${ commit.sha })\``);
|
||||
|
||||
const username = commit.author?.login;
|
||||
|
||||
if (username && shouldMentionAuthors) {
|
||||
const mention = `by @${ username }`;
|
||||
|
||||
reference.push(mention);
|
||||
|
||||
const lastReference = log.references[log.references.length - 1];
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (lastReference?.endsWith(mention)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
log.references.push(log.references.pop()!.replace(mention, `& ${ reference.join(" ") }`));
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (reference.length > 0) log.references.push(reference.join(" "));
|
||||
}
|
||||
authorNode.addReference(commit.sha, pr);
|
||||
}
|
||||
|
||||
const types = unique(Object.values(typeMap).concat(defaultType));
|
||||
const changelog = changelogNode.print();
|
||||
|
||||
const changelog: string[] = [];
|
||||
if (changelog) return `${ changelog }\n`;
|
||||
|
||||
for (const type of types) {
|
||||
const typeGroup = typeGroups.find(log => log.type === type);
|
||||
|
||||
if (typeGroup == null) continue;
|
||||
|
||||
changelog.push(`## ${ type }`);
|
||||
|
||||
sortBy(typeGroup.scopes, "scope");
|
||||
|
||||
for (const { scope, logs } of typeGroup.scopes) {
|
||||
let prefix = "";
|
||||
|
||||
if (scope.length > 0) {
|
||||
changelog.push(`* **${ scope }:**`);
|
||||
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
for (const { breaking, description, references } of logs) {
|
||||
let line = `${ prefix }* ${ breaking ? "***breaking:*** " : "" }${ description }`;
|
||||
|
||||
if (references.length > 0) line += ` (${ references.join(", ") })`;
|
||||
|
||||
changelog.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
changelog.push("");
|
||||
}
|
||||
|
||||
return changelog.join("\n");
|
||||
return "";
|
||||
}
|
||||
+5
-8
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2025 Ardalan Amini
|
||||
@@ -20,19 +20,17 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { marked } from "marked";
|
||||
import {
|
||||
includeCompareLink,
|
||||
mentionNewContributors,
|
||||
octokit,
|
||||
releaseName,
|
||||
releaseNamePrefix,
|
||||
repository,
|
||||
useGithubAutolink,
|
||||
} from "./utils/index.js";
|
||||
useGitHubAutolink,
|
||||
} from "./inputs/index.js";
|
||||
import { octokit, repository } from "./utils/index.js";
|
||||
|
||||
export async function generateFooter(previousTagName?: string): Promise<string> {
|
||||
const { owner, repo, url } = repository();
|
||||
@@ -40,7 +38,6 @@ export async function generateFooter(previousTagName?: string): Promise<string>
|
||||
|
||||
const footer: string[] = [];
|
||||
|
||||
|
||||
if (mentionNewContributors()) {
|
||||
const { rest } = octokit();
|
||||
|
||||
@@ -64,7 +61,7 @@ export async function generateFooter(previousTagName?: string): Promise<string>
|
||||
if (includeCompareLink() && previousTagName) {
|
||||
let link = `${ url }/compare/${ previousTagName }...${ tagName }`;
|
||||
|
||||
if (!useGithubAutolink() || releaseNamePrefix()) link = `\`[${ previousTagName }...${ tagName }](${ url }/compare/${ previousTagName }...${ tagName })\``;
|
||||
if (!useGitHubAutolink() || releaseNamePrefix()) link = `\`[${ previousTagName }...${ tagName }](${ url }/compare/${ previousTagName }...${ tagName })\``;
|
||||
|
||||
footer.push(`**Full Changelog**: ${ link }`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { generateChangelog } from "./changelog.js";
|
||||
import { generateFooter } from "./footer.js";
|
||||
import { setChangelog, setPrerelease, setReleaseId } from "./outputs/index.js";
|
||||
import { getTagInfo } from "./tag.js";
|
||||
|
||||
export async function generate(): Promise<void> {
|
||||
const { prerelease, releaseId, previous } = await getTagInfo();
|
||||
|
||||
setPrerelease(prerelease);
|
||||
|
||||
setReleaseId(releaseId);
|
||||
|
||||
let changelog = await generateChangelog(previous?.sha);
|
||||
|
||||
changelog += await generateFooter(previous?.name);
|
||||
|
||||
setChangelog(changelog);
|
||||
}
|
||||
+5
-21
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2025 Ardalan Amini
|
||||
@@ -20,27 +20,11 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
/* istanbul ignore file */
|
||||
|
||||
import { setFailed } from "@actions/core";
|
||||
import { generateChangelog } from "./changelog.js";
|
||||
import { generateFooter } from "./footer.js";
|
||||
import { getTagInfo } from "./tag.js";
|
||||
import { setChangelog, setPrerelease, setReleaseId } from "./utils/index.js";
|
||||
import { generate } from "./generate.js";
|
||||
|
||||
async function run(): Promise<void> {
|
||||
const { prerelease, releaseId, previous } = await getTagInfo();
|
||||
|
||||
setPrerelease(prerelease);
|
||||
|
||||
setReleaseId(releaseId);
|
||||
|
||||
let changelog = await generateChangelog(previous?.sha);
|
||||
|
||||
changelog += await generateFooter(previous?.name);
|
||||
|
||||
setChangelog(changelog);
|
||||
}
|
||||
|
||||
run().catch(setFailed);
|
||||
generate().catch(setFailed);
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,11 +20,10 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import YAML from "yaml";
|
||||
import { input } from "../input.js";
|
||||
import { input } from "../utils/input.js";
|
||||
|
||||
export function commitTypes(): Record<string, string> {
|
||||
return input("commit-types", value => YAML.parse(value));
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { input } from "../input.js";
|
||||
import { input } from "../utils/input.js";
|
||||
|
||||
export function defaultCommitType(): string {
|
||||
return input("default-commit-type");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,11 +20,10 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { input } from "../input.js";
|
||||
import { input } from "../utils/input.js";
|
||||
|
||||
export function token(): string {
|
||||
export function gitHubToken(): string {
|
||||
return input("github-token");
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function includeCommitLinks(): boolean {
|
||||
return booleanInput("include-commit-links");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function includeCompareLink(): boolean {
|
||||
return booleanInput("include-compare-link");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function includePRLinks(): boolean {
|
||||
return booleanInput("include-pr-links");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,11 +20,11 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
export * from "./commit-types.js";
|
||||
export * from "./default-commit-type.js";
|
||||
export * from "./github-token.js";
|
||||
export * from "./include-compare-link.js";
|
||||
export * from "./include-commit-links.js";
|
||||
export * from "./include-pr-links.js";
|
||||
@@ -33,5 +33,4 @@ export * from "./mention-new-contributors.js";
|
||||
export * from "./release-name.js";
|
||||
export * from "./release-name-prefix.js";
|
||||
export * from "./semver.js";
|
||||
export * from "./token.js";
|
||||
export * from "./use-github-autolink.js";
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function mentionAuthors(): boolean {
|
||||
return booleanInput("mention-authors");
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function mentionNewContributors(): boolean {
|
||||
return booleanInput("mention-new-contributors");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,11 +20,10 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { input } from "../input.js";
|
||||
import { input } from "../utils/input.js";
|
||||
|
||||
export function releaseNamePrefix(): string {
|
||||
return input("release-name-prefix", value => value || "", false);
|
||||
return input("release-name-prefix", false);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { input } from "../input.js";
|
||||
import { input } from "../utils/input.js";
|
||||
|
||||
export function releaseName(): string {
|
||||
return input("release-name");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function semver(): boolean {
|
||||
return booleanInput("semver");
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,11 +20,10 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { booleanInput } from "../boolean-input.js";
|
||||
import { booleanInput } from "../utils/boolean-input.js";
|
||||
|
||||
export function useGithubAutolink(): boolean {
|
||||
export function useGitHubAutolink(): boolean {
|
||||
return booleanInput("use-github-autolink");
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { commitTypes, defaultCommitType } from "../inputs/index.js";
|
||||
import { trim } from "../utils/index.js";
|
||||
import { Node } from "./node.js";
|
||||
import { TypeNode } from "./type.js";
|
||||
|
||||
/**
|
||||
* Represents a changelog node which organizes and processes commit types into structured changelog entries.
|
||||
* This class manages the mapping of commit types to their human-readable counterparts, aggregates commit
|
||||
* types into groups, and generates a formatted output.
|
||||
*/
|
||||
export class ChangelogNode extends Node {
|
||||
|
||||
public readonly defaultType = defaultCommitType();
|
||||
|
||||
public readonly typeMap = commitTypes();
|
||||
|
||||
protected readonly types = (new Map<string, TypeNode>);
|
||||
|
||||
/**
|
||||
* Adds a new type or retrieves an existing one from the already added types.
|
||||
* If the input `type` is not found in the type map, the default type is assigned.
|
||||
*
|
||||
* @param [type=""] - The commit type to be mapped and added.
|
||||
* @returns The corresponding type node that represents the added or existing type.
|
||||
*/
|
||||
public addType(type = ""): TypeNode {
|
||||
const { types, typeMap, defaultType } = this;
|
||||
|
||||
// Map the commit type to the human-readable changelog type.
|
||||
type = typeMap[trim(type)] ?? defaultType;
|
||||
|
||||
// Reusing the already added type to group the commits.
|
||||
if (types.has(type)) return types.get(type)!;
|
||||
|
||||
const typeNode = new TypeNode(type);
|
||||
|
||||
types.set(type, typeNode);
|
||||
|
||||
return typeNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles and concatenates the output of all accepted types into a single string, prefixed by the provided prefix.
|
||||
*
|
||||
* @param [prefix=""] - A string that is prefixed to each type's printed output.
|
||||
* @returns A concatenated string of all printed types with the applied prefix, or null if no types are available.
|
||||
*/
|
||||
public print(prefix = ""): string | null {
|
||||
const { types } = this;
|
||||
|
||||
if (types.size === 0) return null;
|
||||
|
||||
/**
|
||||
* Using this instead of iterating over the `types` values allows the action users to apply their own custom order.
|
||||
*/
|
||||
const acceptedTypes = [...new Set(Object.values(this.typeMap).concat(this.defaultType))];
|
||||
|
||||
const parts: string[] = [];
|
||||
|
||||
for (const key of acceptedTypes) {
|
||||
const type = types.get(key);
|
||||
|
||||
if (!type) continue;
|
||||
|
||||
const printedType = type.print(prefix);
|
||||
|
||||
if (printedType) parts.push(printedType);
|
||||
}
|
||||
|
||||
if (parts.length === 0) return null;
|
||||
|
||||
// Joined by 2 new lines to have one empty line between each type group.
|
||||
return parts.join("\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { mentionAuthors } from "../inputs/index.js";
|
||||
import { CommitHashNode } from "./commit-hash.js";
|
||||
import { Node } from "./node.js";
|
||||
import { PullRequestNode } from "./pull-request.js";
|
||||
|
||||
/**
|
||||
* Represents a node for a commit author, containing information about the author
|
||||
* and associated references to commits or pull requests.
|
||||
*/
|
||||
export class CommitAuthorNode extends Node {
|
||||
|
||||
public readonly shouldMentionAuthor = mentionAuthors();
|
||||
|
||||
protected readonly references: Array<CommitHashNode | PullRequestNode> = [];
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the commit author node with an optional username.
|
||||
*
|
||||
* @param [username] - The commit author username.
|
||||
*/
|
||||
public constructor(public readonly username?: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a reference to either a pull request or a commit hash.
|
||||
* If a pull request is provided, it takes priority over the commit hash.
|
||||
*
|
||||
* @param sha - The SHA hash of the commit reference.
|
||||
* @param [pr] - The optional pull request identifier.
|
||||
* @returns The created reference node, either a CommitHashNode or a PullRequestNode.
|
||||
*/
|
||||
public addReference(sha: string, pr?: string): CommitHashNode | PullRequestNode {
|
||||
let reference: CommitHashNode | PullRequestNode;
|
||||
|
||||
// PR references take priority over commit hash references
|
||||
if (pr) reference = new PullRequestNode(pr);
|
||||
else reference = new CommitHashNode(sha);
|
||||
|
||||
// Check if a reference already exists to avoid duplicates
|
||||
for (const existingRef of this.references) {
|
||||
if (
|
||||
(!pr && existingRef instanceof CommitHashNode && existingRef.sha === sha)
|
||||
|| (existingRef instanceof PullRequestNode && existingRef.pr === pr)
|
||||
) return existingRef;
|
||||
}
|
||||
|
||||
this.references.push(reference);
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a formatted string representation based on references and author information.
|
||||
* It combines references and adds author mention if applicable.
|
||||
*
|
||||
* @returns The formatted string representation or null if no parts are available.
|
||||
*/
|
||||
public print(): string | null {
|
||||
const { username, references, serverUrl, shouldMentionAuthor, shouldUseGithubAutolink } = this;
|
||||
|
||||
const printedReferences: string[] = [];
|
||||
|
||||
for (const reference of references) {
|
||||
const printedReference = reference.print();
|
||||
|
||||
if (printedReference) printedReferences.push(printedReference);
|
||||
}
|
||||
|
||||
const parts: string[] = [];
|
||||
|
||||
if (printedReferences.length > 0) parts.push(printedReferences.join(" & "));
|
||||
|
||||
if (shouldMentionAuthor && username) {
|
||||
if (parts.length > 0) parts.push("by");
|
||||
|
||||
if (shouldUseGithubAutolink) parts.push(`@${ username }`);
|
||||
else parts.push(`[@${ username }](${ serverUrl }/${ username })`);
|
||||
}
|
||||
|
||||
if (parts.length === 0) return null;
|
||||
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { includeCommitLinks } from "../inputs/index.js";
|
||||
import { Node } from "./node.js";
|
||||
|
||||
/**
|
||||
* Represents a node that holds a commit hash (SHA) and provides functionality
|
||||
* for generating formatted strings or links based on its state and the repository context.
|
||||
*/
|
||||
export class CommitHashNode extends Node {
|
||||
|
||||
public readonly shouldNotPrint = !includeCommitLinks();
|
||||
|
||||
/**
|
||||
* Constructs an instance of the commit hash node with a specified SHA string.
|
||||
*
|
||||
* @param sha - The SHA string associated with this instance.
|
||||
*/
|
||||
public constructor(public readonly sha: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and returns a formatted string based on the current object state.
|
||||
* If `shouldNotPrint` is true, the method returns null.
|
||||
* If `shouldUseGithubAutolink` is true, the method directly returns the `sha` value.
|
||||
* Otherwise,
|
||||
* it returns a markdown-formatted string linking to the GitHub commit URL constructed using `sha` and `repo.url`.
|
||||
*
|
||||
* @returns A formatted string, the `sha` string, or null depending on conditions.
|
||||
*/
|
||||
public print(): string | null {
|
||||
const { sha, shouldUseGithubAutolink, repo, shouldNotPrint } = this;
|
||||
|
||||
if (shouldNotPrint) return null;
|
||||
|
||||
if (shouldUseGithubAutolink) return sha;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
||||
return `\`[${ sha.slice(0, 7) }](${ repo.url }/commit/${ sha })\``;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { CommitAuthorNode } from "./commit-author.js";
|
||||
import { Node } from "./node.js";
|
||||
|
||||
/**
|
||||
* Represents a commit node in a data structure that tracks commit information.
|
||||
* Extends the `Node` class and contains additional metadata such as description,
|
||||
* authors, and a flag indicating whether the commit introduces breaking changes.
|
||||
*/
|
||||
export class CommitNode extends Node {
|
||||
|
||||
protected readonly authors: CommitAuthorNode[] = [];
|
||||
|
||||
/**
|
||||
* Constructs an instance of the class.
|
||||
*
|
||||
* @param description - A description of the instance.
|
||||
* @param [breaking=false] - Indicates whether the instance represents a breaking change.
|
||||
*/
|
||||
public constructor(public readonly description: string, public readonly breaking = false) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new author or retrieves the previous author if the username matches the last one.
|
||||
* This optimization helps group consecutive commits by the same author efficiently.
|
||||
*
|
||||
* @param [username] - The username of the author to add.
|
||||
* @returns The added or retrieved author node instance.
|
||||
*/
|
||||
public addAuthor(username?: string): CommitAuthorNode {
|
||||
const { authors } = this;
|
||||
|
||||
// Only reuse authors with known usernames.
|
||||
if (username && authors.length > 0) {
|
||||
// Only if the last reference is to the same author, reuse the node.
|
||||
const previousAuthor = authors[authors.length - 1];
|
||||
|
||||
if (previousAuthor.username === username) return previousAuthor;
|
||||
}
|
||||
|
||||
const author = new CommitAuthorNode(username);
|
||||
|
||||
authors.push(author);
|
||||
|
||||
return author;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a formatted string representation of the commit.
|
||||
*
|
||||
* @param [prefix=""] - A string to prefix the formatted output with.
|
||||
* @returns A formatted string containing the description, authors, and a breaking indicator if applicable.
|
||||
*/
|
||||
public print(prefix = ""): string {
|
||||
const { breaking, description, authors } = this;
|
||||
|
||||
const parts: string[] = [];
|
||||
|
||||
if (breaking) parts.push("***BREAKING:***");
|
||||
|
||||
parts.push(description);
|
||||
|
||||
if (authors.length > 0) {
|
||||
const references: string[] = [];
|
||||
|
||||
for (const author of authors) {
|
||||
const printedAuthor = author.print();
|
||||
|
||||
if (printedAuthor) references.push(printedAuthor);
|
||||
}
|
||||
|
||||
if (references.length > 0) parts.push(`(${ references.join(", ") })`);
|
||||
}
|
||||
|
||||
return `${ prefix }* ${ parts.join(" ") }`;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "./changelog.js";
|
||||
export * from "./commit.js";
|
||||
export * from "./commit-author.js";
|
||||
export * from "./commit-hash.js";
|
||||
export * from "./node.js";
|
||||
export * from "./pull-request.js";
|
||||
export * from "./scope.js";
|
||||
export * from "./type.js";
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { context } from "@actions/github";
|
||||
import { useGitHubAutolink } from "../inputs/index.js";
|
||||
import { repository } from "../utils/index.js";
|
||||
|
||||
/**
|
||||
* Represents the base class for all nodes in the changelog,
|
||||
* providing shared functionality and requiring implementation of a print method.
|
||||
*/
|
||||
export abstract class Node {
|
||||
|
||||
public readonly repo = repository();
|
||||
|
||||
public readonly serverUrl = context.serverUrl;
|
||||
|
||||
public readonly shouldUseGithubAutolink = useGitHubAutolink();
|
||||
|
||||
/**
|
||||
* Outputs a string representation of the changelog node.
|
||||
*
|
||||
* @returns The string representation if available, otherwise `null` if no representation exists or is provided.
|
||||
*/
|
||||
public abstract print(): string | null;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { includePRLinks } from "../inputs/index.js";
|
||||
import { Node } from "./node.js";
|
||||
|
||||
/**
|
||||
* Represents a node associated with a pull request or issue link.
|
||||
* This class provides functionality to generate formatted links
|
||||
* for pull requests or issues based on certain conditions.
|
||||
*/
|
||||
export class PullRequestNode extends Node {
|
||||
|
||||
public readonly shouldNotPrint = !includePRLinks();
|
||||
|
||||
/**
|
||||
* Constructs an instance of the class with the specified `pr` parameter.
|
||||
*
|
||||
* @param pr - A string representing the parameter to be assigned to the instance.
|
||||
*/
|
||||
public constructor(public readonly pr: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a formatted string representing a pull request or issue link
|
||||
* based on the method's logic and class properties.
|
||||
*
|
||||
* @returns A string with the formatted pull request link or null if printing is disabled.
|
||||
*/
|
||||
public print(): string | null {
|
||||
const { pr, shouldUseGithubAutolink, repo, shouldNotPrint } = this;
|
||||
|
||||
if (shouldNotPrint) return null;
|
||||
|
||||
if (shouldUseGithubAutolink) return `#${ pr }`;
|
||||
|
||||
return `[#${ pr }](${ repo.url }/issues/${ pr })`;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { CommitNode } from "./commit.js";
|
||||
import { Node } from "./node.js";
|
||||
|
||||
/**
|
||||
* Represents a scope node within a changelog hierarchy, containing a collection of commit nodes.
|
||||
* A scope node can have an associated scope name and provides functionality to add commits
|
||||
* and generate formatted output with scope and commit details.
|
||||
*/
|
||||
export class ScopeNode extends Node {
|
||||
|
||||
protected readonly commits = (new Map<string, CommitNode>);
|
||||
|
||||
/**
|
||||
* Constructs an instance of the scope node.
|
||||
*
|
||||
* @param scope An optional string value representing the scope.
|
||||
*/
|
||||
public constructor(public readonly scope = "") {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new commit to the internal collection or retrieves an existing one if it already exists.
|
||||
*
|
||||
* @param message The message associated with the commit.
|
||||
* @param [breaking=false] Indicates whether the commit introduces breaking changes.
|
||||
* @returns The newly added or existing commit node.
|
||||
*/
|
||||
public addCommit(message: string, breaking = false): CommitNode {
|
||||
const { commits } = this;
|
||||
|
||||
const key = `${ breaking }::${ message }`;
|
||||
|
||||
if (commits.has(key)) return commits.get(key)!;
|
||||
|
||||
const commitNode = new CommitNode(message, breaking);
|
||||
|
||||
commits.set(key, commitNode);
|
||||
|
||||
return commitNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a formatted string representation of the changelog's scope and commits.
|
||||
*
|
||||
* @param [prefix=""] Optional string to prepend to each line of the output.
|
||||
* @returns A formatted string with scope and commit details, or null if there are no commits.
|
||||
*/
|
||||
public print(prefix = ""): string | null {
|
||||
const { scope, commits } = this;
|
||||
|
||||
if (commits.size === 0) return null;
|
||||
|
||||
const parts: string[] = [];
|
||||
|
||||
if (scope) {
|
||||
parts.push(`${ prefix }* **${ scope }:**`);
|
||||
|
||||
prefix += " ";
|
||||
}
|
||||
|
||||
for (const commit of commits.values()) parts.push(commit.print(prefix));
|
||||
|
||||
return parts.join("\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { trim } from "../utils/index.js";
|
||||
import { Node } from "./node.js";
|
||||
import { ScopeNode } from "./scope.js";
|
||||
|
||||
/**
|
||||
* Represents a node for a specific type that manages associated scopes.
|
||||
* Provides methods to add scopes and retrieve a formatted string representation
|
||||
* of its contents, including associated scopes and their respective commits.
|
||||
*/
|
||||
export class TypeNode extends Node {
|
||||
|
||||
protected readonly scopes = (new Map<string, ScopeNode>);
|
||||
|
||||
/**
|
||||
* Constructs an instance of type node class with a specified type.
|
||||
*
|
||||
* @param type - The commit type associated with the instance.
|
||||
*/
|
||||
public constructor(public readonly type: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new scope to the scope collection.
|
||||
* If the scope already exists,
|
||||
* the existing scope node is returned instead of creating a new one.
|
||||
*
|
||||
* @param [scope=""] - The name of the scope to be added.
|
||||
* @returns The scope node associated with the added or existing scope.
|
||||
*/
|
||||
public addScope(scope = ""): ScopeNode {
|
||||
const { scopes } = this;
|
||||
|
||||
scope = trim(scope);
|
||||
|
||||
// Reusing the already added scope to group the commits.
|
||||
if (scopes.has(scope)) return scopes.get(scope)!;
|
||||
|
||||
const scopeNode = new ScopeNode(scope);
|
||||
|
||||
scopes.set(scope, scopeNode);
|
||||
|
||||
return scopeNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the commits and their scopes grouped in this type.
|
||||
*
|
||||
* @param [prefix=""] - A prefix string to prepend to the output.
|
||||
* @returns The formatted string representation, or null if no scopes are available.
|
||||
*/
|
||||
public print(prefix = ""): string | null {
|
||||
const { type, scopes } = this;
|
||||
|
||||
if (scopes.size === 0) return null;
|
||||
|
||||
const parts: string[] = [`${ prefix }## ${ type }`];
|
||||
|
||||
/**
|
||||
* Sorting the scopes to have a consistent output order in all changelogs.
|
||||
*/
|
||||
const scopeKeys = [...scopes.keys()].sort((a, b) => a.localeCompare(b));
|
||||
|
||||
for (const key of scopeKeys) {
|
||||
const scope = scopes.get(key)!;
|
||||
|
||||
const printedScope = scope.print(prefix);
|
||||
|
||||
if (printedScope) parts.push(printedScope);
|
||||
}
|
||||
|
||||
// If only the header exists with no scope content, return null
|
||||
if (parts.length === 1) return null;
|
||||
|
||||
return parts.join("\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
export * from "./set-changelog.js";
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { output } from "../output.js";
|
||||
import { output } from "../utils/index.js";
|
||||
|
||||
export function setChangelog(changelog: string): void {
|
||||
output("changelog", changelog);
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { output } from "../output.js";
|
||||
import { output } from "../utils/index.js";
|
||||
|
||||
export function setPrerelease(prerelease: boolean): void {
|
||||
output("prerelease", prerelease);
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,10 +20,9 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { output } from "../output.js";
|
||||
import { output } from "../utils/index.js";
|
||||
|
||||
export function setReleaseId(releaseId: string): void {
|
||||
output("release-id", releaseId);
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2025 Ardalan Amini
|
||||
@@ -20,11 +20,11 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { type SemVer } from "semver";
|
||||
import { octokit, parseSemVer, releaseName, repository, semver, sha } from "./utils/index.js";
|
||||
import { releaseName, semver } from "./inputs/index.js";
|
||||
import { octokit, parseSemVer, repository, sha } from "./utils/index.js";
|
||||
|
||||
export interface TagInfoI {
|
||||
prerelease: boolean;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { getBooleanInput } from "@actions/core";
|
||||
|
||||
+6
-3
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,13 +20,16 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
const CACHE = (new Map);
|
||||
|
||||
export function cache<T>(key: string, value: () => T, overwrite = false): T {
|
||||
if (!CACHE.has(key) || overwrite) CACHE.set(key, value());
|
||||
if (overwrite || !CACHE.has(key)) CACHE.set(key, value());
|
||||
|
||||
return CACHE.get(key);
|
||||
}
|
||||
|
||||
export function clearCache(): void {
|
||||
CACHE.clear();
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
import { octokit } from "./octokit.js";
|
||||
import { sha } from "./sha.js";
|
||||
|
||||
export async function *iterateCommits(owner: string, repo: string, from?: string): AsyncGenerator<TCommit> {
|
||||
const { paginate, rest } = octokit();
|
||||
|
||||
const iterator = paginate.iterator(
|
||||
rest.repos.listCommits,
|
||||
{
|
||||
per_page: 100,
|
||||
sha : sha(),
|
||||
owner,
|
||||
repo,
|
||||
},
|
||||
);
|
||||
|
||||
loop: for await (const { data } of iterator) {
|
||||
for (const commit of data) {
|
||||
if (commit.sha === from) break loop;
|
||||
|
||||
yield commit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TCommit {
|
||||
author?: {
|
||||
login: string;
|
||||
} | null;
|
||||
|
||||
commit: {
|
||||
message: string;
|
||||
};
|
||||
|
||||
sha: string;
|
||||
}
|
||||
+3
-4
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,13 +20,11 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
export * from "./inputs/index.js";
|
||||
export * from "./outputs/index.js";
|
||||
export * from "./boolean-input.js";
|
||||
export * from "./cache.js";
|
||||
export * from "./github.js";
|
||||
export * from "./input.js";
|
||||
export * from "./octokit.js";
|
||||
export * from "./output.js";
|
||||
@@ -34,3 +32,4 @@ export * from "./parse-commit-message.js";
|
||||
export * from "./parse-semver.js";
|
||||
export * from "./repository.js";
|
||||
export * from "./sha.js";
|
||||
export * from "./trim.js";
|
||||
+17
-3
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { getInput } from "@actions/core";
|
||||
@@ -28,8 +27,23 @@ import { cache } from "./cache.js";
|
||||
|
||||
export function input<T = string>(
|
||||
name: string,
|
||||
parser: (value: string) => T = (value): T => value as T,
|
||||
required?: boolean,
|
||||
): T;
|
||||
export function input<T = string>(
|
||||
name: string,
|
||||
parser: (value: string) => T,
|
||||
required?: boolean,
|
||||
): T;
|
||||
export function input<T = string>(
|
||||
name: string,
|
||||
parser: boolean | ((value: string) => T) = (value): T => value as T,
|
||||
required = true,
|
||||
): T {
|
||||
if (typeof parser === "boolean") {
|
||||
required = parser;
|
||||
|
||||
parser = (value): T => value as T;
|
||||
}
|
||||
|
||||
return cache(name, () => parser(getInput(name, { required })));
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,14 +20,13 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { getOctokit } from "@actions/github";
|
||||
import { type GitHub } from "@actions/github/lib/utils.js";
|
||||
import { gitHubToken } from "../inputs/index.js";
|
||||
import { cache } from "./cache.js";
|
||||
import { token } from "./inputs/index.js";
|
||||
|
||||
export function octokit(): InstanceType<typeof GitHub> {
|
||||
return cache("octokit", () => getOctokit(token()));
|
||||
return cache("octokit", () => getOctokit(gitHubToken()));
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { info, setOutput } from "@actions/core";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
const REGEX = /^(?<type>[^!:() ]*)(?:\((?<scope>[^!()]*?)\)|)(?<breaking>!?): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,15 +20,14 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { parse, type SemVer } from "semver";
|
||||
import { releaseName, releaseNamePrefix } from "../inputs/index.js";
|
||||
import { cache } from "./cache.js";
|
||||
import { releaseName, releaseNamePrefix } from "./inputs/index.js";
|
||||
|
||||
export function parseSemVer(version = releaseName()): SemVer | null {
|
||||
return cache(`semver-${ version }`, () => parse(version.replace(new RegExp(`^${ releaseNamePrefix() }`), ""), { includePrerelease: true } as never));
|
||||
}
|
||||
|
||||
export { SemVer };
|
||||
export type { SemVer };
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { context } from "@actions/github";
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023-2025 Ardalan Amini
|
||||
@@ -20,7 +20,6 @@
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
import { context } from "@actions/github";
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2025 Ardalan Amini
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
export function trim<T extends string | null | undefined>(value: T): T {
|
||||
if (!value) return value;
|
||||
|
||||
return value.trim().replace(/ {2,}/g, " ") as T;
|
||||
}
|
||||
Reference in new issue
Block a user