Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 25 additions & 36 deletions .github/scripts/check-changelog-exclusions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Used by the changelog-ci workflow to determine early if processing should continue
*/

import { INCLUDED_TYPES } from "./update-changelog.mjs";
import {INCLUDED_TYPES} from "./update-changelog.mjs";

/**
* Labels that should exclude PRs from the changelog
Expand Down Expand Up @@ -40,39 +40,12 @@ const ALL_COMMIT_TYPES = [...INCLUDED_TYPES, ...EXCLUDED_TYPES];
* Regex to match conventional commit type prefix in PR titles,
* including both included and excluded types.
*/
const typeRegex = new RegExp(
`^(${ALL_COMMIT_TYPES.join("|")})(\\(.+?\\))?!?:`,
"i",
);

/**
* Checks if the PR has any labels that are in the EXCLUDED_LABELS list.
* The PR should be excluded from the changelog update process if any excluded label is found.
*
* @param {string[]} labels - Array of PR labels
* @returns {boolean} - True if any label is excluded
*/
function hasExcludedLabel(labels) {
return labels.some((label) =>
EXCLUDED_LABELS.includes(label.name.toLowerCase()),
);
}

/**
* Gets the name of the excluded label, if any.
* @param {string[]} labels - Array of PR labels
* @returns {string|undefined} - The name of the excluded label, if any
*/
function getExcludedLabel(labels) {
return labels.find((label) =>
EXCLUDED_LABELS.includes(label.name.toLowerCase()),
)?.name;
}
const typeRegex = new RegExp(`^(${ALL_COMMIT_TYPES.join("|")})(\\(.+?\\))?!?:`, "i");

/**
* Checks if a PR should be excluded from the changelog
*/
export default async function checkExclusions({ pr, core }) {
export default async function checkExclusions({pr, core}) {
try {
const prTitle = pr.title;

Expand All @@ -96,9 +69,7 @@ export default async function checkExclusions({ pr, core }) {

// If no conventional commit type is found, skip the PR.
if (!match) {
console.log(
"⚠️ No conventional commit type found in PR title. Should skip.",
);
console.log("⚠️ No conventional commit type found in PR title. Should skip.");
shouldSkip = true;
skipReason = "no conventional commit type";
}
Expand All @@ -110,9 +81,7 @@ export default async function checkExclusions({ pr, core }) {

// If the commit type is in the EXCLUDED_TYPES list, skip the PR.
if (EXCLUDED_TYPES.includes(type)) {
console.log(
`⚠️ Conventional commit type "${type}" is excluded. Should skip.`,
);
console.log(`⚠️ Conventional commit type "${type}" is excluded. Should skip.`);
shouldSkip = true;
skipReason = `excluded type: ${type}`;
}
Expand All @@ -135,3 +104,23 @@ export default async function checkExclusions({ pr, core }) {
core.setFailed(`Failed to check exclusions: ${error.message}`);
}
}

/**
* Checks if the PR has any labels that are in the EXCLUDED_LABELS list.
* The PR should be excluded from the changelog update process if any excluded label is found.
*
* @param {string[]} labels - Array of PR labels
* @returns {boolean} - True if any label is excluded
*/
function hasExcludedLabel(labels) {
return labels.some((label) => EXCLUDED_LABELS.includes(label.name.toLowerCase()));
}

/**
* Gets the name of the excluded label, if any.
* @param {string[]} labels - Array of PR labels
* @returns {string|undefined} - The name of the excluded label, if any
*/
function getExcludedLabel(labels) {
return labels.find((label) => EXCLUDED_LABELS.includes(label.name.toLowerCase()))?.name;
}
Loading
Loading