gracefully handle git secrets not being installed#212
Open
lukaso wants to merge 2 commits intoawslabs:masterfrom
Open
gracefully handle git secrets not being installed#212lukaso wants to merge 2 commits intoawslabs:masterfrom
lukaso wants to merge 2 commits intoawslabs:masterfrom
Conversation
For whatever reason, sometimes the env does not have access to git secrets (for example in `vscode` this seems to happen frequently). This change allows it to fail gracefully instead of blocking all commits.
sparr
reviewed
Jun 15, 2023
Comment on lines
+206
to
+212
| echo "err=\"\$(git secrets --${cmd} -- \"\$@\" 2>&1 > /dev/null)\"" >> "${dest}" | ||
| echo "if [[ \"\$err\" == *\"git: 'secrets' is not a git command\"* ]]; then" >> "${dest}" | ||
| echo " exit 0" >> "${dest}" | ||
| echo "elif [[ ! -z \"\$err\" ]]; then" >> "${dest}" | ||
| echo " >&2 echo \"\$err\"" >> "${dest}" | ||
| echo " exit 1" >> "${dest}" | ||
| echo "fi" >> "${dest}" |
Contributor
There was a problem hiding this comment.
Suggested change
| echo "err=\"\$(git secrets --${cmd} -- \"\$@\" 2>&1 > /dev/null)\"" >> "${dest}" | |
| echo "if [[ \"\$err\" == *\"git: 'secrets' is not a git command\"* ]]; then" >> "${dest}" | |
| echo " exit 0" >> "${dest}" | |
| echo "elif [[ ! -z \"\$err\" ]]; then" >> "${dest}" | |
| echo " >&2 echo \"\$err\"" >> "${dest}" | |
| echo " exit 1" >> "${dest}" | |
| echo "fi" >> "${dest}" | |
| cat <<-EOF > "${dest}" | |
| err="\$(git secrets --${cmd} -- "\$@" 2>&1 > /dev/null)" | |
| if [[ "\$err" == *"git: 'secrets' is not a git command"* ]]; then | |
| exit 0 | |
| elif [[ ! -z "\$err" ]]; then | |
| >&2 echo "\$err" | |
| exit 1 | |
| fi | |
| EOF |
I think this will be easier to read, but it needs to be tested.
Also, due to github limitations, this suggestion doesn't replace the first echo on line 205 but should.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
For whatever reason, sometimes the env does not have access to git secrets (for example in
vscodethis seems to happen frequently). This change allows it to fail gracefully instead of blocking all commits.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.