Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip the header length check and configure header length #68

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

golesuman
Copy link
Collaborator

@golesuman golesuman commented Dec 4, 2024

Description

Allow the users to make the header length configurable and also allow disable header length check using a flag.

Introduced two flags

--max-header-length
--disable-header-length-check

Related Issue

Fixes #67

Type of Change

Please mark the appropriate option below to describe the type of change your pull request introduces:

  • Bug fix
  • New feature
  • Enhancement
  • Documentation update
  • Refactor
  • Other (please specify)

Checklist

  • My pull request has a clear title and description.
  • I have used semantic commit messages.
    Examples: "fix: Fixed foobar bug", "feat(accounts): Added foobar feature".
  • I have added/updated the necessary documentation on README.md.
  • I have added appropriate test cases (if applicable) to ensure the changes are functioning correctly.

Additional Notes

There is one issue with HEADER_LENGTH_ERROR be cause of COMMIT_HEADER_MAX_LENGTH constant.

I tried to set "%s" in the message but it seems to fail the tests because of fixers LINTER_FIXTURE_PARAMS and we need some way to pass the value to this fixture .

By submitting this pull request, I confirm that I have read and complied with the contribution guidelines of this project.

@golesuman golesuman force-pushed the fix/char-length-limit-and-skip-length-check branch from 8fc9baa to 3a4539f Compare December 4, 2024 10:43
@aj3sh
Copy link
Member

aj3sh commented Dec 17, 2024

Hi @golesuman, Thanks for your contribution. Any updates on this PR? I haven't reviewed the PR since it's in the draft.

@golesuman
Copy link
Collaborator Author

golesuman commented Dec 18, 2024

Hi @golesuman, Thanks for your contribution. Any updates on this PR? I haven't reviewed the PR since it's in the draft.

Hi @aj3sh. Could you review if the approach is okay ? It looks kinda hacky to be honest. I couldn't update fixtures to actually test the dynamic max header length as I mentioned above in the additional notes because of my schedule. If it looks good then we can actually do something about the test part :)

Copy link
Member

@aj3sh aj3sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the current changes and will look into the issue regarding the header length error.

Additionally, if the header length check is not disabled by default, the issue will remain unresolved since no changes have been made to the GitHub Actions. Therefore, I suggest disabling the header length check by default. The changes to GitHub Actions can be addressed later in this case.

"--max-header-length", help="commit message header max length"
)
output_group.add_argument(
"--disable-header-length-check",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Let's make the length check optional by default and add the option --check-header-length for the header length check.

The length limit is not even on the conventional commit spec.

@@ -85,6 +84,14 @@ def get_args() -> argparse.Namespace:
default=False,
)

output_group.add_argument(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: output_group is for verbose and quiet only.

@@ -224,6 +249,14 @@ def main() -> None:
config.verbose = args.verbose

console.verbose("starting commitlint")

if args.max_header_length and args.disable_header_length_check:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: these can be achieved through argsparse groups.

validator_instances.append(
HeaderLengthValidator(
commit_message=commit_message,
**{"max_header_length": max_header_length}, # type: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This will work too.

Suggested change
**{"max_header_length": max_header_length}, # type: ignore
max_header_length=max_header_length,

@@ -50,6 +50,7 @@ def is_valid(self) -> bool:
"""Checks if there are any errors."""
return len(self._errors) == 0

@property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@property fits perfectly here.

console.verbose("running detailed validators for linting")
return run_validators(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I never thought the task was going to be this tough. I have a few alternative suggestions that are effective and require fewer code changes.

However, our tool has a config for storing such configurations. It's already been implemented for verbose and quiet options, you can check that. With that said, the changes will only be on HeaderLengthValidator where the actual validator runs.

@aj3sh aj3sh added the stale label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commitlint fails after squash merge
2 participants