Skip to content

Commit be9b5b3

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 b475c54 commit be9b5b3

File tree

21 files changed

+242
-67
lines changed

21 files changed

+242
-67
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
steps:
1616
- name: Release
1717
id: release
18-
uses: googleapis/release-please-action@7987652d64b4581673a76e33ad5e98e3dd56832f # v4.1.3
18+
uses: googleapis/release-please-action@v4
1919

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

2323
- name: tag major and minor versions
@@ -32,10 +32,10 @@ jobs:
3232
git push origin v${{ steps.release.outputs.major }} -f
3333
3434
- name: Set up Python
35-
uses: actions/setup-python@v5
35+
uses: actions/setup-python@v6
3636
if: ${{ steps.release.outputs.release_created }}
3737
with:
38-
python-version: '3.x'
38+
python-version: '3.10'
3939

4040
- name: Install dependencies
4141
if: ${{ steps.release.outputs.release_created }}
@@ -49,4 +49,4 @@ jobs:
4949

5050
- name: Publish package
5151
if: ${{ steps.release.outputs.release_created }}
52-
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
52+
uses: pypa/gh-action-pypi-publish@v1.13.0

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. Skips header length check if empty |
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
description: Verbose output.
1111
default: 'false'
1212
required: false
13+
max_header_length:
14+
description: Check maximum header length.
15+
required: false
1316
token:
1417
description: Token for fetching commits using Github API.
1518
default: ${{ github.token }}
@@ -31,7 +34,9 @@ runs:
3134
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:
3641
python-version: '3.10'
3742

@@ -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:
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ 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 not val:
72+
return None
73+
74+
try:
75+
return int(val)
76+
except ValueError:
77+
return None
78+
79+
5980
def write_line_to_file(filepath: str, line: str) -> None:
6081
"""
6182
Write line to a specified filepath.

src/commitlint/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ def get_args() -> argparse.Namespace:
9494
default=False,
9595
)
9696

97+
# --max-header-length : enables header length check (optional)
98+
parser.add_argument(
99+
"--max-header-length",
100+
type=int,
101+
help="Maximum header length to check",
102+
default=None,
103+
)
104+
97105
# parsing args
98106
args = parser.parse_args()
99107

@@ -222,6 +230,7 @@ def main() -> None:
222230
# setting config based on args
223231
config.quiet = args.quiet
224232
config.verbose = args.verbose
233+
config.max_header_length = args.max_header_length
225234

226235
console.verbose("starting commitlint")
227236
try:

0 commit comments

Comments
 (0)