GitHub Importer failing when target_branch_sha doesn't exist in local repository

Summary

It's possible to have a target_branch_sha pointing to an object that no longer exists in the repository. As we currently don't try to fetch remote for target_branch_sha, the PR never gets imported.

See https://gitlab.zendesk.com/agent/tickets/67647 for more details

Steps to reproduce

  1. Create a PR from a fork
  2. Point the PR to a branch that is not merged into master
  3. Merge the PR
  4. Delete the branch and don't merge into master
  5. Run garbage collector into the repository

What is the current bug behavior?

In the import_error we get: Object not found - no match for id (abc1234...)

What is the expected correct behavior?

Importer should fetch from remote even for target_branch.

Possible fixes

Check if target_branch_sha exists, if not, fetch from pull/:number/merge

cc @xiaogang_gitlab @jameslopez @dbalexandre

Assignee Loading
Time tracking Loading