how about
```ruby
if target_project_id.nil? || target_project_id == user_project.id.to_s 
  merge_request.target_project = user_project 
else
  if user_project.forked? && user_project.forked_from_project.id.to_s == target_project_id 
     merge_request.target_project = Project.find_by_id(attrs[:target_project_id]) 
  else 
    render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400)
  end
end
```

Not much better...I could extract some methods:

```ruby
if !for_fork(target_project_id, user_project)
  merge_request.target_project = user_project 
else 
  if target_matches_fork(target_project_id,user_project)
     merge_request.target_project = Project.find_by_id(attrs[:target_project_id]) 
  else
    render_api_error!('(Bad Request) Specified target project that is not the source project, or the source fork of the project.', 400)
  end
end
```