Refactor how we fetch ref for merge requests

Merged username-removed-423915 requested to merge 36089-handle-ref-failure-better into master

What does this MR do?

  • Make sure we raise early if ref wasn't created
  • Only try to fetch_ref for merge requests from forks

Why was this MR needed?

  • To make it easier to understand what's causing the problem
  • To improve performance by avoiding fetching ref

Does this MR meet the acceptance criteria?

  • Tests
    • Added for this feature/bug
  • Review
    • Has been reviewed by Backend

What are the relevant issue numbers?

Closes #36089 (closed), #36296 (closed)

Edited by username-removed-423915