Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Make pre-commit output format configurable #1597
Comments
|
always padding to 80 columns does not work by the way, hook names can be longer than that |
|
and user-generated-content as the left hand side to |
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 apre-commitrunPRE_COMMIT_REPORT_FORMAT_STARTED- defines the format of a report when a hook startsPRE_COMMIT_REPORT_FORMAT_SUCCEEDED- defines the format of a report when a hook succeedsPRE_COMMIT_REPORT_FORMAT_FAILED- defines the format of a report when a hook failsPRE_COMMIT_REPORT_FORMAT_SKIPPED- defines the format of a report when a hook is skippedIf
PRE_COMMIT_REPORT_TYPESis unset it defaults tostart,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,failurewould only show reports frompre-commitwhen 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'sformat()function the following arguments:hook- The fullHooknamedtuplerun- 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 hookfiles_modified- the files that were modified by the hookfiles_modified_count- the number of files that were modified by the hookresult- pass/fail/skipped/skipped-no-files, includes color codes if supportedThis would mean that if no environment variables are set the default formatting string for
pre-commitwould 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-commitonly shows started messages if the hook does not havealways_runset 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-commitis interested in if I provide the pull requests? If not, are there elements that could be changed to better meet the long-term vision ofpre-commit?