Skip to content

Conversation

@minhuinie
Copy link
Contributor

Description

Please briefly describe the code changes in this pull request.

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @minhuinie, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the existing test file validation system by extending its capabilities to include shell scripts. It introduces a new set of functions designed to parse and enforce documentation standards for shell script docstrings, specifically those using the HERE document format. This ensures that shell scripts adhere to the same level of documentation quality and consistency as Python test files, improving maintainability and clarity across the codebase.

Highlights

  • Shell Script Docstring Validation: Introduced comprehensive validation for docstrings within shell scripts, ensuring they follow a defined structure and contain necessary information.
  • Field-Specific Checks for Shell Scripts: Added new utility functions (check_required_field_shell, check_optional_field_shell) to specifically verify the presence, format, and content of required (e.g., 'Since') and optional (e.g., 'Labels', 'Jira') fields in shell script docstrings.
  • Unified Validation Dispatch: The main validation script now intelligently dispatches to the appropriate validation logic (Python or Shell) based on the file's extension, supporting both .py and .sh files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces validation for docstrings in shell script test files, which is a great addition for ensuring documentation quality. The implementation is mostly solid, but I've identified a few areas for improvement. My review includes suggestions to reduce code duplication, fix a bug in the validation logic, and improve maintainability by using constants. Addressing these points will make the new validation script more robust and easier to manage in the future.

has_errors = True
else:
# Check blank line before Description
if description_index > 1 and lines[description_index - 1].strip():
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There appears to be a bug in the logic for checking if there's a blank line before the 'Description:' section. The condition if description_index > 1 will not report an error if 'Description:' is on the line immediately after the summary (i.e., at index 1), which is incorrect. To correctly enforce a blank line, the condition should be if description_index > 0 and lines[description_index - 1].strip():, which is consistent with the checks for other fields.

Suggested change
if description_index > 1 and lines[description_index - 1].strip():
if description_index > 0 and lines[description_index - 1].strip():

Comment on lines +57 to +106
def check_required_field_shell(lines, field, file_path, other_fields):
"""
检查 shell 脚本中的必填字段(如 Since),支持多行内容。
"""
index = next((i for i, line in enumerate(lines) if re.match(rf'^{field}\s*:\s*.*$', line, re.IGNORECASE)), None)
has_errors = False
if index is None:
print(f"The docstring in shell script {file_path} does not contain a valid '{field}:' section.")
has_errors = True
else:
if index > 0 and lines[index - 1].strip():
print(f"The docstring in shell script {file_path} must have a blank line before '{field}'.")
has_errors = True
value_lines = []
first_line_value = re.sub(rf'^{field}\s*:\s*', '', lines[index], flags=re.IGNORECASE).strip()
if first_line_value:
value_lines.append(first_line_value)
for i in range(index + 1, len(lines)):
if lines[i].strip() and not re.match(rf'^({"|".join(other_fields)})\s*:\s*.*$', lines[i], re.IGNORECASE):
value_lines.append(lines[i].strip())
else:
break
if not value_lines:
print(f"The docstring in shell script {file_path} does not contain a value for the '{field}:' field.")
has_errors = True
return has_errors

def check_optional_field_shell(lines, field, file_path, other_fields):
"""
检查 shell 脚本中的可选字段(如 Labels、Jira、History, Catalog),支持多行内容。
"""
index = next((i for i, line in enumerate(lines) if re.match(rf'^{field}\s*:\s*.*$', line, re.IGNORECASE)), None)
has_errors = False
if index is not None:
if index > 0 and lines[index - 1].strip():
print(f"The docstring in shell script {file_path} must have a blank line before '{field}'.")
has_errors = True
value_lines = []
first_line_value = re.sub(rf'^{field}\s*:\s*', '', lines[index], flags=re.IGNORECASE).strip()
if first_line_value:
value_lines.append(first_line_value)
for i in range(index + 1, len(lines)):
if lines[i].strip() and not re.match(rf'^({"|".join(other_fields)})\s*:\s*.*$', lines[i], re.IGNORECASE):
value_lines.append(lines[i].strip())
else:
break
if not value_lines:
print(f"The docstring in shell script {file_path} does not contain a value for the '{field}' field.")
has_errors = True
return has_errors
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The functions check_required_field_shell and check_optional_field_shell are nearly identical. To improve maintainability and reduce code duplication, consider refactoring them into a single helper function. This helper could take an is_required boolean parameter to handle the difference in behavior when a field is missing. The core logic for checking blank lines and parsing multi-line values can be shared.

if first_line_value:
description_lines.append(first_line_value)

all_fields = ['Since', 'Catalog', 'Labels', 'Jira', 'History', 'Description']
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The list of all docstring fields is hardcoded here and in other places in this function (lines 137, 171). This makes the code harder to maintain. It would be better to define this list once as a constant at the top of the function, e.g., ALL_FIELDS = ['Since', 'Catalog', 'Labels', 'Jira', 'History', 'Description'], and reuse it throughout the function.

Comment on lines +279 to 287
if file_path.endswith('.sh'):
if not validate_shell_test_file(file_path):
sys.exit(1)
elif file_path.endswith('.py'):
if not validate_test_file(file_path):
sys.exit(1)
else:
print(f"Unsupported file type: {file_path}. Only .py and .sh files are supported.")
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for selecting a validator based on the file extension and then calling it is duplicated. This can be refactored to be more DRY (Don't Repeat Yourself), which will make the code cleaner and easier to extend with more file types in the future.

Suggested change
if file_path.endswith('.sh'):
if not validate_shell_test_file(file_path):
sys.exit(1)
elif file_path.endswith('.py'):
if not validate_test_file(file_path):
sys.exit(1)
else:
print(f"Unsupported file type: {file_path}. Only .py and .sh files are supported.")
sys.exit(1)
validator = None
if file_path.endswith('.sh'):
validator = validate_shell_test_file
elif file_path.endswith('.py'):
validator = validate_test_file
if validator:
if not validator(file_path):
sys.exit(1)
else:
print(f"Unsupported file type: {file_path}. Only .py and .sh files are supported.")
sys.exit(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants