git-sizer icon indicating copy to clipboard operation
git-sizer copied to clipboard

Feature: Set nonzero exit code with --critical

Open mingalsuo opened this issue 7 years ago • 4 comments

For automation purposes, it would be a great feature to be able to analyze repositories and get a machine readable exit code that states that critical issues were found.

One way is to directly have --critical set the exit code or add another flag that does that if critical issues were found.

Thanks for creating this great tool.

mingalsuo avatar Jun 08 '18 12:06 mingalsuo

That's a good idea. We'd definitely want a way to distinguish between runtime errors (e.g., repository was corrupt) vs. size "errors"; for example, by returning different exit codes.

mhagger avatar Jun 12 '18 06:06 mhagger

I like this idea and I have some time to work on it. @mhagger did you maybe have some recommended exit codes in mind? I'm not aware of any standard command line error codes we could reuse.

Following @mingalsuo description updating the tool to support custom user defined exit codes could be an approach. Have the user provide a config file with them listed.

sspaink avatar Oct 02 '18 21:10 sspaink

A "nice" workaround is to use JSON output and jq.

To just display the results:

git-sizer --json --json-version=2 2>/dev/null | jq -r '. | values[] | select (.levelOfConcern >= 1) | [.description, ((.value | tostring) + .unit), (.levelOfConcern * 100 | floor / 100)] | @tsv' | column -t -s $'\t'

To set the exit code to 1 when all is good (there is no match >= threshold):

git-sizer --json --json-version=2 2>/dev/null | jq -e -r '. | values[] | select (.levelOfConcern >= 1) | [.description, ((.value | tostring) + .unit), (.levelOfConcern * 100 | floor / 100)]'

Then you can "reverse" the exit code.

You can tweak the threshold in select (.levelOfConcern >= 1), or a bit fancier with an env var:

export THRESHOLD=0.5
git-sizer --json --json-version=2 2>/dev/null | jq -e -r '. | values[] | select (.levelOfConcern >= (env.THRESHOLD | tonumber)) | [.description, ((.value | tostring) + .unit), (.levelOfConcern * 100 | floor / 100)]'

This can be further cleaned up in a nice zsh/bash wrapper file and/or a nice jq script file.

ls-jad-elkik avatar Feb 22 '22 17:02 ls-jad-elkik

git cat-file -p :

murayamajpeg avatar May 25 '24 02:05 murayamajpeg