-
Notifications
You must be signed in to change notification settings - Fork 0
Cleanup after coverage PR merge #8
Conversation
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.
Hello @ipv1337, 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!
Summary of Changes
This pull request, titled "Cleanup after coverage PR merge," aims to revert temporary SonarCloud bypass settings and restore proper test coverage calculation. It removes configurations added to .sonarcloud.properties and sonar-project.properties to bypass quality gate checks and force coverage during a previous PR. Additionally, it updates scripts/run_coverage_ci.sh to use pytest with coverage enabled to generate coverage reports and extract the overall coverage percentage for GitHub Actions output.
Highlights
- Revert SonarCloud Bypass: Removes temporary settings in
.sonarcloud.propertiesandsonar-project.propertiesthat were used to bypass SonarCloud quality gate checks and force coverage. - Restore Test Coverage Calculation: Updates
scripts/run_coverage_ci.shto usepytestwith coverage enabled, generating XML and HTML reports, and extracting the coverage percentage for GitHub Actions. - Coverage Script Update: The coverage script now runs pytest with coverage flags, generates coverage reports in multiple formats (XML, HTML, terminal output), and extracts the overall coverage percentage for use in GitHub Actions.
Changelog
- .sonarcloud.properties
- Removed settings that forced coverage, disabled coverage requirements for the quality gate, skipped the quality gate, and considered all code as 'old code'.
- scripts/run_coverage_ci.sh
- Replaced the simplified coverage script with a pytest-based coverage generation.
- Now uses pytest with the
pytest-covplugin to generate coverage reports in XML and HTML formats. - Extracts the overall coverage percentage from the generated XML report and sets it as a GitHub Actions output variable.
- The script now exits on error, ensuring that failures during coverage generation are properly reported.
- sonar-project.properties
- Removed settings that forced 100% coverage on new code, skipped waiting for the quality gate, set branch patterns, and considered all code as 'old code'.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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 is currently in preview and 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 to provide feedback.
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.
The tests all run,
Coverage reports are spun,
Sonar's watchful eye,
Sees metrics fly,
Quality's work is done.
Footnotes
-
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. ↩
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 cleans up temporary SonarCloud bypass settings and restores proper test coverage calculation. The changes involve removing configurations that were temporarily added to bypass SonarCloud checks and reverting to the original coverage calculation method. The new coverage script uses pytest with coverage enabled to generate reports and extract the overall coverage percentage for GitHub output. Overall, the changes seem reasonable and necessary to restore the CI pipeline to its intended state.
Summary of Findings
- Error Handling in Coverage Script: The coverage script should include more robust error handling to ensure that failures in the test suite or coverage generation process are properly reported. Specifically, the script should check the return codes of pytest and the python command used to extract the coverage percentage, and exit with a non-zero status if any of these commands fail. This will ensure that the CI pipeline fails when there are issues with test coverage.
- Clarity of Log Messages: The log messages in the coverage script could be improved to provide more clarity and context. For example, the script could include more detailed information about the specific tests that are being run, and the reasons for any failures. This would make it easier to diagnose and resolve issues with test coverage.
- Missing Error Handling for XML Parsing: The script uses
xml.etree.ElementTreeto parse the coverage XML file. It should include error handling in case the XML file is malformed or missing. Atry-exceptblock should be added around the XML parsing code to catch potential exceptions and provide a more informative error message.
Merge Readiness
The pull request addresses the important task of cleaning up temporary SonarCloud bypass settings and restoring proper test coverage calculation. However, there are some improvements that could be made to enhance the robustness and clarity of the coverage script. I recommend addressing the error handling and logging suggestions before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.
| if [ -f "coverage.xml" ]; then | ||
| echo "✅ coverage.xml file exists" | ||
|
|
||
| # Extract overall coverage percentage | ||
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))") | ||
| echo "Overall coverage percentage: $COVERAGE" | ||
|
|
||
| # Set output for GitHub Actions | ||
| echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "❌ coverage.xml file not generated!" | ||
| echo "percentage=0.00%" >> $GITHUB_OUTPUT | ||
| fi |
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.
Consider adding error handling to the if statement to ensure that the script exits with a non-zero status if the coverage XML file does not exist or if there is an error extracting the coverage percentage. This will ensure that the CI pipeline fails when there are issues with test coverage.
| if [ -f "coverage.xml" ]; then | |
| echo "✅ coverage.xml file exists" | |
| # Extract overall coverage percentage | |
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate))") | |
| echo "Overall coverage percentage: $COVERAGE" | |
| # Set output for GitHub Actions | |
| echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ coverage.xml file not generated!" | |
| echo "percentage=0.00%" >> $GITHUB_OUTPUT | |
| fi | |
| if [ -f "coverage.xml" ]; then | |
| echo "✅ coverage.xml file exists" | |
| # Extract overall coverage percentage | |
| COVERAGE=$(python -c "import xml.etree.ElementTree as ET; try: tree = ET.parse('coverage.xml'); root = tree.getroot(); line_rate = float(root.attrib['line-rate'])*100; print('{:.2f}%'.format(line_rate)); except Exception as e: print('0.00%')") | |
| if [ $? -ne 0 ]; then | |
| echo "❌ Error extracting coverage percentage!" | |
| echo "percentage=0.00%" >> $GITHUB_OUTPUT | |
| exit 1 | |
| fi | |
| echo "Overall coverage percentage: $COVERAGE" | |
| # Set output for GitHub Actions | |
| echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ coverage.xml file not generated!" | |
| echo "percentage=0.00%" >> $GITHUB_OUTPUT | |
| fi |
| python -m pytest \ | ||
| --cov=src.cli_code \ | ||
| --cov-report=xml:coverage.xml \ | ||
| --cov-report=html:coverage_html \ | ||
| --cov-report=term \ | ||
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | ||
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py |
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.
Consider adding a check for the pytest return code to ensure that the tests are passing. If the tests fail, the script should exit with a non-zero status to indicate that the CI pipeline should fail.
| python -m pytest \ | |
| --cov=src.cli_code \ | |
| --cov-report=xml:coverage.xml \ | |
| --cov-report=html:coverage_html \ | |
| --cov-report=term \ | |
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | |
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py | |
| python -m pytest \ | |
| --cov=src.cli_code \ | |
| --cov-report=xml:coverage.xml \ | |
| --cov-report=html:coverage_html \ | |
| --cov-report=term \ | |
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | |
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py | |
| if [ $? -ne 0 ]; then | |
| echo "❌ pytest failed!" | |
| exit 1 | |
| fi |
| python -m pytest \ | ||
| --cov=src.cli_code \ | ||
| --cov-report=xml:coverage.xml \ | ||
| --cov-report=html:coverage_html \ | ||
| --cov-report=term \ | ||
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | ||
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py |
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.
It would be helpful to add set -x to the script for debugging purposes, especially when the script is failing in CI. This will print each command as it is executed, making it easier to diagnose issues.
| python -m pytest \ | |
| --cov=src.cli_code \ | |
| --cov-report=xml:coverage.xml \ | |
| --cov-report=html:coverage_html \ | |
| --cov-report=term \ | |
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | |
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py | |
| set -x | |
| python -m pytest \ | |
| --cov=src.cli_code \ | |
| --cov-report=xml:coverage.xml \ | |
| --cov-report=html:coverage_html \ | |
| --cov-report=term \ | |
| test_dir/test_file_tools.py test_dir/test_directory_tools.py test_dir/test_system_tools.py \ | |
| test_dir/improved/test_quality_tools.py test_dir/improved/test_summarizer_tool.py test_dir/improved/test_tree_tool.py |
Code Coverage Report📊 Current Coverage: 30.05% Detailed coverage analysis is available in SonarCloud Coverage Change DetailsThis shows code coverage for changes in this PR. To improve coverage, consider adding tests for new or modified code. |
|
Closing in favor of PR #9 which contains these changes plus additional SonarCloud fixes |
Reverts temporary SonarCloud bypass settings after PR merge and restores proper test coverage calculation.