Skip to content

Commit

Permalink
fix: further switch to Convention Commits
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrotoff committed Apr 3, 2024
1 parent 90bd769 commit dc9ab8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
}]
]
}
6 changes: 5 additions & 1 deletion src/validatePrTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions src/validatePrTitle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -40,15 +40,15 @@ 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 () => {
await validatePrTitle('fix(core): Bar');
});

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 () => {
Expand Down Expand Up @@ -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.'
);
});
});
Expand Down Expand Up @@ -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".$/
);
});
});
Expand All @@ -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".'
);
});
});
Expand Down Expand Up @@ -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.'
);
});

Expand Down

0 comments on commit dc9ab8f

Please sign in to comment.