-
Notifications
You must be signed in to change notification settings - Fork 0
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
(Added) Enhance commit linting process and configuration #9
base: main
Are you sure you want to change the base?
Conversation
- Expand valid footer tokens to include 'Signed-off-by' - Properly recognize and handle 'Signed-off-by' statements - Enhance compliance with version control best practices This change allows the system to correctly process 'Signed-off-by' lines in commit message footers, improving adherence to industry standards for version control and collaboration workflows. Signed-off-by: Marjo van Lier <[email protected]>
The indentation of the example commit message syntax in the main.py file was incorrect. This commit removes the leading spaces so the markdown syntax is recognised correctly, accurately conveying the example formatting of commit messages. Signed-off-by: Marjo van Lier <[email protected]>
- Rename `commit_message_validator` to `first_commit_message_validator` - Introduce `second_commit_message_validator` using commitlint CLI - Update related test cases to reflect the changes - Change `manager_llm` language model to "gpt-4-turbo-preview" This commit refactors the commit message validation process to improve clarity and maintainability. The validation is split into two distinct steps, allowing for more flexibility and the ability to apply different validation approaches as needed. The related test cases are updated to account for these changes. Additionally, the `manager_llm` language model is updated to "gpt-4-turbo-preview". Signed-off-by: Marjo van Lier <[email protected]>
- Ignore node_modules directory to keep repository clean - Incorporate .commitlintrc.json to enforce commit style guidelines - Add commitlint and config-conventional as dev dependencies Signed-off-by: Marjo van Lier <[email protected]>
- Introduce minimum length rules for commit subject and header - Require subject and header to have at least 10 characters - Improve commit message quality and consistency The commitlint configuration has been updated to enforce minimum length requirements for the commit message subject line and header. This change ensures that commit messages provide sufficient detail and context, enhancing the overall quality of the commit history. Signed-off-by: Marjo van Lier <[email protected]>
The .commitlintrc.json file has been amended to present the commitlint rules in an alphabetical order. This adjustment improves readability and simplifies the management of the rules configuration. Signed-off-by: Marjo van Lier <[email protected]>
WalkthroughThis update introduces a refined commit message validation system, enhancing codebase consistency and readability. By integrating commit message linting configurations and updating validation functions, it ensures commit messages adhere to the conventional commit format. The addition of development dependencies supports this new linting process, while test adjustments align with the updated validation logic, maintaining the integrity of automated checks. Changes
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
PR Description updated to latest commit (7221ee2)
|
PR Review
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review Status
Configuration used: CodeRabbit UI
Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
Files selected for processing (5)
- .commitlintrc.json (1 hunks)
- .gitignore (1 hunks)
- main.py (11 hunks)
- package.json (1 hunks)
- test_validator.py (7 hunks)
Files skipped from review due to trivial changes (2)
- .commitlintrc.json
- .gitignore
Additional comments not posted (4)
package.json (1)
2-5
: The addition of@commitlint/cli
and@commitlint/config-conventional
as development dependencies with version ranges specified using carets is a good practice. This approach allows for automatic updates to newer minor versions, which can include important fixes and improvements.test_validator.py (1)
137-234
: > 📝 NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [4-231]
The update from
commit_message_validator
tofirst_commit_message_validator
across all test cases is consistent and correctly implemented. Ensure that thefirst_commit_message_validator
function inmain.py
is implemented as expected to match these test scenarios.main.py (2)
137-147
: > 📝 NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [42-144]
The implementation of
first_commit_message_validator
is comprehensive and aligns well with the Conventional Commits specification. It's a good practice to return a dictionary with errors, suggestions, and a validity status. However, consider refining the handling of footer tokens to ensure extensibility. For instance, you might want to use a list or a set for allowed footer tokens to make it easier to add new ones in the future.
347-353
: > 📝 NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [321-429]
The updates to the main function and the introduction of agents and tasks for commit message analysis and suggestion are innovative and demonstrate an effort to automate the commit message validation process. However, consider the maintainability of this complex setup. Simplifying the workflow or providing detailed documentation on how each component interacts could help future developers understand and maintain the system more effectively.
@tool("Second Conventional Commit Message Validator") | ||
def second_commit_message_validator(suggested_commit_msg: str) -> str: | ||
""" | ||
Use this tool to validate that a suggested commit message follows the Conventional Commits 1.0.0 specification. | ||
""" | ||
suggested_commit_msg = suggested_commit_msg.replace('`', '\`').strip() | ||
suggested_commit_msg = suggested_commit_msg.replace('"', '\"').strip() | ||
|
||
# Get the path of where main.py is located | ||
root_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
command = 'echo "' + suggested_commit_msg + '" | ' + root_dir + '/node_modules/@commitlint/cli/cli.js -V -g ' + root_dir + '/.commitlintrc.json' | ||
|
||
print(f"Command: {command}") | ||
|
||
# Run the command to validate the commit message | ||
return_data = subprocess.getoutput(command) | ||
|
||
return_data = return_data.strip() | ||
|
||
print(f"Return data: {return_data}") | ||
|
||
return return_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second_commit_message_validator
function provides a practical approach to validating commit messages using the commitlint CLI. However, consider improving the security of command construction to prevent potential command injection vulnerabilities. Instead of direct string concatenation, use safer methods such as lists for command arguments with subprocess
functions that support them.
- command = 'echo "' + suggested_commit_msg + '" | ' + root_dir + '/node_modules/@commitlint/cli/cli.js -V -g ' + root_dir + '/.commitlintrc.json'
+ command = ['bash', '-c', f'echo "{suggested_commit_msg}" | {root_dir}/node_modules/@commitlint/cli/cli.js -V -g {root_dir}/.commitlintrc.json']
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
@tool("Second Conventional Commit Message Validator") | |
def second_commit_message_validator(suggested_commit_msg: str) -> str: | |
""" | |
Use this tool to validate that a suggested commit message follows the Conventional Commits 1.0.0 specification. | |
""" | |
suggested_commit_msg = suggested_commit_msg.replace('`', '\`').strip() | |
suggested_commit_msg = suggested_commit_msg.replace('"', '\"').strip() | |
# Get the path of where main.py is located | |
root_dir = os.path.dirname(os.path.abspath(__file__)) | |
command = 'echo "' + suggested_commit_msg + '" | ' + root_dir + '/node_modules/@commitlint/cli/cli.js -V -g ' + root_dir + '/.commitlintrc.json' | |
print(f"Command: {command}") | |
# Run the command to validate the commit message | |
return_data = subprocess.getoutput(command) | |
return_data = return_data.strip() | |
print(f"Return data: {return_data}") | |
return return_data | |
@tool("Second Conventional Commit Message Validator") | |
def second_commit_message_validator(suggested_commit_msg: str) -> str: | |
""" | |
Use this tool to validate that a suggested commit message follows the Conventional Commits 1.0.0 specification. | |
""" | |
suggested_commit_msg = suggested_commit_msg.replace('`', '\`').strip() | |
suggested_commit_msg = suggested_commit_msg.replace('"', '\"').strip() | |
# Get the path of where main.py is located | |
root_dir = os.path.dirname(os.path.abspath(__file__)) | |
command = ['bash', '-c', f'echo "{suggested_commit_msg}" | {root_dir}/node_modules/@commitlint/cli/cli.js -V -g {root_dir}/.commitlintrc.json'] | |
print(f"Command: {command}") | |
# Run the command to validate the commit message | |
return_data = subprocess.getoutput(command) | |
return_data = return_data.strip() | |
print(f"Return data: {return_data}") | |
return return_data |
User description
Summary
This merge request introduces improvements to the project's commit linting process and configuration. It adds a new
last_commit
script in thebin
directory to streamline the linting process and makes adjustments to the commitlint configuration file (.commitlintrc.json
) to enforce a consistent commit structure and promote cleaner, more informative commit messages.Context and Background
Commit linting is an essential practice to maintain a consistent and meaningful commit history. By enforcing a standardized commit message format, it becomes easier to understand the purpose and scope of each commit. The existing commitlint configuration required enhancements to focus on the most important aspects of commit style and ensure a consistent structure across all commits.
Related resources:
Problem Description
The current commit linting process lacked a dedicated script to streamline the execution of commitlint with the appropriate configuration file. Additionally, the commitlint configuration included unused rules and needed improvements to enforce a consistent commit structure and promote cleaner, more informative commit messages.
Solution Description
The introduced changes address the identified issues in the following ways:
A new
last_commit
script is added to thebin
directory. This script determines the full path to its location and constructs the appropriatecommitlint
command using the project's configuration file. It enhances robustness by exiting immediately if any invoked command fails or if any required variable is unset.The commitlint configuration file (
.commitlintrc.json
) is updated to remove unused rules and focus on the essential aspects of commit style. New rules are introduced to enforce a consistent commit structure, such as minimum and maximum lengths for the header, subject, and body.The severity level of the "scope-empty" rule is changed from an error (2) to a warning (1). This adjustment allows commits with empty scopes to proceed but displays a warning message to encourage the inclusion of a scope when appropriate.
The rules in the configuration file are reordered to improve organization and readability.
List of Changes
last_commit
script to streamline commit linting processType
enhancement, documentation
Description
commit_message_validator
tofirst_commit_message_validator
and introducedsecond_commit_message_validator
for enhanced commit message validation.@commitlint/cli
and@commitlint/config-conventional
as dev dependencies.Changes walkthrough
main.py
Enhance commit message validation and support 'Signed-off-by'
main.py
commit_message_validator
tofirst_commit_message_validator
.second_commit_message_validator
for additional commitmessage validation.
test_validator.py
Update test cases for commit message validator renaming
test_validator.py
commit_message_validator
to
first_commit_message_validator
..commitlintrc.json
Add commitlint configuration for commit message validation
.commitlintrc.json
message validation.
package-lock.json
Add commitlint dependencies
package-lock.json
@commitlint/cli
and@commitlint/config-conventional
.package.json
Add commitlint dev dependencies
package.json
@commitlint/cli
and@commitlint/config-conventional
as devdependencies.
Summary by CodeRabbit
.gitignore
to exclude/node_modules/
.