Skip to content

Conversation

@agateau-gg
Copy link
Collaborator

@agateau-gg agateau-gg commented Oct 10, 2024

What has been done

This PR reworks ggshield verbose mode. It does a few different things:

  • Make --debug automatically enable verbose mode, so there is no need to add both -v and --debug.
  • Unify the way we output verbose messages by using ui.display_verbose() instead of
    if verbose:
         click.echo(...)
    
  • As a consequence of the previous point: remove lots of verbose arguments from functions. They are no longer necessary because the UI now knows its verbosity level.

Review

This PR is quite large, because verbose is everywhere. As usual, best reviewed commit by commit.

Validation

  • Run a ggshield command with --debug: notice the verbose output is there

@codecov
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 71.17647% with 49 lines in your changes missing coverage. Please review.

Project coverage is 91.91%. Comparing base (bc77a6a) to head (db00d97).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
ggshield/core/git_hooks/ci/previous_commit.py 66.66% 15 Missing ⚠️
ggshield/cmd/iac/scan/diff.py 12.50% 7 Missing ⚠️
...ld/core/git_hooks/ci/current_and_previous_state.py 22.22% 7 Missing ⚠️
ggshield/cmd/iac/scan/ci.py 25.00% 3 Missing ⚠️
ggshield/core/ui/rich/rich_scanner_ui.py 40.00% 3 Missing ⚠️
ggshield/verticals/secret/repo.py 0.00% 3 Missing ⚠️
ggshield/cmd/sca/scan/sca_scan_utils.py 33.33% 2 Missing ⚠️
ggshield/core/ui/rich/rich_ggshield_ui.py 50.00% 2 Missing ⚠️
ggshield/__main__.py 92.30% 1 Missing ⚠️
ggshield/cmd/sca/scan/ci.py 75.00% 1 Missing ⚠️
... and 5 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #979      +/-   ##
==========================================
+ Coverage   91.58%   91.91%   +0.32%     
==========================================
  Files         180      181       +1     
  Lines        7605     7593      -12     
==========================================
+ Hits         6965     6979      +14     
+ Misses        640      614      -26     
Flag Coverage Δ
unittests 91.91% <71.17%> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gg-jonathangriffe
Copy link
Contributor

Thank you for this MR.
Is there a specific reason why some click.echo have been replaced and some haven't ?

Copy link
Contributor

@salome-voltz salome-voltz left a comment

Choose a reason for hiding this comment

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

I am a bit ocnfused about your use of ui.display_info for what was previously error logs (I haven't marked all of them though). In my understanding, you should use us.display_error or ui.display_warning instead. Am I missing something ? (this concerns the first commit)

def is_verbose() -> bool:
"""
Convenient function to check if verbose messages are visible. Use this if displaying
verbose messages is costly (for example displaying a list of files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
verbose messages is costly (for example displaying a list of files)
verbose messages are costly (for example displaying a list of files)


config = ContextObj.get(ctx).config
# Update allow_self_signed in the config
# TODO: this should be reworked: if a command which writes the config is called with
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# TODO: this should be reworked: if a command which writes the config is called with
# TODO: this should be reworked: if a command that writes the config is called with

@agateau-gg
Copy link
Collaborator Author

Thank you for this MR. Is there a specific reason why some click.echo have been replaced and some haven't ?

MY goal was to replace all calls to click.echo() when used to show info while ggshield is working, keeping those used to print results (they are the one printing to stdout). I may have missed some though. Let me know 😅.

@agateau-gg agateau-gg marked this pull request as ready for review October 16, 2024 14:28
These functions are going to be useful for the next commit.

This commit also provides a single way to reset the whole module for
unit-tests: `ui.reset.reset()`.
Use ui.display_verbose() everywhere.

Remove many `verbose: bool` arguments.

Check if verbose is enabled using `ui.is_verbose()` instead of using
`config.user_config.verbose`. This avoids the need to update
`config.user_config.verbose` when called with `--verbose`, which is bad
because if the command rewrites the configuration file, it's going to
write `verbose: true` (this is still the case for `--allow-self-signed`).
@agateau-gg agateau-gg force-pushed the agateau/use-ui-verbose branch from b5e9685 to db00d97 Compare October 25, 2024 11:19
@agateau-gg agateau-gg enabled auto-merge October 25, 2024 11:28
@agateau-gg agateau-gg merged commit 77fa6a9 into main Oct 25, 2024
27 of 28 checks passed
@agateau-gg agateau-gg deleted the agateau/use-ui-verbose branch October 25, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants