Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: examples should follow Conventional Commits conventions #259

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .releaserc.json
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]"
}]
]
}
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -7,10 +7,10 @@ Used by: [Electron](https://github.com/electron/electron) · [Vite](https://gith
## Examples

**Valid pull request titles:**
- fix: Correct typo
- feat: Add support for Node.js 18
- refactor!: Drop support for Node.js 12
- feat(ui): Add `Button` component
- fix: correct typo
- feat: add support for Node.js 18
- refactor!: drop support for Node.js 12
- feat(ui): add `Button` component

> Note that since pull request titles only have a single line, you have to use `!` to indicate breaking changes.

Expand Down Expand Up @@ -117,7 +117,7 @@ For work-in-progress PRs you can typically use [draft pull requests from GitHub]
**Example:**

```
[WIP] feat: Add support for Node.js 18
[WIP] feat: add support for Node.js 18
```

This will prevent the PR title from being validated, and pull request checks will remain pending.
Expand Down
6 changes: 5 additions & 1 deletion src/validatePrTitle.js
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)}`;
Copy link
Author

@tkrotoff tkrotoff Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

After:

Available types:
 - feat: a new feature
 - fix: a bug fix
 - docs: documentation only changes
 - style: changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: a code change that neither fixes a bug nor adds a feature
 - perf: a code change that improves performance
 - test: adding missing tests or correcting existing tests
 - build: changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: other changes that don't modify src or test files
 - revert: reverts a previous commit

}

return bullet;
Expand Down
32 changes: 16 additions & 16 deletions src/validatePrTitle.test.js
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