Commit b46a08f5 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'kassio/github-importer-expose-stats-on-import-status-endpoint' into 'master'

GithubImporter: Expose import stats on import status endpoint

See merge request gitlab-org/gitlab!76355
parents 1e87a36f 1a0c2329
...@@ -294,6 +294,7 @@ The `failed_relations` array is capped to 100 items. ...@@ -294,6 +294,7 @@ The `failed_relations` array is capped to 100 items.
"path_with_namespace": "gitlab-org/gitlab-test", "path_with_namespace": "gitlab-org/gitlab-test",
"created_at": "2017-08-29T04:36:44.383Z", "created_at": "2017-08-29T04:36:44.383Z",
"import_status": "started", "import_status": "started",
"import_type": "github",
"correlation_id": "mezklWso3Za", "correlation_id": "mezklWso3Za",
"failed_relations": [ "failed_relations": [
{ {
...@@ -302,8 +303,58 @@ The `failed_relations` array is capped to 100 items. ...@@ -302,8 +303,58 @@ The `failed_relations` array is capped to 100 items.
"exception_class": "RuntimeError", "exception_class": "RuntimeError",
"exception_message": "A failure occurred", "exception_message": "A failure occurred",
"source": "custom error context", "source": "custom error context",
"relation_name": "merge_requests" "relation_name": "merge_requests",
"line_number": 0
} }
] ]
} }
``` ```
When importing from GitHub, the a `stats` field lists how many objects were already fetched from
GitHub and how many were already imported:
```json
{
"id": 1,
"description": "Itaque perspiciatis minima aspernatur corporis consequatur.",
"name": "Gitlab Test",
"name_with_namespace": "Gitlab Org / Gitlab Test",
"path": "gitlab-test",
"path_with_namespace": "gitlab-org/gitlab-test",
"created_at": "2017-08-29T04:36:44.383Z",
"import_status": "started",
"import_type": "github",
"correlation_id": "mezklWso3Za",
"failed_relations": [
{
"id": 42,
"created_at": "2020-04-02T14:48:59.526Z",
"exception_class": "RuntimeError",
"exception_message": "A failure occurred",
"source": "custom error context",
"relation_name": "merge_requests",
"line_number": 0
}
],
"stats": {
"fetched": {
"diff_note": 19,
"issue": 3,
"label": 1,
"note": 3,
"pull_request": 2,
"pull_request_merged_by": 1,
"pull_request_review": 16
},
"imported": {
"diff_note": 19,
"issue": 3,
"label": 1,
"note": 3,
"pull_request": 2,
"pull_request_merged_by": 1,
"pull_request_review": 16
}
}
}
```
...@@ -16,6 +16,12 @@ module API ...@@ -16,6 +16,12 @@ module API
expose :import_error do |project, _options| expose :import_error do |project, _options|
project.import_state&.last_error project.import_state&.last_error
end end
expose :stats do |project, _options|
if project.github_import?
::Gitlab::GithubImport::ObjectCounter.summary(project)
end
end
end end
end end
end end
...@@ -17,6 +17,7 @@ RSpec.describe API::Entities::ProjectImportStatus, :aggregate_failures do ...@@ -17,6 +17,7 @@ RSpec.describe API::Entities::ProjectImportStatus, :aggregate_failures do
expect(subject[:correlation_id]).to be_nil expect(subject[:correlation_id]).to be_nil
expect(subject[:import_error]).to be_nil expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([]) expect(subject[:failed_relations]).to eq([])
expect(subject[:stats]).to be_nil
end end
end end
...@@ -76,5 +77,22 @@ RSpec.describe API::Entities::ProjectImportStatus, :aggregate_failures do ...@@ -76,5 +77,22 @@ RSpec.describe API::Entities::ProjectImportStatus, :aggregate_failures do
expect(subject[:failed_relations]).to eq([]) expect(subject[:failed_relations]).to eq([])
end end
end end
context 'when importing from github', :clean_gitlab_redis_cache do
let(:project) { create(:project, :import_failed, import_type: 'github') }
let(:entity) { described_class.new(project) }
before do
::Gitlab::GithubImport::ObjectCounter.increment(project, :issues, :fetched, value: 10)
::Gitlab::GithubImport::ObjectCounter.increment(project, :issues, :imported, value: 8)
end
it 'exposes the import stats' do
expect(subject[:stats]).to eq(
'fetched' => { 'issues' => 10 },
'imported' => { 'issues' => 8 }
)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment