Skip to content

Commit 28d785c

Browse files
committed
chore: improve error handling by commenting on PR with invalid commit message summary
1 parent ec7ba86 commit 28d785c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

commit-message-validator.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ async function run() {
4646

4747
// Fail the workflow if errors are found
4848
if (hasError) {
49-
core.setFailed(`One or more commits have invalid message format.\n${errorMessages.join('\n')}\n\nPlease follow the Conventional Commits format: <type>[optional scope]: <description>\nExample: feat(auth): add login functionality\n\nFor more information, visit: https://www.conventionalcommits.org/`);
49+
const errorSummary = `One or more commits have invalid message format.\n${errorMessages.join('\n')}\n\nPlease follow the Conventional Commits format: <type>[optional scope]: <description>\nExample: feat(auth): add login functionality\n\nFor more information, visit: https://www.conventionalcommits.org/`;
50+
// comment on the PR with the error summary
51+
await octokit.rest.issues.createComment({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
issue_number: pullRequest.number,
55+
body: errorSummary,
56+
});
57+
core.info('Commented on PR with error summary.');
58+
// Set the action as failed
59+
core.setFailed(errorSummary);
5060
} else {
5161
core.info('✅ All commit messages have valid format.');
5262
}

0 commit comments

Comments
 (0)