Make CreatePipelineService return a ServiceResponse object
Problem
Ci::CreatePipelineService#execute
returns a pipeline object. The caller of this service is then responsible for understanding if the operation was successful or not.
In some places in our code we check if pipeline.persisted?
and classify that as a success. But most of the time the service object persists the pipeline even if there are errors.
This can be a source of bugs and we do.
The correct way of checking the result is pipeline.created_successfully?
which checks whether the pipeline is persisted and does not have errors. However, we can't expect that everyone knows about this. That's why we should instead use a ServiceResponse
.
Solution
Make the service object return a ServiceResponse object instead which it's bundled with success?
or error?
messages and abstracts the caller from understanding the service object's internals.
A pipeline should also be returned as part of the ServiceResponse
payload.