Extract last_known_revision logic to Deployment class

This should fix the Rubocop errors as well.
That would return a relation with 0 or 1 deployments instead of single deployment or nil.