Extract helper methods from run_hook

The `run_hook` method had a number of things going on that made it a bit
complex to work with. Extract chunks of logic into separate helpers to
make it a bit more manageable.

Change-Id: I2b4bf3fe7f3439470f5b0b0d2eee0ea906157c40
Reviewed-on: http://gerrit.causes.com/37380
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane@causes.com>