GitHub importer fails when source repository (forked) was deleted
This issue is partially related to https://gitlab.com/gitlab-org/gitlab-ce/issues/29093. See client issue for more context / additional details: https://gitlab.zendesk.com/agent/tickets/67647
How to reproduce
- Fork a repository
- Push some code
- Create a merge request
- Delete the Forked repository
Details
You can see a working example here: https://github.com/xiaogangwen/my-awesome-project/pull/11 The relevant information is:
xgwennt wants to merge 2 commits into
xiaogangwen:master
fromunknown repository
As the source repository was deleted, it now displays unknown repository
, but we can retrieve the original "label" from the API request.
At the API request level, the head.repo
is now nil and because of that the import_error displays the cryptic:
undefined method `id' for nil:NilClass
This is being triggered by the cross_project?
in Gitlab::GithubImporter::PullRequestFormatter
. It's not the only place that needs to be fixed. Basically anywhere that relies on the existence of a repository should.
How to fix
There are two possible solutions I discussed with @jameslopez. One is to check for the existence of the repository and add some extra if/elses. The other is to come up with a NullObject
with some extra context to try to reply meaninfull data so we don't have to refactor everywhere.