Improve code responsible for creating pipelines and builds
Currently our code responsible for creating pipelines and builds is really tricky.
We now have few files that do basically the same - or similar - job, and this is may be a reason for running into bugs like https://gitlab.com/gitlab-org/gitlab-ce/issues/17977.
This classes do similar job, and therefore we should either join it or refactor and create a facade class for that (later preferred probably):
Then we have quite complicated methods with high complexity like
Pipeline#create_builds. Next thing is that we depend on building builds (
Pipeline#build_builds) to see if there are builds for the current pipeline available (we create a pipeline object, we build builds, but then we do not save pipeline objects if
false, which is really tricky). This has been introduced in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4403 which adds even more technical debt, but we discussed this with @ayufan that we need to fix like https://gitlab.com/gitlab-org/gitlab-ce/issues/17977 before doing this refactoring and the proposed fix is a fair compromise for now.