GithubImport: Fix Review importer when the author doesn't exist anymore
What does this MR do?
If the author of a review is deleted, in the Github system, the API
sends null
in the user
field. This commit fixes the
PullRequestReview Importer to now raise any exceptions in this scenario.
Without the fix, exceptions with undefined method 'id' for nil:NilClass
happens:
Example of exception
{
"severity": "ERROR",
"time": "2021-05-06T18:02:42.184Z",
"correlation_id": "17f8d3c3aff0fb6da5f5e0feb1043ac1",
"extra.sidekiq": {
"class": "Gitlab::GithubImport::ImportPullRequestReviewWorker",
"args": [
"9",
"[FILTERED]",
"[FILTERED]"
],
"retry": 5,
"queue": "github_importer:github_import_import_pull_request_review",
"version": 0,
"queue_namespace": "github_importer",
"dead": false,
"jid": "b9d1f1fc87f744f945c72bca",
"created_at": 1620323455.9328947,
"meta.user": "root",
"meta.project": "node-with-queues/node",
"meta.root_namespace": "node-with-queues",
"meta.caller_id": "Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker",
"meta.remote_ip": "96.231.211.84",
"meta.related_class": "Projects::CreateService",
"meta.feature_category": "importers",
"correlation_id": "17f8d3c3aff0fb6da5f5e0feb1043ac1",
"enqueued_at": 1620324162.1698716,
"error_message": "undefined method `id' for nil:NilClass",
"error_class": "NoMethodError",
"failed_at": 1620323455.9514377,
"retry_count": 4,
"retried_at": 1620323755.618828
},
"extra.import_source": "github",
"extra.project_id": 9,
"extra.importer": "Gitlab::GithubImport::Importer::PullRequestReviewImporter",
"exception.class": "NoMethodError",
"exception.message": "undefined method `id' for nil:NilClass",
"exception.backtrace": [
"lib/gitlab/github_import/user_finder.rb:66:in `user_id_for'",
"lib/gitlab/github_import/importer/pull_request_review_importer.rb:16:in `execute'",
"app/workers/concerns/gitlab/github_import/object_importer.rb:31:in `import'",
"app/workers/concerns/gitlab/github_import/rescheduling_methods.rb:31:in `try_import'",
"app/workers/concerns/gitlab/github_import/rescheduling_methods.rb:19:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing.rb:16:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb:40:in `perform'",
"lib/gitlab/sidekiq_middleware/duplicate_jobs/server.rb:8:in `call'",
"lib/gitlab/sidekiq_middleware/worker_context.rb:9:in `wrap_in_optional_context'",
"lib/gitlab/sidekiq_middleware/worker_context/server.rb:17:in `block in call'",
"lib/gitlab/application_context.rb:56:in `block in use'",
"lib/gitlab/application_context.rb:56:in `use'",
"lib/gitlab/application_context.rb:22:in `with_context'",
"lib/gitlab/sidekiq_middleware/worker_context/server.rb:15:in `call'",
"lib/gitlab/sidekiq_status/server_middleware.rb:7:in `call'",
"lib/gitlab/sidekiq_versioning/middleware.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/admin_mode/server.rb:8:in `call'",
"lib/gitlab/sidekiq_middleware/instrumentation_logger.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/batch_loader.rb:7:in `call'",
"lib/gitlab/sidekiq_middleware/extra_done_log_metadata.rb:7:in `call'",
"lib/gitlab/sidekiq_middleware/request_store_middleware.rb:10:in `block in call'",
"lib/gitlab/with_request_store.rb:17:in `enabling_request_store'",
"lib/gitlab/with_request_store.rb:10:in `with_request_store'",
"lib/gitlab/sidekiq_middleware/request_store_middleware.rb:9:in `call'",
"lib/gitlab/sidekiq_middleware/server_metrics.rb:37:in `call'",
"lib/gitlab/sidekiq_middleware/monitor.rb:8:in `block in call'",
"lib/gitlab/sidekiq_daemon/monitor.rb:49:in `within_job'",
"lib/gitlab/sidekiq_middleware/monitor.rb:7:in `call'",
"lib/gitlab/sidekiq_logging/structured_logger.rb:19:in `call'"
]
}
Side Note: I think this is a bug in the Github API. In the normal comments, github send the ghost
user, but in the reviews it sends null
, even though in the github UI they show the ghost
user.
Related to: #330294 (closed)
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because _____.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by Kassio Borges