-
Notifications
You must be signed in to change notification settings - Fork 135
Update check-go-version-yaml.sh #72
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
base: master
Are you sure you want to change the base?
Conversation
update code
Summary of ChangesHello @AfuroIsCrazy, 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 refactors and enhances the Highlights
Using Gemini Code AssistThe 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
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 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
|
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.
Code Review
This pull request significantly improves the check-go-version-yaml.sh script by refactoring it for better robustness, maintainability, and user experience. The changes consolidate duplicated functions, adopt a more reliable parsing method with awk, and ensure all files are checked before reporting a final status. I have one high-severity comment regarding the awk implementation which could lead to incorrect matches, along with a suggested fix to make it more precise.
| local extracted_go_version=$(awk -v key="$key_pattern" \ | ||
| 'BEGIN {IGNORECASE=1} | ||
| $0 ~ key { | ||
| # Replace the key (case-insensitive) and any following colon/spaces | ||
| sub("[ \t]*" key "[ \t]*:?[ \t]*", "", $0); | ||
| # Remove quotes (single or double) from the start/end | ||
| gsub(/^["\x27]|["\x27]$/, "", $0); | ||
| # Trim leading/trailing whitespace again | ||
| gsub(/^[ \t]|[ \t]$/, "", $0); | ||
| print $0; | ||
| exit | ||
| }' "$yamlfile" | ||
| ) |
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 current awk script for extracting the version is not anchored to the beginning of the line. This can cause it to incorrectly match the key pattern if it appears in a comment or a value string, leading to false-positive errors.
Additionally, the logic for stripping the key is more complex than necessary, and the version_regex variable on line 20 is unused and should be removed along with its comments.
To make the script more robust, I suggest anchoring the awk pattern to the start of the line (allowing for leading whitespace) and simplifying the value extraction. This will ensure that only actual YAML keys are matched.
| local extracted_go_version=$(awk -v key="$key_pattern" \ | |
| 'BEGIN {IGNORECASE=1} | |
| $0 ~ key { | |
| # Replace the key (case-insensitive) and any following colon/spaces | |
| sub("[ \t]*" key "[ \t]*:?[ \t]*", "", $0); | |
| # Remove quotes (single or double) from the start/end | |
| gsub(/^["\x27]|["\x27]$/, "", $0); | |
| # Trim leading/trailing whitespace again | |
| gsub(/^[ \t]|[ \t]$/, "", $0); | |
| print $0; | |
| exit | |
| }' "$yamlfile" | |
| ) | |
| local extracted_go_version=$(awk -v key="$key_pattern" \ | |
| 'BEGIN { IGNORECASE = 1 } | |
| $0 ~ ("^[[:space:]]*" key "[[:space:]]*:") { | |
| # Remove everything up to the first colon and any following spaces. | |
| sub(/.*:[[:space:]]*/, ""); | |
| # Remove quotes (single or double) from the start/end. | |
| gsub(/^["\x27]|["\x27]$/, ""); | |
| # Trim leading/trailing whitespace. | |
| gsub(/^[[:space:]]+|[[:space:]]+$/, ""); | |
| print $0; | |
| exit; | |
| }' "$yamlfile" | |
| ) |
update code