-
Notifications
You must be signed in to change notification settings - Fork 5
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
Enhance pr_changed_files with exit codes and string output #151
Conversation
feb51f0
to
e55dd43
Compare
# Typical usage patterns: | ||
# # Using exit codes | ||
# $ if pr_changed_files --any-match docs/* *.md; then | ||
# echo "Documentation was updated" | ||
# fi | ||
# | ||
# # Using stdout output | ||
# $ DOCS_UPDATED=$(pr_changed_files --stdout --any-match docs/* *.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
Documentation updates Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
6e4e1dd
to
c6abeda
Compare
… code, actual output, expected output
8f64ca2
to
ace4813
Compare
Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the test missing to assert expected empty output (which I think is worth fixing before merging), the rest looks good, so I'm approving to unblock, supposing you'll fix that test helper.
I've also left a nitpick for implementation of exit_result
, but up to you if you want to adopt it, and not a blocker.
PS: 🎗️ Reminder to update your P2 post accordingly once this ships, to provide up-to-date call examples.
bin/pr_changed_files
Outdated
exit_result() { | ||
local result=$1 | ||
if [[ "$use_stdout" == "true" ]]; then | ||
if [[ "$result" -eq 0 ]]; then | ||
echo "true" | ||
else | ||
echo "false" | ||
fi | ||
exit 0 | ||
fi | ||
|
||
exit "$result" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Future improvement idea I just had while re-reading the whole code: I wonder if the implementation wouldn't read better (especially the call site of this internal function) if we had 2 separate methods instead:
exit_true() {
if [[ "$use_stdout" == "true" ]]; then
echo "true"
fi
exit 0
}
exit_false() {
if [[ "$use_stdout" == "true" ]]; then
echo "false"
exit 0
fi
exit 1
}
Then the call sites would read exit_false()
instead of exit_result 1
, which arguably makes it easier to understand when reading the implementation… 🤔 🤷
That's just a nitpick though, and definitively not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea though, makes it indeed more readable than exit_result 1
! Implemented on ecd08ee
Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
Follow up to the discussion started on woocommerce/woocommerce-ios#15086 (comment).
This PR adds both exit codes (default mode) and
"true"
"false"
output (using--stdout
flag) to thepr_changed_files
command, updating documentation and tests accordingly.CHANGELOG.md
if necessary.