Skip to content

Commit 0f12164

Browse files
committed
feat!: add max-header-length for header length check
- [Breaking change] disable default header length check - update dependency actions version - add release details on contributing file
1 parent b428eea commit 0f12164

23 files changed

Lines changed: 494 additions & 128 deletions

.github/workflows/commitlint.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ We welcome and appreciate pull requests from the community. To contribute:
9595

9696
- Participate in the code review process and address any feedback promptly.
9797

98+
## Release
99+
100+
The release process, changelog, and versioning are managed by
101+
[release-please](https://github.com/googleapis/release-please). Versions are automatically
102+
determined based on Conventional Commit types, and the changelog is generated from commit
103+
messages.
104+
105+
The [release-please-action](https://github.com/googleapis/release-please-action) creates
106+
a release PR ([example PR](https://github.com/opensource-nepal/commitlint/pull/62)) for
107+
bug fixes and features. A new release is published only after the release PR is merged.
108+
98109
## License
99110

100111
By contributing to this project, you agree that your contributions will be licensed under the **GPL-3.0 License**.

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ steps:
2525
...
2626
```
2727

28-
If you don't have any workflows, create a new GitHub workflow file, 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.yml`:
2929

3030
```yaml
3131
name: Conventional Commitlint
@@ -70,11 +70,12 @@ Github API failed with status code 403. Response: {'message': 'Resource not acce
7070

7171
#### GitHub Action Inputs
7272

73-
| # | Name | Type | Default | Description |
74-
| --- | ----------------- | ------- | ---------------------- | --------------------------------------------------------------------- |
75-
| 1 | **fail_on_error** | Boolean | `true` | Whether the GitHub Action should fail if commitlint detects an issue. |
76-
| 2 | **verbose** | Boolean | `false` | Enables verbose output. |
77-
| 3 | **token** | String | `secrets.GITHUB_TOKEN` | GitHub Token for fetching commits using the GitHub API. |
73+
| # | Name | Type | Default | Description |
74+
| --- | --------------------- | ------- | ---------------------- | --------------------------------------------------------------------------------------------- |
75+
| 1 | **fail_on_error** | Boolean | `true` | Whether the GitHub Action should fail if commitlint detects an issue. |
76+
| 2 | **verbose** | Boolean | `false` | Enables verbose output. |
77+
| 3 | **max_header_length** | Number | | Optional. Maximum header length to check. If not specified, the header length is not checked. |
78+
| 4 | **token** | String | `secrets.GITHUB_TOKEN` | GitHub Token for fetching commits using the GitHub API. |
7879

7980
#### GitHub Action Outputs
8081

action.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
name: 'Conventional Commitlint'
2-
description: 'A GitHub Action to check conventional commit message'
1+
name: "Conventional Commitlint"
2+
description: "A GitHub Action to check conventional commit message"
33

44
inputs:
55
fail_on_error:
66
description: Whether to fail the workflow if commit messages don't follow conventions.
7-
default: 'true'
7+
default: "true"
88
required: false
99
verbose:
1010
description: Verbose output.
11-
default: 'false'
11+
default: "false"
12+
required: false
13+
max_header_length:
14+
description: "Maximum header length to check. If not specified, the header length is not checked."
1215
required: false
1316
token:
1417
description: Token for fetching commits using Github API.
@@ -24,16 +27,16 @@ outputs:
2427
value: ${{ steps.commitlint.outputs.exit_code }}
2528

2629
branding:
27-
color: 'red'
28-
icon: 'git-commit'
30+
color: "red"
31+
icon: "git-commit"
2932

3033
runs:
31-
using: 'composite'
34+
using: "composite"
3235
steps:
3336
- name: Install Python
3437
uses: actions/setup-python@v5.1.0
3538
with:
36-
python-version: '3.10'
39+
python-version: "3.10"
3740

3841
- name: Commitlint Action
3942
id: commitlint
@@ -46,3 +49,4 @@ runs:
4649
INPUT_TOKEN: ${{ inputs.token }}
4750
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
4851
INPUT_VERBOSE: ${{ inputs.verbose }}
52+
INPUT_MAX_HEADER_LENGTH: ${{ inputs.max_header_length }}

docs/cli.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,29 @@ pip install commitlint
99
## Usage
1010

1111
```
12-
commitlint [-h] [-V] [--file FILE] [--hash HASH] [--from-hash FROM_HASH] [--to-hash TO_HASH] [--skip-detail] [--hide-input]
12+
commitlint [-h] [-V] [--file FILE] [--hash HASH] [--from-hash FROM_HASH] [--to-hash TO_HASH]
13+
[--skip-detail] [--hide-input]
1314
[-q | -v]
15+
[--max-header-length MAX_HEADER_LENGTH]
1416
[commit_message]
1517
1618
Check if a commit message follows the Conventional Commits format.
1719
1820
Positional arguments:
19-
commit_message The commit message to be checked.
21+
commit_message The commit message to be checked.
2022
2123
Options:
22-
-h, --help Show this help message and exit.
23-
-V, --version Show the program's version number and exit.
24-
--file FILE Path to a file containing the commit message.
25-
--hash HASH Commit hash.
26-
--from-hash FROM_HASH Commit hash to start checking from.
27-
--to-hash TO_HASH Commit hash to check up to.
28-
--skip-detail Skip detailed error messages.
29-
--hide-input Hide input from stdout.
30-
-q, --quiet Suppress stdout and stderr.
31-
-v, --verbose Enable verbose output.
24+
-h, --help Show this help message and exit.
25+
--file FILE Path to a file containing the commit message.
26+
-V, --version Show the program's version number and exit.
27+
--hash HASH Commit hash.
28+
--from-hash FROM_HASH Commit hash to start checking from.
29+
--to-hash TO_HASH Commit hash to check up to.
30+
--skip-detail Skip detailed error messages.
31+
--hide-input Hide input from stdout.
32+
-q, --quiet Suppress stdout and stderr.
33+
-v, --verbose Enable verbose output.
34+
--max-header-length LENGTH Maximum header length to check.
3235
```
3336

3437
## Examples
@@ -79,6 +82,12 @@ Run `commitlint` in verbose mode:
7982
$ commitlint --verbose "chore: my commit message"
8083
```
8184

85+
Run `commitlint` with maximum header length check:
86+
87+
```shell
88+
$ commitlint --max-header-length 72 "chore: my commit message"
89+
```
90+
8291
Check the version:
8392

8493
```shell

docs/conventional-commits.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ E.g., `feat(parser): add JSON parser`.
2222
**Body:** A detailed description of the commit.
2323

2424
For more details, please refer to the Conventional Commits specification at https://www.conventionalcommits.org/en/v1.0.0/
25-
26-
> 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).

github_actions/action/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .utils import (
1313
get_boolean_input,
1414
get_input,
15+
get_positive_int_input,
1516
request_github_api,
1617
write_line_to_file,
1718
write_output,
@@ -26,6 +27,7 @@
2627
INPUT_TOKEN = "token"
2728
INPUT_FAIL_ON_ERROR = "fail_on_error"
2829
INPUT_VERBOSE = "verbose"
30+
INPUT_MAX_HEADER_LENGTH = "max_header_length"
2931

3032
# Status
3133
STATUS_SUCCESS = "success"
@@ -115,6 +117,10 @@ def run_commitlint(commit_message: str) -> Tuple[bool, Optional[str]]:
115117
if verbose:
116118
commands.append("--verbose")
117119

120+
max_header_length = get_positive_int_input(INPUT_MAX_HEADER_LENGTH)
121+
if max_header_length is not None:
122+
commands.extend(["--max-header-length", str(max_header_length)])
123+
118124
output = subprocess.check_output(commands, text=True, stderr=subprocess.PIPE)
119125
if output:
120126
sys.stdout.write(f"{output}")

github_actions/action/utils.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,52 @@ def get_boolean_input(key: str) -> bool:
5656
)
5757

5858

59+
def get_int_input(key: str) -> int | None:
60+
"""
61+
Read the GitHub action integer input.
62+
63+
Args:
64+
key: Input key.
65+
66+
Returns:
67+
The integer value of the input. If not integer, returns None
68+
69+
Raises:
70+
ValueError: If the value is a non-empty, non-integer string.
71+
"""
72+
val = get_input(key)
73+
74+
if val == "":
75+
# GitHub Action passes empty data as a empty string ("")
76+
return None
77+
78+
try:
79+
return int(val)
80+
except ValueError:
81+
raise ValueError(f"Input '{key}' must be a valid integer.") from None
82+
83+
84+
def get_positive_int_input(key: str) -> int | None:
85+
"""
86+
Read the GitHub action integer input.
87+
88+
Args:
89+
key: Input key.
90+
91+
Returns:
92+
The integer value of the input. If not integer, returns None
93+
94+
Raises:
95+
ValueError: If the value is a non-empty, non-integer string.
96+
"""
97+
int_val = get_int_input(key)
98+
99+
if int_val is not None and int_val <= 0:
100+
raise ValueError(f"Input '{key}' must be a positive integer.")
101+
102+
return int_val
103+
104+
59105
def write_line_to_file(filepath: str, line: str) -> None:
60106
"""
61107
Write line to a specified filepath.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ requires = ["poetry-core"]
4848
build-backend = "poetry.core.masonry.api"
4949

5050
[tool.pytest.ini_options]
51-
pythonpath = "src"
51+
pythonpath = [".", "src"]
5252
testpaths = ["tests"]
5353
python_files = "test_*.py"
5454
addopts = "-vvv"

src/commitlint/app_params.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Module for AppParams"""
2+
3+
from dataclasses import dataclass
4+
5+
6+
@dataclass
7+
class AppParams:
8+
"""
9+
Represents runtime parameters that control linting behavior and output handling.
10+
11+
These parameters are typically derived from CLI arguments and define how
12+
commit messages are validated and displayed.
13+
"""
14+
15+
# Skips the detailed error check (fails immediately without detail error message).
16+
skip_detail: bool = False
17+
18+
# Hide input from stdout/stderr. Specifically used by GitHub Actions.
19+
hide_input: bool = False
20+
21+
# Maximum header length to check. If not specified, the header length is not checked.
22+
max_header_length: int | None = None
23+
24+
# Remove comments from the commit message.
25+
strip_comments: bool = False

0 commit comments

Comments
 (0)