This looks like the same code as https://github.com/drone/drone/blob/07965b356f20817e3e13616fb0c5afdd6f76829e/pkg/handler/hooks.go#L134 -- extract a shared function instead?