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

Enhance pr_changed_files with exit codes and string output #151

Merged
merged 15 commits into from
Feb 21, 2025

Conversation

iangmaia
Copy link
Contributor

@iangmaia iangmaia commented Feb 12, 2025

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 the pr_changed_files command, updating documentation and tests accordingly.


  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

@iangmaia iangmaia marked this pull request as ready for review February 13, 2025 11:08
@iangmaia iangmaia force-pushed the iangmaia/pr-changed-files-iteration branch from feb51f0 to e55dd43 Compare February 19, 2025 16:39
@iangmaia iangmaia requested a review from AliSoftware February 20, 2025 18:00
Comment on lines +16 to +23
# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@iangmaia iangmaia force-pushed the iangmaia/pr-changed-files-iteration branch from 6e4e1dd to c6abeda Compare February 21, 2025 11:47
@iangmaia iangmaia force-pushed the iangmaia/pr-changed-files-iteration branch from 8f64ca2 to ace4813 Compare February 21, 2025 12:01
Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
@iangmaia iangmaia requested a review from AliSoftware February 21, 2025 18:46
Copy link
Contributor

@AliSoftware AliSoftware left a 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.

Comment on lines 118 to 131
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"
}

Copy link
Contributor

@AliSoftware AliSoftware Feb 21, 2025

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.

Copy link
Contributor Author

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

iangmaia and others added 2 commits February 21, 2025 20:35
Co-authored-by: Olivier Halligon <olivier.halligon@automattic.com>
@iangmaia iangmaia merged commit df99bdf into trunk Feb 21, 2025
17 checks passed
@iangmaia iangmaia deleted the iangmaia/pr-changed-files-iteration branch February 21, 2025 22:46
This was referenced Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants