From 80f4a3719423e26158c3d71abf4c9ba5a915ee76 Mon Sep 17 00:00:00 2001 From: Rajasimman S Date: Fri, 25 Apr 2025 14:41:18 +0530 Subject: [PATCH] chore: standardize string quotes in action.yml and commit-message-validator.js --- README.md | 5 ++++- action.yml | 17 +++++++++-------- commit-message-validator.js | 16 ++++++++-------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ba0daf1..55d8f5c 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,13 @@ You can customize the regex pattern used for validation: ## Default Conventional Commits Format The default pattern validates the following format: + ``` [optional scope]: ``` Where `type` is one of: + - feat: A new feature - fix: A bug fix - docs: Documentation changes @@ -76,4 +78,5 @@ Where `type` is one of: ## License -This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. \ No newline at end of file +This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. + diff --git a/action.yml b/action.yml index bdbb526..ad54bf6 100644 --- a/action.yml +++ b/action.yml @@ -1,17 +1,18 @@ -name: 'Conventional Commit Validator' -description: 'Validates that commit messages follow the Conventional Commits format' +name: "Conventional Commit Validator" +description: "Validates that commit messages follow the Conventional Commits format" inputs: github-token: - description: 'GitHub token for API access' + description: "GitHub token for API access" required: true default: ${{ github.token }} pattern: - description: 'Regex pattern for commit message validation' + description: "Regex pattern for commit message validation" required: false default: '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(\w+\))?: .+$' runs: - using: 'node20' - main: 'dist/index.js' + using: "node20" + main: "dist/index.js" branding: - icon: 'check-circle' - color: 'green' \ No newline at end of file + icon: "check-circle" + color: "green" + diff --git a/commit-message-validator.js b/commit-message-validator.js index 45c3324..6d6ab4a 100644 --- a/commit-message-validator.js +++ b/commit-message-validator.js @@ -7,33 +7,33 @@ async function run() { const token = core.getInput('github-token', { required: true }); const pattern = core.getInput('pattern') || '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\\(\\w+\\))?: .+$'; const regexPattern = new RegExp(pattern); - + // Create octokit client const octokit = github.getOctokit(token); const context = github.context; - + // Get current PR const pullRequest = context.payload.pull_request; if (!pullRequest) { core.info('No pull request found. Skipping commit message validation.'); return; } - + // Get commits in PR const { data: commits } = await octokit.rest.pulls.listCommits({ owner: context.repo.owner, repo: context.repo.repo, pull_number: pullRequest.number, }); - + let hasError = false; let errorMessages = []; - + // Validate each commit message commits.forEach((commit) => { const commitMessage = commit.commit.message.split('\n')[0].trim(); const sha = commit.sha.substring(0, 7); - + if (!regexPattern.test(commitMessage)) { const errorMsg = `❌ Commit ${sha} has an invalid message format: "${commitMessage}"`; core.error(errorMsg); @@ -43,7 +43,7 @@ async function run() { core.info(`✅ Commit ${sha} has a valid message: "${commitMessage}"`); } }); - + // Fail the workflow if errors are found if (hasError) { core.setFailed(`One or more commits have invalid message format.\n${errorMessages.join('\n')}\n\nPlease follow the Conventional Commits format: [optional scope]: \nExample: feat(auth): add login functionality\n\nFor more information, visit: https://www.conventionalcommits.org/`); @@ -55,4 +55,4 @@ async function run() { } } -run(); \ No newline at end of file +run();