Skip to content

Commit 3c7c482

Browse files
committed
feat: add max-header-length for header length check
- disable default header length check - update dependency actions version - add release details on contributing file
1 parent b428eea commit 3c7c482

File tree

22 files changed

+372
-120
lines changed

22 files changed

+372
-120
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Github CI
22

33
on:
44
push:
5-
branches: ['main']
5+
branches: ["main"]
66
pull_request:
77

88
jobs:
@@ -11,13 +11,13 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ['3.10']
14+
python-version: ["3.10"]
1515

1616
steps:
17-
- uses: actions/checkout@v4
17+
- uses: actions/checkout@v6
1818

1919
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v5
20+
uses: actions/setup-python@v6
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323

@@ -38,7 +38,7 @@ jobs:
3838
poetry run pytest --cov=src/ --cov-report=xml --no-cov-on-fail
3939
4040
- name: Send coverage to CodeCov
41-
uses: codecov/codecov-action@v3
41+
uses: codecov/codecov-action@v5
4242
with:
4343
token: ${{ secrets.CODECOV_TOKEN }}
4444
fail_ci_if_error: false
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: Commitlint
22

33
on:
44
push:
5-
branches: ['main']
5+
branches: ["main"]
66
pull_request:
77

88
jobs:
99
commitlint:
1010
runs-on: ubuntu-latest
1111
name: Commitlint
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v6
1414

1515
- name: Run commitlint
1616
# uses: opensource-nepal/commitlint@v1

.github/workflows/release-please.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
on:
22
push:
3-
branches: ['main']
3+
branches: ["main"]
44

55
name: release-please
66

77
jobs:
88
release-please:
99
runs-on: ubuntu-latest
1010
permissions:
11+
# This job has the highest privileges, so always pin actions to a specific commit hash.
12+
# Ensure the referenced commit hash is verified and free from known vulnerabilities.
1113
id-token: write # for PYPI release
1214
contents: write
1315
pull-requests: write
1416

1517
steps:
1618
- name: Release
1719
id: release
18-
uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
20+
uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0
1921

20-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v6
2123
if: ${{ steps.release.outputs.release_created }}
2224

2325
- name: tag major and minor versions
@@ -32,10 +34,10 @@ jobs:
3234
git push origin v${{ steps.release.outputs.major }} -f
3335
3436
- name: Set up Python
35-
uses: actions/setup-python@v5
37+
uses: actions/setup-python@v6
3638
if: ${{ steps.release.outputs.release_created }}
3739
with:
38-
python-version: '3.x'
40+
python-version: "3.10"
3941

4042
- name: Install dependencies
4143
if: ${{ steps.release.outputs.release_created }}

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: 15 additions & 9 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,18 @@ 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
34-
uses: actions/setup-python@v5.1.0
37+
# Use a specific version for action dependencies
38+
# A commitlint action version should use fixed dependency versions (not mutable versions)
39+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
3540
with:
36-
python-version: '3.10'
41+
python-version: "3.10"
3742

3843
- name: Commitlint Action
3944
id: commitlint
@@ -46,3 +51,4 @@ runs:
4651
INPUT_TOKEN: ${{ inputs.token }}
4752
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
4853
INPUT_VERBOSE: ${{ inputs.verbose }}
54+
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

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_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_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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ 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+
val = get_input(key)
70+
71+
if val == "":
72+
# GitHub Action passes empty data as a empty string ("")
73+
return None
74+
75+
try:
76+
return int(val)
77+
except ValueError:
78+
raise ValueError(f"Input '{key}' must be a valid integer.") from None
79+
80+
5981
def write_line_to_file(filepath: str, line: str) -> None:
6082
"""
6183
Write line to a specified filepath.

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. Specially 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)