Skip to content
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

Make pre-commit output format configurable #1597

Closed
EliRibble opened this issue Sep 9, 2020 · 3 comments
Closed

Make pre-commit output format configurable #1597

EliRibble opened this issue Sep 9, 2020 · 3 comments

Comments

@EliRibble
Copy link

@EliRibble EliRibble commented Sep 9, 2020

My team uses pre-commit on fairly large repositories and in some cases have repositories with more than 15 hooks. Developers have been complaining to me that pre-commit produces too much output. I'm willing to contribute a patch, but wanted to run the design by the maintainer(s) first.

I'd like to propose some new environment variables:

  • PRE_COMMIT_REPORT_TYPES - defines the types of reports that are made during a pre-commit run
  • PRE_COMMIT_REPORT_FORMAT_STARTED - defines the format of a report when a hook starts
  • PRE_COMMIT_REPORT_FORMAT_SUCCEEDED - defines the format of a report when a hook succeeds
  • PRE_COMMIT_REPORT_FORMAT_FAILED - defines the format of a report when a hook fails
  • PRE_COMMIT_REPORT_FORMAT_SKIPPED - defines the format of a report when a hook is skipped

If PRE_COMMIT_REPORT_TYPES is unset it defaults to start,success,failure,skipped. That is the full set of supported report types. Users may set the value to a smaller set, including the empty set, and disable any output from reports of that type. For example, success,failure would only show reports from pre-commit when a hook either succeeds or fails, but not show a partial report when a hook starts nor any report when a hook is skipped.

The PRE_COMMIT_REPORT_FORMAT_* environment variables allow the user to define the exact format of reports for the different stages of a hook. Each format line would receive as arguments to Python's format() function the following arguments:

  • hook - The full Hook namedtuple
  • run - The result of the hook run which isn't currently a structure but could be, and would contain:
  • duration - time in seconds for the run, None if the hook has just started.
  • returncode - the exit code of the hook
  • files_modified - the files that were modified by the hook
  • files_modified_count - the number of files that were modified by the hook
  • result - pass/fail/skipped/skipped-no-files, includes color codes if supported

This would mean that if no environment variables are set the default formatting string for pre-commit would be:

PRE_COMMIT_REPORT_FORMAT_STARTED = {hook.name:.<74s}
PRE_COMMIT_REPORT_FORMAT_SUCEEDED = {hook.name}{result:.>80s}
PRE_COMMIT_REPORT_FORMAT_SKIPPED = {hook.name}{result:.>80s}
PRE_COMMIT_REPORT_FORMAT_FAILED = {hook.name}{result:.>80s}

This roughly corresponds to the current report behavior, though it always pads to 80 columns instead of dynamically calculating a max column width based on the current hook names.

Currently pre-commit only shows started messages if the hook does not have always_run set and there are no specific filenames provided to it. Ideally this feature would change that and consistently show started messages for all hooks if the user configures it.

Is this a change that pre-commit is interested in if I provide the pull requests? If not, are there elements that could be changed to better meet the long-term vision of pre-commit?

@asottile
Copy link
Member

@asottile asottile commented Sep 9, 2020

going to decline your proposal and mark this as a duplicate of #823 -- you'll want to follow #1560

@asottile asottile closed this Sep 9, 2020
@asottile
Copy link
Member

@asottile asottile commented Sep 9, 2020

always padding to 80 columns does not work by the way, hook names can be longer than that

@asottile
Copy link
Member

@asottile asottile commented Sep 9, 2020

and user-generated-content as the left hand side to .format() is a security problem, you can achieve arbitrary code execution via that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.