-
Notifications
You must be signed in to change notification settings - Fork 527
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
Fix #2198: Introduce pre push hook for ktlint #2002
Fix #2198: Introduce pre push hook for ktlint #2002
Conversation
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.
Tested this and it works correctly. Thanks @anandwana001
Will need to defer to @BenHenning and @vinitamurthi for code correctness.
I'll need to take a look at this tomorrow my time (it's getting a bit late). @vinitamurthi it might be nice if you could take a look at this first. One issue with the pre-commit hook is that we can't force people to actually install it in the Android workflow, and if you don't install it it's not as useful. :) |
scripts/setup.py
Outdated
if file_exists: | ||
print('Pre-commit hook already exists') |
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.
The downside to this is that, if we make any changes to the pre-commit hook, it will not get updated to folks who already have the hook installed. Maybe we should not do this and just replace the file even if it exists (Since this script shouldn't be run very often anyway)
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.
now with bash, what we are doing is moving of file.
That's actually why I thought we should install the hook in a setup script (among other reasons). Today the setup script is not something we can force people to do, but in the future we can actually have people use the setup script to install everything they require to get oppia-android working (particularly, bazel :) )
And in documentation we basically have the installation steps as: Clone the repo, download Android studio, run this setup script. |
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.
Thanks @anandwana001! Left some high-level thoughts.
scripts/pre-commit
Outdated
echo "********************************" | ||
echo "Checking code formatting" | ||
echo "********************************" |
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.
I'm being a bit nitpicky (sorry!) - can we have the entire lint check work within a function and then call that function in this script? The reason I ask for that is so that we can cleanly extend this hook if we want to add more checks into it later on
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.
One step further: I think the lint check itself should be its own script that this hook calls (apologies if that's what you meant @vinitamurthi). The pre-commit hook ought to just be a set of commands to run, and having the command separate also lets people use it directly.
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.
Yes that's what I meant sorry I didn't make it clear! We should keep them in separate scripts and the pre-commit hook should have commands to run those scripts one after the other
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.
Sounds good, Thanks @vinitamurthi
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.
Done
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.
Thanks @anandwana001! Left a few more thoughts.
scripts/pre-commit
Outdated
echo "********************************" | ||
echo "Checking code formatting" | ||
echo "********************************" |
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.
One step further: I think the lint check itself should be its own script that this hook calls (apologies if that's what you meant @vinitamurthi). The pre-commit hook ought to just be a set of commands to run, and having the command separate also lets people use it directly.
@anandwana001 We discussed that if possible I can resolve ben's comment but even if I do that we will need approval from @BenHenning and therefore I am not resolving his comments. Thanks. |
Thanks @anandwana001. Just had one follow-up regarding the executable bit of the pre-commit file, otherwise this looks good to me. |
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.
Thanks @anandwana001! I was about to approve then realized one last thing. :( We should make setup.sh the one-stop-solves-all solution for preparing the codebase. To start, it should set up ktlint and in the future we can add other tools (such as Bazel).
… introduce-pre-commit-hook-ktlint
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.
Small doubt regarding how to run ktlint in pre push hook
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.
Thanks @anandwana001! LGTM!
@anandwana001 just 2 comments to address from me before merging. PTAL. |
Explanation
Fix #2198
As we know that we have ktlint check in our actions and we also enforce for good formatting code. So, rather than sending a PR and then fixing the ktlint issue, we are introducing a pre-push hook which will run the ktlint before any push.
As per this PR, we want any contributor after opening the codebase we want them to run a script which will copy our hooks script into the
.git/hooks
folder.Script to run ->
bash scripts/setup.sh
Checklist