Refactor a service responsible for creating a pipeline Closes #37563 and #34415 See merge request gitlab-org/gitlab-ce!14482