-
-
Notifications
You must be signed in to change notification settings - Fork 245
feat: implement conventional commits with commitlint validation #2686
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
Draft
Copilot
wants to merge
3
commits into
main
Choose a base branch
from
copilot/fix-2685
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no-install commitlint --edit "$1" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('commitlint configuration', () => { | ||
it('commitlint config file exists', () => { | ||
const configPath = path.join(process.cwd(), 'commitlint.config.js'); | ||
expect(fs.existsSync(configPath)).toBe(true); | ||
}); | ||
|
||
it('commit-msg hook exists and is executable', () => { | ||
const hookPath = path.join(process.cwd(), '.husky', 'commit-msg'); | ||
expect(fs.existsSync(hookPath)).toBe(true); | ||
|
||
const stats = fs.statSync(hookPath); | ||
// Check if file is executable (using bitwise AND with octal permission) | ||
expect(stats.mode & parseInt('111', 8)).toBeGreaterThan(0); | ||
}); | ||
|
||
it('commitlint is in package.json dependencies', () => { | ||
const packagePath = path.join(process.cwd(), 'package.json'); | ||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); | ||
|
||
expect(packageJson.devDependencies['@commitlint/cli']).toBeDefined(); | ||
expect( | ||
packageJson.devDependencies['@commitlint/config-conventional'], | ||
).toBeDefined(); | ||
}); | ||
|
||
it('commitlint script is in package.json', () => { | ||
const packagePath = path.join(process.cwd(), 'package.json'); | ||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8')); | ||
|
||
expect(packageJson.scripts.commitlint).toBe('commitlint --edit'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default { | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { | ||
// Allow longer commit messages for detailed explanations | ||
'body-max-line-length': [2, 'always', 100], | ||
'header-max-length': [2, 'always', 100], | ||
// Allow these conventional commit types | ||
'type-enum': [ | ||
2, | ||
'always', | ||
[ | ||
'build', // Changes that affect the build system or external dependencies | ||
'chore', // Maintenance tasks, tooling, housekeeping | ||
'ci', // Changes to CI configuration files and scripts | ||
'docs', // Documentation only changes | ||
'feat', // A new feature | ||
'fix', // A bug fix | ||
'perf', // A code change that improves performance | ||
'refactor', // A code change that neither fixes a bug nor adds a feature | ||
'revert', // Reverts a previous commit | ||
'style', // Changes that do not affect the meaning of the code | ||
'test', // Adding missing tests or correcting existing tests | ||
], | ||
], | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dosu explain to me whether this will run offline as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot explain to me whether this will run offline as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the hook will run offline! The implementation uses
npx --no-install commitlint
which ensures it only uses locally installed dependencies and won't attempt to download packages from the internet.How it works offline:
pnpm install
, commitlint and its dependencies are installed locallynpx --no-install
which restricts npx to only use already-installed packagesRequirements for offline use:
pnpm install
@commitlint/cli
and@commitlint/config-conventional
need to be available locallyThis approach ensures the hook works reliably in offline environments, CI systems, or any scenario where internet access might be restricted. The commit accedb8 addresses this specifically.