|
1 |
| -# commitlint |
| 1 | +# Conventional Commitlint |
2 | 2 |
|
3 | 3 | [](https://badge.fury.io/py/commitlint)
|
4 | 4 | [](https://github.com/opensource-nepal/commitlint/actions)
|
5 | 5 | [](https://pypi.org/project/commitlint/)
|
6 | 6 | [](https://codecov.io/github/opensource-nepal/commitlint)
|
7 | 7 | [](https://github.com/opensource-nepal/commitlint/blob/main/LICENSE)
|
8 | 8 |
|
9 |
| -commitlint is a tool designed to lint your commit messages according to the [Conventional Commits](https://www.conventionalcommits.org/) standard for your pre-commit hook and GitHub Actions. |
| 9 | +`commitlint` is a tool that lints commit messages according to the [Conventional Commits](./docs/conventional-commits.md) standard. It can be used in GitHub Actions and as a pre-commit hook. |
10 | 10 |
|
11 |
| -## Conventional Commits |
| 11 | +## Usage |
12 | 12 |
|
13 |
| -A conventional commit message follows a specific format that includes a prefix indicating the type of change, an optional scope for context, and a concise description of the modification. |
14 |
| -This structure improves readability, facilitates automated changelog generation, and ensures a consistent commit history. |
| 13 | +### GitHub Actions |
15 | 14 |
|
16 |
| -The commit message should follow this structure: |
17 |
| - |
18 |
| -``` |
19 |
| -<type>(<optional scope>): <description> |
20 |
| -
|
21 |
| -[Optional body] |
22 |
| -``` |
23 |
| - |
24 |
| -**Type:** Indicates the type of change, such as build, ci, docs, feat, fix, perf, refactor, style, test, chore, revert, or bump. |
25 |
| -E.g., `feat: add JSON parser`. |
26 |
| - |
27 |
| -**Scope:** Additional contextual information. |
28 |
| -E.g., `feat(parser): add JSON parser`. |
29 |
| - |
30 |
| -**Description:** Brief description of the commit. |
31 |
| - |
32 |
| -**Body:** A detailed description of the commit. |
33 |
| - |
34 |
| -For more details, please refer to the Conventional Commits specification at https://www.conventionalcommits.org/en/v1.0.0/ |
35 |
| - |
36 |
| -> NOTE: commitlint also checks the length of the commit header (**max 72 characters**). The commit header refers to the first line of the commit message (excluding the body). |
37 |
| -
|
38 |
| -## How to use |
39 |
| - |
40 |
| -### For pre-commit |
41 |
| - |
42 |
| -1. Add the following configuration on `.pre-commit-config.yaml`. |
43 |
| - |
44 |
| - ```yaml |
45 |
| - repos: |
46 |
| - ... |
47 |
| - - repo: https://github.com/opensource-nepal/commitlint |
48 |
| - rev: v1.2.0 |
49 |
| - hooks: |
50 |
| - - id: commitlint |
51 |
| - ... |
52 |
| - ``` |
53 |
| - |
54 |
| -2. Install the `commit-msg` hook in your project repo: |
55 |
| - |
56 |
| - ```bash |
57 |
| - pre-commit install --hook-type commit-msg |
58 |
| - ``` |
59 |
| - |
60 |
| - Installing using only `pre-commit install` will not work. |
61 |
| - |
62 |
| -> **_NOTE:_** Avoid using commit messages that start with '#'. |
63 |
| -> This might result in unexpected behavior with commitlint. |
64 |
| -
|
65 |
| -### For GitHub Actions |
66 |
| - |
67 |
| -If you have any existing workflows, add the following steps: |
| 15 | +If you have an existing workflow, add the following steps: |
68 | 16 |
|
69 | 17 | ```yaml
|
70 | 18 | ...
|
71 | 19 | steps:
|
72 | 20 | ...
|
73 |
| - - name: Run commitlint |
| 21 | + |
| 22 | + - name: Conventional Commitlint |
74 | 23 | uses: opensource-nepal/commitlint@v1
|
| 24 | + |
75 | 25 | ...
|
76 | 26 | ```
|
77 | 27 |
|
78 |
| -If you don't have any workflows, create a new GitHub workflow, e.g. `.github/workflows/commitlint.yaml`. |
| 28 | +If you don't have any workflows, create a new GitHub workflow file, e.g., `.github/workflows/commitlint.yaml`: |
79 | 29 |
|
80 | 30 | ```yaml
|
81 |
| -name: Commitlint |
| 31 | +name: Conventional Commitlint |
82 | 32 |
|
83 | 33 | on:
|
84 | 34 | push:
|
|
88 | 38 | jobs:
|
89 | 39 | commitlint:
|
90 | 40 | runs-on: ubuntu-latest
|
91 |
| - name: Commitlint |
| 41 | + name: Conventional Commitlint |
92 | 42 | steps:
|
93 |
| - - name: Run commitlint |
| 43 | + - name: Conventional Commitlint |
94 | 44 | uses: opensource-nepal/commitlint@v1
|
95 | 45 | ```
|
96 | 46 |
|
97 |
| -> **_NOTE:_** commitlint GitHub Actions will only be triggered by "push", "pull_request", or "pull_request_target" events. The difference between "pull_request" and "pull_request_target" is that "pull_request" is more secure for public repos while "pull_request_target" is necessary for private repos. |
| 47 | +> **_Note:_** The `commitlint` GitHub Action is triggered only by `push`, `pull_request`, or `pull_request_target` events. |
98 | 48 |
|
99 | 49 | #### GitHub Action Inputs
|
100 | 50 |
|
101 | 51 | | # | Name | Type | Default | Description |
|
102 | 52 | | --- | ----------------- | ------- | ---------------------- | --------------------------------------------------------------------- |
|
103 |
| -| 1 | **fail_on_error** | Boolean | `true` | Determines whether the GitHub Action should fail if commitlint fails. | |
104 |
| -| 2 | **verbose** | Boolean | `false` | Verbose output. | |
105 |
| -| 3 | **token** | String | `secrets.GITHUB_TOKEN` | Github Token for fetching commits using Github API. | |
| 53 | +| 1 | **fail_on_error** | Boolean | `true` | Whether the GitHub Action should fail if commitlint detects an issue. | |
| 54 | +| 2 | **verbose** | Boolean | `false` | Enables verbose output. | |
| 55 | +| 3 | **token** | String | `secrets.GITHUB_TOKEN` | GitHub Token for fetching commits using the GitHub API. | |
106 | 56 |
|
107 | 57 | #### GitHub Action Outputs
|
108 | 58 |
|
109 |
| -| # | Name | Type | Description | |
110 |
| -| --- | ------------- | ------- | ---------------------------------------------------------------------------- | |
111 |
| -| 1 | **exit_code** | Integer | The exit code of the commitlint step. | |
112 |
| -| 2 | **status** | String | The outcome of the commitlint step. Possible values: 'success' or 'failure'. | |
113 |
| - |
114 |
| -## CLI (Command Line Interface) |
| 59 | +| # | Name | Type | Description | |
| 60 | +| --- | ------------- | ------- | ------------------------------------------------------------ | |
| 61 | +| 1 | **exit_code** | Integer | The exit code of the commitlint step. | |
| 62 | +| 2 | **status** | String | The outcome of the commitlint step (`success` or `failure`). | |
115 | 63 |
|
116 |
| -### Installation |
| 64 | +### Pre-commit |
117 | 65 |
|
118 |
| -```shell |
119 |
| -pip install commitlint |
120 |
| -``` |
| 66 | +1. Add the following configuration to `.pre-commit-config.yaml`: |
121 | 67 |
|
122 |
| -### Usage |
123 |
| - |
124 |
| -``` |
125 |
| -commitlint [-h] [-V] [--file FILE] [--hash HASH] [--from-hash FROM_HASH] [--to-hash TO_HASH] [--skip-detail] [-q | -v] |
126 |
| - [commit_message] |
127 |
| - |
128 |
| -positional arguments: |
129 |
| - commit_message The commit message to be checked |
130 |
| - |
131 |
| -optional arguments: |
132 |
| - -h, --help show this help message and exit |
133 |
| - -V, --version show program's version number and exit |
134 |
| - --file FILE Path to a file containing the commit message |
135 |
| - --hash HASH Commit hash |
136 |
| - --from-hash FROM_HASH |
137 |
| - From commit hash |
138 |
| - --to-hash TO_HASH To commit hash |
139 |
| - --skip-detail Skip the detailed error message check |
140 |
| - -q, --quiet Ignore stdout and stderr |
141 |
| - -v, --verbose Verbose output |
142 |
| -``` |
143 |
| -
|
144 |
| -### Examples |
145 |
| -
|
146 |
| -Check commit message directly: |
147 |
| -
|
148 |
| -```shell |
149 |
| -$ commitlint "chore: my commit message" |
150 |
| -``` |
151 |
| - |
152 |
| -Check commit message from file: |
153 |
| - |
154 |
| -```shell |
155 |
| -$ commitlint --file /foo/bar/commit-message.txt |
156 |
| -``` |
157 |
| - |
158 |
| -> **_NOTE:_** For `--file` option, avoid using commit messages that start with '#'. |
159 |
| -> This might result in unexpected behavior with commitlint. |
160 |
| -
|
161 |
| -Check commit message of a hash: |
162 |
| - |
163 |
| -```shell |
164 |
| -$ commitlint --hash 9a8c08173 |
165 |
| -``` |
166 |
| - |
167 |
| -Check commit message of a hash range: |
168 |
| - |
169 |
| -```shell |
170 |
| -$ commitlint --from-hash 00bf73fef7 --to-hash d6301f1eb0 |
171 |
| -``` |
172 |
| - |
173 |
| -Check commit message skipping the detail check: |
174 |
| - |
175 |
| -```shell |
176 |
| -$ commitlint --skip-detail "chore: my commit message" |
177 |
| -# or |
178 |
| -$ commitlint --skip-detail --hash 9a8c08173 |
179 |
| -``` |
| 68 | + ```yaml |
| 69 | + repos: |
| 70 | + ... |
| 71 | + - repo: https://github.com/opensource-nepal/commitlint |
| 72 | + rev: v1.3.0 |
| 73 | + hooks: |
| 74 | + - id: commitlint |
| 75 | + ... |
| 76 | + ``` |
180 | 77 |
|
181 |
| -Run commitlint in quiet mode: |
| 78 | +2. Install the `commit-msg` hook in your project repository: |
182 | 79 |
|
183 |
| -```shell |
184 |
| -$ commitlint --quiet "chore: my commit message" |
185 |
| -``` |
| 80 | + ```bash |
| 81 | + pre-commit install --hook-type commit-msg |
| 82 | + ``` |
186 | 83 |
|
187 |
| -Run commitlint in verbose mode: |
| 84 | + Running only `pre-commit install` will not work. |
188 | 85 |
|
189 |
| -```shell |
190 |
| -$ commitlint --verbose "chore: my commit message" |
191 |
| -``` |
| 86 | +> **_Note:_** Avoid using commit messages that start with `#`, as this may cause unexpected behavior with `commitlint`. |
192 | 87 |
|
193 |
| -Version check: |
| 88 | +## CLI (Command Line Interface) |
194 | 89 |
|
195 |
| -```shell |
196 |
| -$ commitlint --version |
197 |
| -# or |
198 |
| -$ commitlint -V |
199 |
| -``` |
| 90 | +For CLI usage, please refer to [cli.md](./docs/cli.md). |
200 | 91 |
|
201 | 92 | ## Contribution
|
202 | 93 |
|
203 |
| -We appreciate feedback and contribution to this package. To get started please see our [contribution guide](./CONTRIBUTING.md). |
| 94 | +We appreciate feedback and contributions to this package. To get started, please see our [contribution guide](./CONTRIBUTING.md). |
0 commit comments