From dc9ab8fcb9e324ec668709c459d0f55ef3e109b9 Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Wed, 3 Apr 2024 11:48:43 +0200 Subject: [PATCH] fix: further switch to Convention Commits --- .releaserc.json | 2 +- src/validatePrTitle.js | 6 +++++- src/validatePrTitle.test.js | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.releaserc.json b/.releaserc.json index a7f2a663f..72143f875 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -12,7 +12,7 @@ }], ["@semantic-release/git", { "assets": ["dist", "CHANGELOG.md"], - "message": "chore: Release ${nextRelease.version} [skip ci]" + "message": "chore: release ${nextRelease.version} [skip ci]" }] ] } diff --git a/src/validatePrTitle.js b/src/validatePrTitle.js index 6dff4ac79..292f15f1e 100644 --- a/src/validatePrTitle.js +++ b/src/validatePrTitle.js @@ -30,13 +30,17 @@ module.exports = async function validatePrTitle( } const result = parser(prTitle, parserOpts); + function removeCapitalLetter(text) { + return text.charAt(0).toLowerCase() + text.substring(1); + } + function printAvailableTypes() { return `Available types:\n${types .map((type) => { let bullet = ` - ${type}`; if (types === defaultTypes) { - bullet += `: ${conventionalCommitTypes.types[type].description}`; + bullet += `: ${removeCapitalLetter(conventionalCommitTypes.types[type].description)}`; } return bullet; diff --git a/src/validatePrTitle.test.js b/src/validatePrTitle.test.js index 6575b287c..05419026e 100644 --- a/src/validatePrTitle.test.js +++ b/src/validatePrTitle.test.js @@ -2,11 +2,11 @@ const validatePrTitle = require('./validatePrTitle'); it('allows valid PR titles that use the default types', async () => { const inputs = [ - 'fix: Fix bug', - 'fix!: Fix bug', - 'feat: Add feature', - 'feat!: Add feature', - 'refactor: Internal cleanup' + 'fix: fix bug', + 'fix!: fix bug', + 'feat: add feature', + 'feat!: add feature', + 'refactor: internal cleanup' ]; for (let index = 0; index < inputs.length; index++) { @@ -40,7 +40,7 @@ it('throws for PR titles with an unknown type', async () => { describe('defined scopes', () => { it('allows a missing scope by default', async () => { - await validatePrTitle('fix: Bar'); + await validatePrTitle('fix: bar'); }); it('allows all scopes by default', async () => { @@ -48,7 +48,7 @@ describe('defined scopes', () => { }); it('allows a missing scope when custom scopes are defined', async () => { - await validatePrTitle('fix: Bar', {scopes: ['foo']}); + await validatePrTitle('fix: bar', {scopes: ['foo']}); }); it('allows a matching scope', async () => { @@ -132,12 +132,12 @@ describe('defined scopes', () => { it('throws when a scope is missing', async () => { await expect( - validatePrTitle('fix: Bar', { + validatePrTitle('fix: bar', { scopes: ['foo', 'bar'], requireScope: true }) ).rejects.toThrow( - 'No scope found in pull request title "fix: Bar". Scope must match one of: foo, bar.' + 'No scope found in pull request title "fix: bar". Scope must match one of: foo, bar.' ); }); }); @@ -253,12 +253,12 @@ describe('defined scopes', () => { it('throws when a scope is missing', async () => { await expect( - validatePrTitle('fix: Bar', { + validatePrTitle('fix: bar', { requireScope: true }) ).rejects.toThrow( // Should make no mention of any available scope - /^No scope found in pull request title "fix: Bar".$/ + /^No scope found in pull request title "fix: bar".$/ ); }); }); @@ -277,9 +277,9 @@ describe('custom types', () => { it('throws for PR titles with an unknown type', async () => { await expect( - validatePrTitle('fix: Foobar', {types: ['foo', 'bar']}) + validatePrTitle('fix: foobar', {types: ['foo', 'bar']}) ).rejects.toThrow( - 'Unknown release type "fix" found in pull request title "fix: Foobar".' + 'Unknown release type "fix" found in pull request title "fix: foobar".' ); }); }); @@ -332,11 +332,11 @@ describe('description validation', () => { it('throws for only partial matches', async () => { await expect( - validatePrTitle('fix: Foobar', { - subjectPattern: 'Foo' + validatePrTitle('fix: foobar', { + subjectPattern: 'foo' }) ).rejects.toThrow( - 'The subject "Foobar" found in pull request title "fix: Foobar" isn\'t an exact match for the configured pattern "Foo". Please provide a subject that matches the whole pattern exactly.' + 'The subject "foobar" found in pull request title "fix: foobar" isn\'t an exact match for the configured pattern "foo". Please provide a subject that matches the whole pattern exactly.' ); });