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:
Ardalan Amini authored and GitHub committed 2025-06-07 15:37:31 +03:30
1 parent 3c1177539c
commit 9bd6b8698c
95 files changed
+4381 -302

No files matched your search

+280
View File
@@ -0,0 +1,280 @@
/**
* 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.
*/
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { getBooleanInput, getInput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import fetchMock from "fetch-mock";
import { generateChangelog } from "../src/changelog.js";
it("should return nothing", async () => {
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const shouldUseGithubAutolink = true;
const defaultCommitType = "Other Changes";
const commitTypes = "chore: Chores\nci: CI";
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case gitHubTokenInputName:
return gitHubTokenInputValue;
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
default:
return "";
}
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: update test workflow\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: info.previous.sha,
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[commit],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateChangelog(info.previous.sha);
expect(result).toBe("");
});
it("should return nothing (no description)", async () => {
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "7a94b0db6150850cb1ae7243b13a4c972e9db261",
},
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const shouldUseGithubAutolink = true;
const defaultCommitType = "Other Changes";
const commitTypes = "chore: Chores\nci: CI";
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case gitHubTokenInputName:
return gitHubTokenInputValue;
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
default:
return "";
}
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: \n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: "3c1177539c1a216084f922ea52e56dd719a25945",
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[
commit, {
author: {
login: "ardalanamini",
},
commit: {
message: "chore: update copyright year\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: info.previous.sha,
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateChangelog(info.previous.sha);
expect(result).toBe("");
});
it("should return nothing (flagged to ignore)", async () => {
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "7a94b0db6150850cb1ae7243b13a4c972e9db261",
},
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const shouldUseGithubAutolink = true;
const defaultCommitType = "Other Changes";
const commitTypes = "chore: Chores\nci: CI";
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case gitHubTokenInputName:
return gitHubTokenInputValue;
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
default:
return "";
}
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: update test workflow [ignore]\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: "3c1177539c1a216084f922ea52e56dd719a25945",
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[
commit, {
author: {
login: "ardalanamini",
},
commit: {
message: "chore: update copyright year\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: info.previous.sha,
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateChangelog(info.previous.sha);
expect(result).toBe("");
});
it("should generate the changelog", async () => {
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "7a94b0db6150850cb1ae7243b13a4c972e9db261",
},
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const shouldUseGithubAutolink = true;
const defaultCommitType = "Other Changes";
const commitTypes = "chore: Chores\nci: CI";
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case gitHubTokenInputName:
return gitHubTokenInputValue;
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
default:
return "";
}
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: update test workflow\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: "3c1177539c1a216084f922ea52e56dd719a25945",
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[
commit, {
author: {
login: "ardalanamini",
},
commit: {
message: "chore: update copyright year\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: info.previous.sha,
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateChangelog(info.previous.sha);
expect(result).toBe("## CI\n* update test workflow\n");
});
+209
View File
@@ -0,0 +1,209 @@
/**
* 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.
*/
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { getBooleanInput, getInput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import fetchMock from "fetch-mock";
import { generateFooter } from "../src/footer";
import { repository } from "../src/utils/index.js";
it("should return nothing", async () => {
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const result = await generateFooter(info.previous.name);
expect(result).toBe("");
});
it("should generate the changelog footer with new contributors", async () => {
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const releaseNameInputName = "release-name";
const releaseNameInputValue = "2.0.0";
jest.mocked(getBooleanInput).mockImplementation((name) => {
if (name === "mention-new-contributors") return true;
return false;
});
jest.mocked(getInput).mockImplementation((name) => {
switch (name) {
case gitHubTokenInputName: return gitHubTokenInputValue;
case releaseNameInputName: return releaseNameInputValue;
default: return "";
}
});
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const fetch = fetchMock.postOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/releases/generate-notes",
{
body: {
body: "## New Contributors\n- Author Name",
},
},
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateFooter(info.previous.name);
expect(result).toEqual("\n\n## New Contributors\n- Author Name\n");
expect(getInput).toHaveBeenCalledTimes(2);
expect(getInput).toHaveBeenNthCalledWith(1, releaseNameInputName, { required: true });
expect(getInput).toHaveNthReturnedWith(1, releaseNameInputValue);
expect(getInput).toHaveBeenNthCalledWith(2, gitHubTokenInputName, { required: true });
expect(getInput).toHaveNthReturnedWith(2, gitHubTokenInputValue);
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
it("should generate the changelog footer with the full changelog link", async () => {
const { url } = repository();
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const releaseNameInputName = "release-name";
const releaseNameInputValue = "2.0.0";
jest.mocked(getBooleanInput).mockImplementation((name) => {
if (name === "include-compare-link") return true;
return false;
});
jest.mocked(getInput).mockImplementation((name) => {
switch (name) {
case gitHubTokenInputName: return gitHubTokenInputValue;
case releaseNameInputName: return releaseNameInputValue;
default: return "";
}
});
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const result = await generateFooter(info.previous.name);
expect(result).toEqual(`\n\n**Full Changelog**: \`[${ info.previous.name }...${ releaseNameInputValue }](${ url }/compare/${ info.previous.name }...${ releaseNameInputValue })\``);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(releaseNameInputName, { required: true });
expect(getInput).toHaveReturnedWith(releaseNameInputValue);
expect(getOctokit).toHaveBeenCalledTimes(0);
});
it("should generate the changelog footer with new contributors and the full changelog short link", async () => {
const { url } = repository();
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const releaseNameInputName = "release-name";
const releaseNameInputValue = "2.0.0";
jest.mocked(getBooleanInput).mockImplementation(() => true);
jest.mocked(getInput).mockImplementation((name) => {
switch (name) {
case gitHubTokenInputName: return gitHubTokenInputValue;
case releaseNameInputName: return releaseNameInputValue;
default: return "";
}
});
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const fetch = fetchMock.postOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/releases/generate-notes",
{
body: {
body: "## New Contributors\n- Author Name",
},
},
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await generateFooter(info.previous.name);
expect(result).toEqual(`\n\n## New Contributors\n- Author Name\n\n\n**Full Changelog**: ${ url }/compare/${ info.previous.name }...${ releaseNameInputValue }`);
expect(getInput).toHaveBeenCalledTimes(3);
expect(getInput).toHaveBeenNthCalledWith(1, releaseNameInputName, { required: true });
expect(getInput).toHaveNthReturnedWith(1, releaseNameInputValue);
expect(getInput).toHaveBeenNthCalledWith(2, gitHubTokenInputName, { required: true });
expect(getInput).toHaveNthReturnedWith(2, gitHubTokenInputValue);
expect(getInput).toHaveBeenNthCalledWith(3, "release-name-prefix", { required: false });
expect(getInput).toHaveNthReturnedWith(3, "");
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
+133
View File
@@ -0,0 +1,133 @@
/**
* 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.
*/
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { getBooleanInput, getInput, setOutput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import fetchMock from "fetch-mock";
import { generate } from "../src/generate.js";
it("should generate the outputs", async () => {
const info = {
releaseName: "2.0.0",
releaseId : "latest",
prerelease : false,
previous : {
name: "1.0.0",
sha : "7a94b0db6150850cb1ae7243b13a4c972e9db261",
},
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const defaultCommitType = "Other Changes";
const commitTypes = "chore: Chores\nci: CI";
jest.mocked(getBooleanInput).mockImplementation((name) => {
switch (name) {
case "use-github-autolink":
case "mention-new-contributors":
return true;
default:
return false;
}
});
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case gitHubTokenInputName:
return gitHubTokenInputValue;
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
case "release-name":
return info.releaseName;
default:
return "";
}
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: update test workflow\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: "3c1177539c1a216084f922ea52e56dd719a25945",
};
const fetch = fetchMock
.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/tags",
[
{
name : info.previous.name,
commit: {
sha: info.previous.sha,
},
},
],
).getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[
commit, {
author: {
login: "ardalanamini",
},
commit: {
message: "chore: update copyright year\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: info.previous.sha,
},
],
)
.postOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/releases/generate-notes",
{
body: {
body: "## New Contributors\n- Ardalan Amini",
},
},
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
await generate();
expect(setOutput).toHaveBeenCalledTimes(3);
expect(setOutput).toHaveBeenCalledWith("prerelease", info.prerelease);
expect(setOutput).toHaveBeenCalledWith("release-id", info.releaseId);
expect(setOutput).toHaveBeenCalledWith(
"changelog",
"## CI\n* update test workflow\n\n\n## New Contributors\n- Ardalan Amini\n",
);
});
+63
View File
@@ -0,0 +1,63 @@
/**
* 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 { getInput } from "@actions/core";
import { commitTypes } from "../../src/inputs";
it("should get and parse the \"commit-types\" input", () => {
const inputValue = `
feat : New Features
fix : Bug Fixes
build : Build System & Dependencies
perf : Performance Improvements
docs : Documentation
test : Tests
refactor: Refactors
chore : Chores
ci : CI
style : Code Style
revert : Reverts
`;
jest.mocked(getInput).mockReturnValueOnce(inputValue);
const result = commitTypes();
expect(result).toEqual({
feat : "New Features",
fix : "Bug Fixes",
build : "Build System & Dependencies",
perf : "Performance Improvements",
docs : "Documentation",
test : "Tests",
refactor: "Refactors",
chore : "Chores",
ci : "CI",
style : "Code Style",
revert : "Reverts",
});
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("commit-types", { required: true });
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { getInput } from "@actions/core";
import { defaultCommitType } from "../../src/inputs";
it("should get and parse the \"default-commit-type\" input", () => {
const inputValue = "Other Changes";
jest.mocked(getInput).mockReturnValueOnce(inputValue);
const result = defaultCommitType();
expect(result).toEqual(inputValue);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("default-commit-type", { required: true });
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { getInput } from "@actions/core";
import { gitHubToken } from "../../src/inputs";
it("should get and parse the \"github-token\" input", () => {
const inputValue = "github-token-value";
jest.mocked(getInput).mockReturnValueOnce(inputValue);
const result = gitHubToken();
expect(result).toEqual(inputValue);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("github-token", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { includeCommitLinks } from "../../src/inputs";
it.each([true, false])("should get and parse the \"include-commit-links\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = includeCommitLinks();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("include-commit-links", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { includeCompareLink } from "../../src/inputs";
it.each([true, false])("should get and parse the \"include-compare-link\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = includeCompareLink();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("include-compare-link", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { includePRLinks } from "../../src/inputs";
it.each([true, false])("should retrieve the \"include-pr-links\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = includePRLinks();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("include-pr-links", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { mentionAuthors } from "../../src/inputs";
it.each([true, false])("should get and parse the \"mention-authors\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = mentionAuthors();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("mention-authors", { required: true });
});
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { mentionNewContributors } from "../../src/inputs";
it.each([true, false])("should get and parse the \"mention-new-contributors\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = mentionNewContributors();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("mention-new-contributors", { required: true });
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { getInput } from "@actions/core";
import { releaseNamePrefix } from "../../src/inputs";
it("should get and parse the \"release-name-prefix\" input", () => {
const inputValue = "@actions/github/";
jest.mocked(getInput).mockReturnValueOnce(inputValue);
const result = releaseNamePrefix();
expect(result).toEqual(inputValue);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("release-name-prefix", { required: false });
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { getInput } from "@actions/core";
import { releaseName } from "../../src/inputs";
it("should get and parse the \"release-name\" input", () => {
const inputValue = "v1.0.0";
jest.mocked(getInput).mockReturnValueOnce(inputValue);
const result = releaseName();
expect(result).toEqual(inputValue);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("release-name", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { semver } from "../../src/inputs";
it.each([true, false])("should get and parse the \"semver\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = semver();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("semver", { required: true });
});
+37
View File
@@ -0,0 +1,37 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { useGitHubAutolink } from "../../src/inputs";
it.each([true, false])("should retrieve the \"use-github-autolink\" input as %j", (inputValue) => {
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = useGitHubAutolink();
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith("use-github-autolink", { required: true });
});
+27
View File
@@ -0,0 +1,27 @@
/**
* 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 { clearCache } from "../../src/utils";
afterEach(() => clearCache());
+26
View File
@@ -0,0 +1,26 @@
/**
* 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.
*/
jest.mock("@actions/core");
jest.mock("@actions/github");
+119
View File
@@ -0,0 +1,119 @@
/**
* 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 { getBooleanInput, getInput } from "@actions/core";
import { context } from "@actions/github";
import YAML from "yaml";
import { ChangelogNode, CommitNode, ScopeNode, TypeNode } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const url = `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`;
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should create an instance with common values", () => {
const shouldUseGithubAutolink = true;
const defaultCommitType = "Other Changes";
const commitTypes = "feat: Features\nbug: Bug Fixes";
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case "default-commit-type":
return defaultCommitType;
case "commit-types":
return commitTypes;
default:
return "";
}
});
const changelogNode = (new ChangelogNode);
expect(changelogNode.shouldUseGithubAutolink).toBe(shouldUseGithubAutolink);
expect(changelogNode.defaultType).toBe(defaultCommitType);
expect(changelogNode.typeMap).toEqual(YAML.parse(commitTypes));
expect(changelogNode.repo).toEqual({
...repo,
url,
});
expect(changelogNode.print()).toBeNull();
});
it("should not print anything", () => {
jest.mocked(getBooleanInput).mockReturnValueOnce(true);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case "default-commit-type":
return "Other Changes";
case "commit-types":
return "feat: Features\nbug: Bug Fixes";
default:
return "";
}
});
const changelogNode = (new ChangelogNode);
const typeNode = changelogNode.addType("feat");
const scopeNode = typeNode.addScope();
expect(typeNode).toBeInstanceOf(TypeNode);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(changelogNode.print()).toBeNull();
});
it("should print commit changelog", () => {
jest.mocked(getBooleanInput).mockReturnValueOnce(true);
jest.mocked(getInput).mockImplementation((input) => {
switch (input) {
case "default-commit-type":
return "Other Changes";
case "commit-types":
return "feat: Features\nbug: Bug Fixes";
default:
return "";
}
});
const changelogNode = (new ChangelogNode);
const commitNode1 = changelogNode.addType("feat").addScope()
.addCommit("implement awesome feature");
const commitNode2 = changelogNode.addType("bug").addScope()
.addCommit("fix some issue");
expect(commitNode1).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
expect(changelogNode.print()).toBe("## Features\n* implement awesome feature\n\n## Bug Fixes\n* fix some issue");
});
+288
View File
@@ -0,0 +1,288 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { CommitAuthorNode, CommitHashNode, Node, PullRequestNode } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const serverUrl = context.serverUrl;
const url = `${ serverUrl }/${ repo.owner }/${ repo.repo }`;
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should print the username only to be autolinked", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const commitAuthorNode = new CommitAuthorNode(username);
expect(commitAuthorNode).toBeInstanceOf(Node);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(commitAuthorNode.repo).toEqual({
...repo,
url,
});
expect(commitAuthorNode.print()).toBe(`@${ username }`);
});
it("should not print anything", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "mention-authors");
const username = "ardalanamini";
const commitAuthorNode = new CommitAuthorNode(username);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(false);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(commitAuthorNode.print()).toBeNull();
});
it("should print the username with the link (not using autolink)", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const username = "ardalanamini";
const commitAuthorNode = new CommitAuthorNode(username);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(false);
expect(commitAuthorNode.print()).toBe(`[@${ username }](${ serverUrl }/${ username })`);
});
describe("should print the username & commit sha", () => {
it("with autolink", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(reference).toBeInstanceOf(CommitHashNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } by @${ username }`);
});
it("without autolink", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(false);
expect(reference).toBeInstanceOf(CommitHashNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } by [@${ username }](${ serverUrl }/${ username })`);
});
});
describe("should print the username & pr (prioritized over commit sha)", () => {
it("with autolink", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const pr = "197";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha, pr);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(reference).toBeInstanceOf(PullRequestNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } by @${ username }`);
});
it("without autolink", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const pr = "197";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha, pr);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(false);
expect(reference).toBeInstanceOf(PullRequestNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } by [@${ username }](${ serverUrl }/${ username })`);
});
});
describe("should print the username & multiple references", () => {
it("with autolink", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const pr = "197";
const sha2 = "7a94b0db6150850cb1ae7243b13a4c972e9db261";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha, pr);
const reference2 = commitAuthorNode.addReference(sha2);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(reference).toBeInstanceOf(PullRequestNode);
expect(reference2).toBeInstanceOf(CommitHashNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } & ${ reference2.print() } by @${ username }`);
});
it("without autolink", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const pr = "197";
const sha2 = "7a94b0db6150850cb1ae7243b13a4c972e9db261";
const commitAuthorNode = new CommitAuthorNode(username);
const reference = commitAuthorNode.addReference(sha, pr);
const reference2 = commitAuthorNode.addReference(sha2);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(false);
expect(reference).toBeInstanceOf(PullRequestNode);
expect(reference2).toBeInstanceOf(CommitHashNode);
expect(commitAuthorNode.print()).toBe(`${ reference.print() } & ${ reference2.print() } by [@${ username }](${ serverUrl }/${ username })`);
});
});
describe("should reuse reference", () => {
it("commit sha", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const commitAuthorNode = new CommitAuthorNode(username);
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const reference1 = commitAuthorNode.addReference(sha);
const reference2 = commitAuthorNode.addReference(sha);
expect(commitAuthorNode).toBeInstanceOf(Node);
expect(reference1).toEqual(reference2);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(commitAuthorNode.repo).toEqual({
...repo,
url,
});
expect(commitAuthorNode.print()).toBe(`${ sha } by @${ username }`);
});
it("pr number", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const username = "ardalanamini";
const commitAuthorNode = new CommitAuthorNode(username);
const pr = "1";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const reference1 = commitAuthorNode.addReference(sha, pr);
const reference2 = commitAuthorNode.addReference(sha, pr);
expect(commitAuthorNode).toBeInstanceOf(Node);
expect(reference1).toEqual(reference2);
expect(commitAuthorNode.username).toBe(username);
expect(commitAuthorNode.shouldMentionAuthor).toBe(true);
expect(commitAuthorNode.shouldUseGithubAutolink).toBe(true);
expect(commitAuthorNode.repo).toEqual({
...repo,
url,
});
expect(commitAuthorNode.print()).toBe(`#${ pr } by @${ username }`);
});
});
+88
View File
@@ -0,0 +1,88 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { CommitHashNode, Node } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should print the sha only to be autolinked", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const commitHashNode = new CommitHashNode(sha);
expect(commitHashNode).toBeInstanceOf(Node);
expect(commitHashNode.sha).toBe(sha);
expect(commitHashNode.shouldNotPrint).toBe(false);
expect(commitHashNode.shouldUseGithubAutolink).toBe(true);
expect(commitHashNode.repo).toEqual({
...repo,
url: `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`,
});
expect(commitHashNode.print()).toBe(sha);
});
it("should not print anything", () => {
jest.mocked(getBooleanInput).mockReturnValue(false);
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const commitHashNode = new CommitHashNode(sha);
expect(commitHashNode.sha).toBe(sha);
expect(commitHashNode.shouldNotPrint).toBe(true);
expect(commitHashNode.shouldUseGithubAutolink).toBe(false);
expect(commitHashNode.print()).toBeNull();
});
it("should print the sha with the link (not using autolink)", () => {
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const commitHashNode = new CommitHashNode(sha);
expect(commitHashNode.sha).toBe(sha);
expect(commitHashNode.shouldNotPrint).toBe(false);
expect(commitHashNode.shouldUseGithubAutolink).toBe(false);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(commitHashNode.print()).toBe(`\`[${ sha.slice(0, 7) }](${ context.serverUrl }/${ repo.owner }/${ repo.repo }/commit/${ sha })\``);
});
+172
View File
@@ -0,0 +1,172 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { CommitAuthorNode, CommitHashNode, CommitNode, Node } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const url = `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`;
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should print a commit description only", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const commitNode = new CommitNode(description);
expect(commitNode).toBeInstanceOf(Node);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(false);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode.repo).toEqual({
...repo,
url,
});
expect(commitNode.print()).toBe(`* ${ description }`);
});
it("should print a commit description with prefix", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const commitNode = new CommitNode(description);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(false);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
const prefix = " ";
expect(commitNode.print(prefix)).toBe(`${ prefix }* ${ description }`);
});
it("should print a breaking commit description only", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const commitNode = new CommitNode(description, true);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(true);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode.print()).toBe(`* ***BREAKING:*** ${ description }`);
});
it("should print the commit description and its author", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const username = "ardalanamini";
const commitNode = new CommitNode(description);
const author = commitNode.addAuthor(username);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(false);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
expect(author).toBeInstanceOf(CommitAuthorNode);
expect(commitNode.print()).toBe(`* ${ description } (${ author.print() })`);
});
it("should print the commit description and its multiple authors", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const username = "ardalanamini";
const username2 = "not-ardalanamini";
const commitNode = new CommitNode(description);
const author = commitNode.addAuthor(username);
const author2 = commitNode.addAuthor(username2);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(false);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
expect(author).toBeInstanceOf(CommitAuthorNode);
expect(author2).toBeInstanceOf(CommitAuthorNode);
expect(commitNode.print()).toBe(`* ${ description } (${ author.print() }, ${ author2.print() })`);
});
it("it should reuse the same author node for same authors", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const username = "ardalanamini";
const sha = "3c1177539c1a216084f922ea52e56dd719a25945";
const sha2 = "7a94b0db6150850cb1ae7243b13a4c972e9db261";
const commitNode = new CommitNode(description);
const author = commitNode.addAuthor(username);
const reference = author.addReference(sha);
const author2 = commitNode.addAuthor(username);
const reference2 = author.addReference(sha2);
expect(commitNode.description).toBe(description);
expect(commitNode.breaking).toBe(false);
expect(commitNode.shouldUseGithubAutolink).toBe(true);
expect(author).toBeInstanceOf(CommitAuthorNode);
expect(reference).toBeInstanceOf(CommitHashNode);
expect(author2).toBeInstanceOf(CommitAuthorNode);
expect(reference2).toBeInstanceOf(CommitHashNode);
expect(author).toBe(author2);
const result = commitNode.print();
expect(result).toBe(`* ${ description } (${ author.print() })`);
expect(result).toBe(`* ${ description } (${ author2.print() })`);
});
+56
View File
@@ -0,0 +1,56 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { Node } from "../../src/nodes";
it("should create an instance with common values", () => {
const shouldUseGithubAutolink = true;
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
jest.mocked(getBooleanInput).mockReturnValueOnce(shouldUseGithubAutolink);
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
class TestNode extends Node {
public print(): string {
return this.repo.repo;
}
}
const node = (new TestNode);
expect(node.shouldUseGithubAutolink).toBe(shouldUseGithubAutolink);
expect(node.serverUrl).toBe(context.serverUrl);
expect(node.repo).toEqual({
...repo,
url: `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`,
});
});
+88
View File
@@ -0,0 +1,88 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { Node, PullRequestNode } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should print the pr only to be autolinked", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const pr = "197";
const pullRequestNode = new PullRequestNode(pr);
expect(pullRequestNode).toBeInstanceOf(Node);
expect(pullRequestNode.pr).toBe(pr);
expect(pullRequestNode.shouldNotPrint).toBe(false);
expect(pullRequestNode.shouldUseGithubAutolink).toBe(true);
expect(pullRequestNode.repo).toEqual({
...repo,
url: `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`,
});
expect(pullRequestNode.print()).toBe(`#${ pr }`);
});
it("should not print anything", () => {
jest.mocked(getBooleanInput).mockReturnValue(false);
const pr = "197";
const pullRequestNode = new PullRequestNode(pr);
expect(pullRequestNode.pr).toBe(pr);
expect(pullRequestNode.shouldNotPrint).toBe(true);
expect(pullRequestNode.shouldUseGithubAutolink).toBe(false);
expect(pullRequestNode.print()).toBeNull();
});
it("should print the pr with the link (not using autolink)", () => {
// Enable PR links but disable GitHub autolink to test manual link generation
jest.mocked(getBooleanInput).mockImplementation(name => name !== "use-github-autolink");
const pr = "197";
const pullRequestNode = new PullRequestNode(pr);
expect(pullRequestNode.pr).toBe(pr);
expect(pullRequestNode.shouldNotPrint).toBe(false);
expect(pullRequestNode.shouldUseGithubAutolink).toBe(false);
expect(pullRequestNode.print()).toBe(`[#${ pr }](${ context.serverUrl }/${ repo.owner }/${ repo.repo }/issues/${ pr })`);
});
+188
View File
@@ -0,0 +1,188 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { CommitNode, Node, ScopeNode } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const url = `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`;
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should not print anything", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const scope = "commit-scope";
const scopeNode = new ScopeNode(scope);
expect(scopeNode).toBeInstanceOf(Node);
expect(scopeNode.scope).toBe(scope);
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode.repo).toEqual({
...repo,
url,
});
expect(scopeNode.print()).toBeNull();
});
it("should print a scope & its commit", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const scope = "commit-scope";
const description = "ci: update test workflow";
const scopeNode = new ScopeNode(scope);
const commitNode = scopeNode.addCommit(description);
expect(scopeNode.scope).toBe(scope);
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(scopeNode.print()).toBe(`* **${ scope }:**\n${ commitNode.print(" ") }`);
});
it("should reuse the same commit message (in the case the breaking matches as well)", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const scope = "commit-scope";
const description = "ci: update test workflow";
const scopeNode = new ScopeNode(scope);
const commitNode = scopeNode.addCommit(description);
const commitNode2 = scopeNode.addCommit(description);
expect(scopeNode.scope).toBe(scope);
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
expect(commitNode).toBe(commitNode2);
const result = scopeNode.print();
expect(result).toBe(`* **${ scope }:**\n${ commitNode.print(" ") }`);
expect(result).toBe(`* **${ scope }:**\n${ commitNode2.print(" ") }`);
});
it("should print a scope & its commit with prefix", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const scope = "commit-scope";
const description = "ci: update test workflow";
const scopeNode = new ScopeNode(scope);
const commitNode = scopeNode.addCommit(description);
expect(scopeNode.scope).toBe(scope);
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
const prefix = " ";
expect(scopeNode.print(prefix)).toBe(`${ prefix }* **${ scope }:**\n${ commitNode.print(`${ prefix } `) }`);
});
it("should print a scope & its multiple commits", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const scope = "commit-scope";
const description = "ci: update test workflow";
const description2 = "chore: update copyright year";
const scopeNode = new ScopeNode(scope);
const commitNode = scopeNode.addCommit(description);
const commitNode2 = scopeNode.addCommit(description2);
expect(scopeNode.scope).toBe(scope);
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
expect(scopeNode.print()).toBe(`* **${ scope }:**\n${ commitNode.print(" ") }\n${ commitNode2.print(" ") }`);
});
it("should print a commit without scope", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const scopeNode = (new ScopeNode);
const commitNode = scopeNode.addCommit(description);
expect(scopeNode.scope).toBe("");
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(scopeNode.print()).toBe(`${ commitNode.print() }`);
});
it("should print multiple commits without scope", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const description = "ci: update test workflow";
const description2 = "chore: update copyright year";
const scopeNode = (new ScopeNode);
const commitNode = scopeNode.addCommit(description);
const commitNode2 = scopeNode.addCommit(description2);
expect(scopeNode.scope).toBe("");
expect(scopeNode.shouldUseGithubAutolink).toBe(true);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
expect(scopeNode.print()).toBe(`${ commitNode.print() }\n${ commitNode2.print() }`);
});
+198
View File
@@ -0,0 +1,198 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { context } from "@actions/github";
import { CommitNode, Node, ScopeNode, TypeNode } from "../../src/nodes";
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const url = `${ context.serverUrl }/${ repo.owner }/${ repo.repo }`;
beforeEach(() => {
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
});
it("should not print anything when no scopes/commits are added", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const typeNode = new TypeNode(commitType);
expect(typeNode).toBeInstanceOf(Node);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(typeNode.repo).toEqual({
...repo,
url,
});
expect(typeNode.print()).toBeNull();
});
it("should not print anything when no commits are added", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const scope = "commit-scope";
const typeNode = new TypeNode(commitType);
const scopeNode = typeNode.addScope(scope);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(typeNode.print()).toBeNull();
});
it("should print a type & its scope/commit", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const scope = "commit-scope";
const description = "ci: update test workflow";
const typeNode = new TypeNode(commitType);
const scopeNode = typeNode.addScope(scope);
const commitNode = scopeNode.addCommit(description);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(typeNode.print()).toBe(`## ${ commitType }\n${ scopeNode.print() }`);
});
it("should reuse the same scope (in the case the breaking matches as well)", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const scope = "commit-scope";
const description = "ci: update test workflow";
const description2 = "chore: update copyright year";
const typeNode = new TypeNode(commitType);
const scopeNode = typeNode.addScope(scope);
const scopeNode2 = typeNode.addScope(scope);
const commitNode = scopeNode.addCommit(description);
const commitNode2 = scopeNode2.addCommit(description2);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(scopeNode2).toBeInstanceOf(ScopeNode);
expect(scopeNode).toBe(scopeNode2);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
const result = typeNode.print();
expect(result).toBe(`## ${ commitType }\n${ scopeNode.print() }`);
expect(result).toBe(`## ${ commitType }\n${ scopeNode2.print() }`);
});
it("should print a type & its scope/commit with prefix", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const scope = "commit-scope";
const description = "ci: update test workflow";
const typeNode = new TypeNode(commitType);
const scopeNode = typeNode.addScope(scope);
const commitNode = scopeNode.addCommit(description);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(commitNode).toBeInstanceOf(CommitNode);
const prefix = " ";
expect(typeNode.print(prefix)).toBe(`${ prefix }## ${ commitType }\n${ scopeNode.print(prefix) }`);
});
it("should print a type & its multiple scope/commits", () => {
jest.mocked(getBooleanInput).mockReturnValue(true);
const commitType = "commit-type";
const scope = "commit-scope";
const description = "ci: update test workflow";
const description2 = "chore: update copyright year";
const typeNode = new TypeNode(commitType);
const scopeNode = typeNode.addScope(scope);
const commitNode = scopeNode.addCommit(description);
const scopeNode2 = typeNode.addScope();
const commitNode2 = scopeNode2.addCommit(description2);
expect(typeNode.type).toBe(commitType);
expect(typeNode.shouldUseGithubAutolink).toBe(true);
expect(scopeNode).toBeInstanceOf(ScopeNode);
expect(scopeNode2).toBeInstanceOf(ScopeNode);
expect(commitNode).toBeInstanceOf(CommitNode);
expect(commitNode2).toBeInstanceOf(CommitNode);
expect(typeNode.print()).toBe(`## ${ commitType }\n${ scopeNode2.print() }\n${ scopeNode.print() }`);
});
+40
View File
@@ -0,0 +1,40 @@
/**
* 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 { info, setOutput } from "@actions/core";
import { setChangelog } from "../../src/outputs";
it("should log and set the changelog output", () => {
const outputValue = "Changelog Value";
setChangelog(outputValue);
const outputName = "changelog";
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenCalledWith(`output -> ${ outputName }: ${ outputValue }`);
expect(setOutput).toHaveBeenCalledTimes(1);
expect(setOutput).toHaveBeenCalledWith(outputName, outputValue);
});
+38
View File
@@ -0,0 +1,38 @@
/**
* 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 { info, setOutput } from "@actions/core";
import { setPrerelease } from "../../src/outputs";
it.each([true, false])("should output \"prerelease\" value as %j", (outputValue) => {
setPrerelease(outputValue);
const outputName = "prerelease";
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenCalledWith(`output -> ${ outputName }: ${ outputValue }`);
expect(setOutput).toHaveBeenCalledTimes(1);
expect(setOutput).toHaveBeenCalledWith(outputName, outputValue);
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { info, setOutput } from "@actions/core";
import { setReleaseId } from "../../src/outputs";
it("should output \"release-id\" value", () => {
const outputName = "release-id";
const outputValue = "latest";
setReleaseId(outputValue);
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenCalledWith(`output -> ${ outputName }: ${ outputValue }`);
expect(setOutput).toHaveBeenCalledTimes(1);
expect(setOutput).toHaveBeenCalledWith(outputName, outputValue);
});
+134
View File
@@ -0,0 +1,134 @@
/**
* 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 { getBooleanInput, getInput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import fetchMock from "fetch-mock";
import { getTagInfo } from "../src/tag";
it("should get tag information", async () => {
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
jest.mocked(getInput).mockImplementationOnce((name) => {
if (name === gitHubTokenInputName) return gitHubTokenInputValue;
return "";
});
const info = {
releaseId : "latest",
prerelease: false,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/tags",
[
{
name : info.previous.name,
commit: {
sha: info.previous.sha,
},
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await getTagInfo();
expect(result).toEqual(info);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(gitHubTokenInputName, { required: true });
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
it("should get semver tag information", async () => {
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
const releaseNameInputName = "release-name";
const releaseNameInputValue = "2.0.0-beta.1";
const releaseNamePrefixInputName = "release-name-prefix";
const releaseNamePrefixInputValue = "";
jest.mocked(getBooleanInput).mockReturnValueOnce(true);
jest.mocked(getInput).mockImplementation((name) => {
switch (name) {
case gitHubTokenInputName: return gitHubTokenInputValue;
case releaseNameInputName: return releaseNameInputValue;
case releaseNamePrefixInputName: return releaseNamePrefixInputValue;
default: return "";
}
});
const info = {
releaseId : "beta",
prerelease: true,
previous : {
name: "1.0.0",
sha : "3c1177539c1a216084f922ea52e56dd719a25945",
},
};
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/tags",
[
{
name : info.previous.name,
commit: {
sha: info.previous.sha,
},
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = await getTagInfo();
expect(result).toEqual(info);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
expect(getInput).toHaveBeenCalledTimes(3);
expect(getInput).toHaveBeenCalledWith(gitHubTokenInputName, { required: true });
expect(getInput).toHaveBeenCalledWith(releaseNameInputName, { required: true });
expect(getInput).toHaveBeenCalledWith(releaseNamePrefixInputName, { required: false });
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
+67
View File
@@ -0,0 +1,67 @@
/**
* 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 { getBooleanInput } from "@actions/core";
import { booleanInput, cache } from "../../src/utils";
it("should get and parse a boolean input", () => {
const inputName = "foo";
const inputValue = true;
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = booleanInput(inputName);
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith(inputName, { required: true });
});
it("should get a cached boolean input", () => {
const inputName = "foo";
const inputValue = true;
cache(inputName, () => inputValue);
const result = booleanInput(inputName);
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(0);
});
it("should get and parse an optional boolean input", () => {
const inputName = "foo";
const inputValue = false;
jest.mocked(getBooleanInput).mockReturnValueOnce(inputValue);
const result = booleanInput(inputName, false);
expect(result).toEqual(inputValue);
expect(getBooleanInput).toHaveBeenCalledTimes(1);
expect(getBooleanInput).toHaveBeenCalledWith(inputName, { required: false });
});
+90
View File
@@ -0,0 +1,90 @@
/**
* 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 { cache, clearCache } from "../../src/utils";
it("should cache value", () => {
const name = "foo";
const value = "bar";
const fn = jest.fn(() => value);
const firstCallResult = cache(name, fn);
expect(firstCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(1);
fn.mockClear();
const secondCallResult = cache(name, fn);
expect(secondCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(0);
});
it("should overwrite cache value", () => {
const name = "foo";
const value = "bar";
const fn = jest.fn(() => value);
const firstCallResult = cache(name, fn);
expect(firstCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(1);
fn.mockClear();
const secondCallResult = cache(name, fn, true);
expect(secondCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(1);
});
it("should clear cache", () => {
const name = "foo";
const value = "bar";
const fn = jest.fn(() => value);
const firstCallResult = cache(name, fn);
expect(firstCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(1);
fn.mockClear();
clearCache();
const secondCallResult = cache(name, fn);
expect(secondCallResult).toBe(value);
expect(fn).toHaveBeenCalledTimes(1);
});
+92
View File
@@ -0,0 +1,92 @@
/**
* 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 { getInput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import fetchMock from "fetch-mock";
import { iterateCommits } from "../../src/utils";
it("should iterate over commits", async () => {
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
jest.mocked(getInput).mockImplementationOnce((name) => {
if (name === gitHubTokenInputName) return gitHubTokenInputValue;
return "";
});
const commit = {
author: {
login: "ardalanamini",
},
commit: {
message: "ci: update test workflow\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: "3c1177539c1a216084f922ea52e56dd719a25945",
};
const fromSha = "7a94b0db6150850cb1ae7243b13a4c972e9db261";
const fetch = fetchMock.getOnce(
"begin:https://api.github.com/repos/ardalanamini/auto-changelog/commits",
[
commit, {
author: {
login: "ardalanamini",
},
commit: {
message: "chore: update copyright year\n\nSigned-off-by: Ardalan Amini <[email protected]>",
},
sha: fromSha,
},
],
);
const gitHub = new GitHub({ request: { fetch: fetch.fetchHandler } });
jest.mocked(getOctokit).mockImplementationOnce(() => gitHub);
const result = iterateCommits(repo.owner, repo.repo, fromSha);
expect(await result.next()).toEqual({
done : false,
value: commit,
});
expect(await result.next()).toEqual({
done: true,
});
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(gitHubTokenInputName, { required: true });
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
+93
View File
@@ -0,0 +1,93 @@
/**
* 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 { getInput } from "@actions/core";
import { cache, input } from "../../src/utils";
it("should get input value", () => {
const name = "foo";
const value = "bar";
jest.mocked(getInput).mockReturnValueOnce(value);
const result = input(name);
expect(result).toBe(value);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(name, { required: true });
});
it("should get cached input value", () => {
const name = "foo";
const value = "bar";
cache(name, () => value);
const result = input(name);
expect(result).toBe(value);
expect(getInput).toHaveBeenCalledTimes(0);
});
it("should get optional input value", () => {
const name = "foo";
const value = "";
jest.mocked(getInput).mockReturnValueOnce(value);
const result = input(name, false);
expect(result).toBe(value);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(name, { required: false });
});
it("should get parsed input value", () => {
const name = "foo";
jest.mocked(getInput).mockReturnValueOnce("1");
const result = input(name, inputValue => +inputValue);
expect(result).toBe(1);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(name, { required: true });
});
it("should get parsed optional input value", () => {
const name = "foo";
jest.mocked(getInput).mockReturnValueOnce("");
const result = input(name, inputValue => +(inputValue || "1"), false);
expect(result).toBe(1);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(name, { required: false });
});
+51
View File
@@ -0,0 +1,51 @@
/**
* 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 { getInput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHub } from "@actions/github/lib/utils";
import { octokit } from "../../src/utils";
it("should get octokit instance", () => {
const gitHubTokenInputName = "github-token";
const gitHubTokenInputValue = "github-token-value";
jest.mocked(getInput).mockImplementationOnce((name) => {
if (name === gitHubTokenInputName) return gitHubTokenInputValue;
return "";
});
jest.mocked(getOctokit).mockImplementationOnce(() => new GitHub);
const result = octokit();
expect(result).toBeInstanceOf(GitHub);
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith(gitHubTokenInputName, { required: true });
expect(getOctokit).toHaveBeenCalledTimes(1);
expect(getOctokit).toHaveBeenCalledWith(gitHubTokenInputValue);
});
+39
View File
@@ -0,0 +1,39 @@
/**
* 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 { info, setOutput } from "@actions/core";
import { output } from "../../src/utils";
it("should output value", () => {
const name = "foo";
const value = "bar";
output(name, value);
expect(info).toHaveBeenCalledTimes(1);
expect(info).toHaveBeenCalledWith(`output -> ${ name }: ${ value }`);
expect(setOutput).toHaveBeenCalledTimes(1);
expect(setOutput).toHaveBeenCalledWith(name, value);
});
+1 -2
View File
@@ -1,4 +1,4 @@
/*
/**
* MIT License
*
* Copyright (c) 2024-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.
*
*/
/* eslint-disable no-undefined */
+104
View File
@@ -0,0 +1,104 @@
/**
* 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 { getInput } from "@actions/core";
import { parseSemVer } from "../../src/utils";
it("should parse the semver version string", () => {
const major = 1;
const minor = 2;
const patch = 3;
const prerelease = "alpha";
const prereleaseVersion = 4;
const version = `${ major }.${ minor }.${ patch }-${ prerelease }.${ prereleaseVersion }`;
const raw = `v${ version }`;
const releaseNamePrefix = "@actions/github/";
jest.mocked(getInput).mockImplementationOnce((name) => {
if (name === "release-name-prefix") return releaseNamePrefix;
return "";
});
const result = parseSemVer(raw);
expect(result).toBeDefined();
expect(result).toEqual({
build : [],
includePrerelease: true,
loose : false,
major,
minor,
options : { includePrerelease: true },
patch,
prerelease : [prerelease, prereleaseVersion],
raw,
version,
});
expect(getInput).toHaveBeenCalledTimes(1);
expect(getInput).toHaveBeenCalledWith("release-name-prefix", { required: false });
});
it("should parse the release name by default", () => {
const major = 1;
const minor = 2;
const patch = 3;
const prerelease = "alpha";
const prereleaseVersion = 4;
const version = `${ major }.${ minor }.${ patch }-${ prerelease }.${ prereleaseVersion }`;
const raw = `v${ version }`;
const releaseNamePrefix = "@actions/github/";
jest.mocked(getInput).mockImplementation((name) => {
switch (name) {
case "release-name":
return raw;
case "release-name-prefix":
return releaseNamePrefix;
default:
return "";
}
});
const result = parseSemVer();
expect(result).toBeDefined();
expect(result).toEqual({
build : [],
includePrerelease: true,
loose : false,
major,
minor,
options : { includePrerelease: true },
patch,
prerelease : [prerelease, prereleaseVersion],
raw,
version,
});
expect(getInput).toHaveBeenCalledTimes(2);
expect(getInput).toHaveBeenNthCalledWith(1, "release-name", { required: true });
expect(getInput).toHaveBeenNthCalledWith(2, "release-name-prefix", { required: false });
});
+46
View File
@@ -0,0 +1,46 @@
/**
* 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 { repository } from "../../src/utils";
it("should get the repository information with constructed URL", () => {
const repo = {
owner: "ardalanamini",
repo : "auto-changelog",
};
const serverUrl = context.serverUrl;
expect(serverUrl).toEqual("https://github.com");
jest.spyOn(context, "repo", "get").mockReturnValueOnce(repo);
const result = repository();
expect(result).toEqual({
...repo,
url: `${ serverUrl }/${ repo.owner }/${ repo.repo }`,
});
});
+63
View File
@@ -0,0 +1,63 @@
/**
* 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 { sha } from "../../src/utils";
it("should get the current commit sha", () => {
const shaValue = "3c1177539c1a216084f922ea52e56dd719a25945";
const original = jest.mocked(context).sha;
jest.mocked(context).sha = shaValue;
const result = sha();
jest.mocked(context).sha = original;
expect(result).toBe(shaValue);
});
it("should cache the sha value", () => {
const shaValue: string = "3c1177539c1a216084f922ea52e56dd719a25945";
const original = jest.mocked(context).sha;
jest.mocked(context).sha = shaValue;
// The first call should access context.sha
const result1 = sha();
// Change the mocked value
jest.mocked(context).sha = "different-sha";
// Second call should return cached value, not the new mocked value
const result2 = sha();
jest.mocked(context).sha = original;
expect(result1).toBe(shaValue);
// Should be cached
expect(result2).toBe(shaValue);
});
+54
View File
@@ -0,0 +1,54 @@
/**
* 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 "../../src/utils/trim.js";
it("should remove leading and trailing whitespace", () => {
expect(trim(" hello ")).toBe("hello");
});
it("should replace multiple spaces with a single space", () => {
expect(trim("hello world")).toBe("hello world");
});
it("should handle null value", () => {
expect(trim(null)).toBeNull();
});
it("should handle undefined value", () => {
// eslint-disable-next-line no-undefined,@typescript-eslint/no-confusing-void-expression
expect(trim(undefined)).toBeUndefined();
});
it("should handle empty string", () => {
expect(trim("")).toBe("");
});
it("should handle string with no extra spaces", () => {
expect(trim("hello")).toBe("hello");
});
it("should handle strings with only spaces", () => {
expect(trim(" ")).toBe("");
});