This can be done with https://pre-commit.com/ (https://github.com/pre-commit/pre-commit). This framework appears to have been created with this very question in mind.