Skip to content

Commit

Permalink
chore(contributions): add conventional commits to lint pr titles (#351)
Browse files Browse the repository at this point in the history
* commitlint init

* chore(husky): initialize husky pre-commit and enforce commit-msg

* chore(contributions): add commit lint information on contributions.md

* chore(contributing): update md

* chore(workflow): add commitlint github workflow

* chore(workflow): commit lint pr title

* do not lint commit msg, just pr

* remove commitlint config from eslintignore

* re-add dev deps
  • Loading branch information
jaredvu authored Mar 7, 2024
1 parent 8446489 commit 102bc80
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
vite-env.d.ts
polyfills.ts
vite.config.ts
commitlint.config.ts

# Temporarily ignore, we will slowly remove each directory as we fix files to follow ESLint rules
/src/components
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Lint PR Title
on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up pnpm
uses: dydxprotocol/setup-pnpm@v1

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- name: Install dependencies
run: |
pnpm install @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional'], rules: { 'subject-case': [0,'always',['sentence-case']],'header-max-length': [2, 'always', 120], 'body-max-line-length': [0, 'always', 120] }};" > commitlint.config.js
- name: Lint PR Title
run: |
echo "${PR_TITLE}" | pnpx commitlint --config commitlint.config.ts
env:
PR_TITLE: '${{ github.event.pull_request.title }}'
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm test
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu
3. Make sure your code lints.
4. Issue that pull request!

## We use [Conventional Commits](https://github.com/conventional-changelog/commitlint)
We use a commit-msg hook to check if your commit messages meet the conventional commit format.

In general the pattern mostly looks like this:

`type(scope?): subject` #scope is optional; multiple scopes are supported (current delimiter options: "/", "\" and ",")

### Real world examples can look like this:
`chore: run tests on travis ci`
`fix(server): send cors headers`
`feat(blog): add comment section`

Common types according to commitlint-config-conventional can be:

build
chore
ci
docs
feat
fix
perf
refactor
revert
style
test

## Any contributions you make will be under the same License
When you submit code changes, your submissions are understood to be under the same [License](https://github.com/dydxprotocol/v4-web/blob/master/LICENSE) that covers the project.

Expand Down
1 change: 1 addition & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"ladle-p": "ladle preview",
"lint": "eslint --ext .ts,.tsx src/",
"fix-lint": "eslint --fix --ext .ts,.tsx src/",
"test": "vitest",
"test": "vitest run",
"tsc": "tsc",
"postinstall": "tar -xzC public -f tradingview/tradingview.tgz"
"postinstall": "tar -xzC public -f tradingview/tradingview.tgz",
"prepare": "husky",
"commitlint": "commitlint --edit"
},
"packageManager": "[email protected]",
"dependencies": {
Expand Down Expand Up @@ -118,6 +120,8 @@
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@dydxprotocol/v4-proto": "^3.0.0",
"@ladle/react": "^4.0.2",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand Down Expand Up @@ -149,6 +153,7 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^9.0.11",
"minimist": "^1.2.8",
"node-fetch": "^3.3.1",
"pnpm": "^8.6.6",
Expand Down
Loading

0 comments on commit 102bc80

Please sign in to comment.