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

chore: move commitizen config to commitlint; #1835

Open
wants to merge 1 commit into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
run: npm ci
- name: Bootstrap project
run: npm run bootstrap
- name: Lint commit
run: npm run lint:commit
- name: Lint commits
run: npm run lint:commits
- name: Lint code
run: npm run lint:changes
vitest-tests:
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run lint:commit
npx --no -- commitlint --edit $1
1 change: 0 additions & 1 deletion .husky/pre-push

This file was deleted.

17 changes: 16 additions & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
exec < /dev/tty && npx cz --hook || true
# Don't run this hook on --amend or rebase
# From https://github.com/commitizen/cz-cli/issues/672#issuecomment-1328123802
#
# Explanation:
# Per the [prepare-commit-msg hook docs](https://git-scm.com/docs/githooks#_prepare_commit_msg),
# the second argument can have these values:
# - Empty: No message supplied
# - "message": Message was supplied via -m or -F
# - "template": Template was supplied via -t or via commit.template git config
# - "merge": Commit is a merge commit or .git/MERGE_MSG file exists
# - "squash": .git/SQUASH_MSG file exists
# - "commit": -c, -C, or --amend was supplied. In this case, the script gets a third argument representing the commit object.

if [ -z "$2" ]; then
exec < /dev/tty && npx cz --hook
fi
78 changes: 59 additions & 19 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,71 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')

const ignoredPackages = ['__docs__', '__examples__']

function getChangedPackages() {
try {
const output = execSync('git diff --cached --name-only', {
encoding: 'utf-8'
})
return Array.from(
new Set(
output
.split('\n')
.filter((line) => line.startsWith('packages/'))
.map((line) => line.split('/')[1])
.filter((pkg) => !ignoredPackages.includes(pkg))
)
)
} catch (error) {
console.error(error.message)
return []
}
}

function getAllPackages() {
try {
const packagesDir = path.resolve('packages')
return fs
.readdirSync(packagesDir)
.filter(
(pkg) =>
fs.statSync(path.join(packagesDir, pkg)).isDirectory() &&
!ignoredPackages.includes(pkg)
)
} catch (error) {
console.error(error.message)
return []
}
}

module.exports = {
extends: ['@commitlint/config-conventional'],
parserOpts: {
headerPattern: /^(\w*)\((\w*)\)-(\w*)\s(.*)$/,
headerCorrespondence: ['type', 'scope', 'subject']
},
// see https://commitlint.js.org/#/reference-rules
// https://commitlint.js.org/reference/rules.html
rules: {
'type-enum': [
2,
'always',
[
'WIP',
'feat',
'fix',
'docs',
'chore',
'style',
'refactor',
'test',
'perf',
'revert'
]
],
'type-case': [0],
'header-max-length': [0, 'always', 150] // commit message first field (subject) length
'header-max-length': [2, 'always', 150]
},

// https://cz-git.qbb.sh/config/
prompt: {
enableMultipleScopes: true,
scopeEnumSeparator: ',',
scopes: getAllPackages(),
defaultScope: getChangedPackages(),
skipQuestions: ['footerPrefix', 'confirmCommit'],
// If more than 3 packages are selected display 'many', e.g. `refactor(many): some message`
formatMessageCB: ({ scope, defaultMessage }) =>
scope.split(',').length > 3
? defaultMessage.replace(scope, 'many')
: defaultMessage
}
}
Loading
Loading