Add validation for missing project/user in Ci::CreatePipelineService
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=561453) </details> <!--IssueSummary end--> ## Summary Following up on the discussion in !200986, we should add validation for missing projects and users in `Ci::CreatePipelineService` as well, in addition to the existing guards in `CreatePipelineWorker`. ## Background In !200986, we added guards in `CreatePipelineWorker` to handle missing projects and users gracefully: ```ruby project = Project.find_by_id(project_id) return unless project user = User.find_by_id(user_id) return unless user ``` ## Proposal @allison.browne suggested that we should also add validation in the `Ci::CreatePipelineService` itself. The benefits would be: 1. **Better error handling**: We could use `error()` without a failure reason to populate `::Ci::PipelineCreation::Requests` with an error, allowing users to see why the latest pipeline for a project or MR wasn't created. 2. **Broader protection**: This would handle the condition from other callers of `Ci::CreatePipelineService`, not just the worker. 3. **Consistent behavior**: Using `error(msg)` in the pipeline creation service without a `failure_reason` will not persist the pipeline, having the same effect as not creating a pipeline. ## Implementation Notes - Add validation in `Ci::CreatePipelineService` to check that both project and user exist - Use the service's `error()` method to provide meaningful feedback when they don't exist - Ensure the error doesn't persist a failed pipeline (no `failure_reason`) - Keep the existing validation in `CreatePipelineWorker` as well ## Related - Original MR: !200986 - Discussion: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/200986#note_2683423302
issue