Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
7581f866
Commit
7581f866
authored
Sep 29, 2021
by
Doug Stull
Committed by
Tetiana Chupryna
Sep 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Github Importer: Improve logging with more identifying data
parent
933c35c6
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
191 additions
and
47 deletions
+191
-47
app/workers/concerns/gitlab/github_import/object_importer.rb
app/workers/concerns/gitlab/github_import/object_importer.rb
+5
-6
lib/gitlab/github_import/representation/diff_note.rb
lib/gitlab/github_import/representation/diff_note.rb
+10
-2
lib/gitlab/github_import/representation/issue.rb
lib/gitlab/github_import/representation/issue.rb
+7
-1
lib/gitlab/github_import/representation/lfs_object.rb
lib/gitlab/github_import/representation/lfs_object.rb
+7
-2
lib/gitlab/github_import/representation/note.rb
lib/gitlab/github_import/representation/note.rb
+10
-2
lib/gitlab/github_import/representation/pull_request.rb
lib/gitlab/github_import/representation/pull_request.rb
+7
-1
lib/gitlab/github_import/representation/pull_request_review.rb
...itlab/github_import/representation/pull_request_review.rb
+9
-2
lib/gitlab/github_import/representation/user.rb
lib/gitlab/github_import/representation/user.rb
+0
-1
spec/lib/gitlab/github_import/representation/diff_note_spec.rb
...lib/gitlab/github_import/representation/diff_note_spec.rb
+18
-4
spec/lib/gitlab/github_import/representation/issue_spec.rb
spec/lib/gitlab/github_import/representation/issue_spec.rb
+13
-0
spec/lib/gitlab/github_import/representation/lfs_object_spec.rb
...ib/gitlab/github_import/representation/lfs_object_spec.rb
+17
-0
spec/lib/gitlab/github_import/representation/note_spec.rb
spec/lib/gitlab/github_import/representation/note_spec.rb
+18
-4
spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb
.../github_import/representation/pull_request_review_spec.rb
+15
-2
spec/lib/gitlab/github_import/representation/pull_request_spec.rb
.../gitlab/github_import/representation/pull_request_spec.rb
+12
-0
spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
...ers/concerns/gitlab/github_import/object_importer_spec.rb
+43
-20
No files found.
app/workers/concerns/gitlab/github_import/object_importer.rb
View file @
7581f866
...
@@ -26,8 +26,7 @@ module Gitlab
...
@@ -26,8 +26,7 @@ module Gitlab
object
=
representation_class
.
from_json_hash
(
hash
)
object
=
representation_class
.
from_json_hash
(
hash
)
# To better express in the logs what object is being imported.
# To better express in the logs what object is being imported.
self
.
github_id
=
object
.
attributes
.
fetch
(
:github_id
)
self
.
github_identifiers
=
object
.
github_identifiers
info
(
project
.
id
,
message:
'starting importer'
)
info
(
project
.
id
,
message:
'starting importer'
)
importer_class
.
new
(
object
,
project
,
client
).
execute
importer_class
.
new
(
object
,
project
,
client
).
execute
...
@@ -35,10 +34,10 @@ module Gitlab
...
@@ -35,10 +34,10 @@ module Gitlab
Gitlab
::
GithubImport
::
ObjectCounter
.
increment
(
project
,
object_type
,
:imported
)
Gitlab
::
GithubImport
::
ObjectCounter
.
increment
(
project
,
object_type
,
:imported
)
info
(
project
.
id
,
message:
'importer finished'
)
info
(
project
.
id
,
message:
'importer finished'
)
rescue
Key
Error
=>
e
rescue
NoMethod
Error
=>
e
# This exception will be more useful in development when a new
# This exception will be more useful in development when a new
# Representation is created but the developer forgot to add a
# Representation is created but the developer forgot to add a
# `:github_id` field.
# `:github_id
entifiers
` field.
Gitlab
::
Import
::
ImportFailureService
.
track
(
Gitlab
::
Import
::
ImportFailureService
.
track
(
project_id:
project
.
id
,
project_id:
project
.
id
,
error_source:
importer_class
.
name
,
error_source:
importer_class
.
name
,
...
@@ -72,7 +71,7 @@ module Gitlab
...
@@ -72,7 +71,7 @@ module Gitlab
private
private
attr_accessor
:github_id
attr_accessor
:github_id
entifiers
def
info
(
project_id
,
extra
=
{})
def
info
(
project_id
,
extra
=
{})
Logger
.
info
(
log_attributes
(
project_id
,
extra
))
Logger
.
info
(
log_attributes
(
project_id
,
extra
))
...
@@ -82,7 +81,7 @@ module Gitlab
...
@@ -82,7 +81,7 @@ module Gitlab
extra
.
merge
(
extra
.
merge
(
project_id:
project_id
,
project_id:
project_id
,
importer:
importer_class
.
name
,
importer:
importer_class
.
name
,
github_id
:
github_id
github_id
entifiers:
github_identifiers
)
)
end
end
end
end
...
...
lib/gitlab/github_import/representation/diff_note.rb
View file @
7581f866
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
expose_attribute
:noteable_type
,
:noteable_id
,
:commit_id
,
:file_path
,
expose_attribute
:noteable_type
,
:noteable_id
,
:commit_id
,
:file_path
,
:diff_hunk
,
:author
,
:note
,
:created_at
,
:updated_at
,
:diff_hunk
,
:author
,
:note
,
:created_at
,
:updated_at
,
:
github_id
,
:original_commit
_id
:
original_commit_id
,
:note
_id
NOTEABLE_ID_REGEX
=
%r{/pull/(?<iid>
\d
+)}i
.
freeze
NOTEABLE_ID_REGEX
=
%r{/pull/(?<iid>
\d
+)}i
.
freeze
...
@@ -40,7 +40,7 @@ module Gitlab
...
@@ -40,7 +40,7 @@ module Gitlab
note:
note
.
body
,
note:
note
.
body
,
created_at:
note
.
created_at
,
created_at:
note
.
created_at
,
updated_at:
note
.
updated_at
,
updated_at:
note
.
updated_at
,
github
_id:
note
.
id
note
_id:
note
.
id
}
}
new
(
hash
)
new
(
hash
)
...
@@ -82,6 +82,14 @@ module Gitlab
...
@@ -82,6 +82,14 @@ module Gitlab
new_file:
false
new_file:
false
}
}
end
end
def
github_identifiers
{
note_id:
note_id
,
noteable_id:
noteable_id
,
noteable_type:
noteable_type
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/issue.rb
View file @
7581f866
...
@@ -25,7 +25,6 @@ module Gitlab
...
@@ -25,7 +25,6 @@ module Gitlab
hash
=
{
hash
=
{
iid:
issue
.
number
,
iid:
issue
.
number
,
github_id:
issue
.
number
,
title:
issue
.
title
,
title:
issue
.
title
,
description:
issue
.
body
,
description:
issue
.
body
,
milestone_number:
issue
.
milestone
&
.
number
,
milestone_number:
issue
.
milestone
&
.
number
,
...
@@ -75,6 +74,13 @@ module Gitlab
...
@@ -75,6 +74,13 @@ module Gitlab
def
issuable_type
def
issuable_type
pull_request?
?
'MergeRequest'
:
'Issue'
pull_request?
?
'MergeRequest'
:
'Issue'
end
end
def
github_identifiers
{
iid:
iid
,
issuable_type:
issuable_type
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/lfs_object.rb
View file @
7581f866
...
@@ -16,8 +16,7 @@ module Gitlab
...
@@ -16,8 +16,7 @@ module Gitlab
new
(
new
(
oid:
lfs_object
.
oid
,
oid:
lfs_object
.
oid
,
link:
lfs_object
.
link
,
link:
lfs_object
.
link
,
size:
lfs_object
.
size
,
size:
lfs_object
.
size
github_id:
lfs_object
.
oid
)
)
end
end
...
@@ -31,6 +30,12 @@ module Gitlab
...
@@ -31,6 +30,12 @@ module Gitlab
def
initialize
(
attributes
)
def
initialize
(
attributes
)
@attributes
=
attributes
@attributes
=
attributes
end
end
def
github_identifiers
{
oid:
oid
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/note.rb
View file @
7581f866
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
attr_reader
:attributes
attr_reader
:attributes
expose_attribute
:noteable_id
,
:noteable_type
,
:author
,
:note
,
expose_attribute
:noteable_id
,
:noteable_type
,
:author
,
:note
,
:created_at
,
:updated_at
,
:
github
_id
:created_at
,
:updated_at
,
:
note
_id
NOTEABLE_TYPE_REGEX
=
%r{/(?<type>(pull|issues))/(?<iid>
\d
+)}i
.
freeze
NOTEABLE_TYPE_REGEX
=
%r{/(?<type>(pull|issues))/(?<iid>
\d
+)}i
.
freeze
...
@@ -42,7 +42,7 @@ module Gitlab
...
@@ -42,7 +42,7 @@ module Gitlab
note:
note
.
body
,
note:
note
.
body
,
created_at:
note
.
created_at
,
created_at:
note
.
created_at
,
updated_at:
note
.
updated_at
,
updated_at:
note
.
updated_at
,
github
_id:
note
.
id
note
_id:
note
.
id
}
}
new
(
hash
)
new
(
hash
)
...
@@ -64,6 +64,14 @@ module Gitlab
...
@@ -64,6 +64,14 @@ module Gitlab
end
end
alias_method
:issuable_type
,
:noteable_type
alias_method
:issuable_type
,
:noteable_type
def
github_identifiers
{
note_id:
note_id
,
noteable_id:
noteable_id
,
noteable_type:
noteable_type
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/pull_request.rb
View file @
7581f866
...
@@ -25,7 +25,6 @@ module Gitlab
...
@@ -25,7 +25,6 @@ module Gitlab
hash
=
{
hash
=
{
iid:
pr
.
number
,
iid:
pr
.
number
,
github_id:
pr
.
number
,
title:
pr
.
title
,
title:
pr
.
title
,
description:
pr
.
body
,
description:
pr
.
body
,
source_branch:
pr
.
head
.
ref
,
source_branch:
pr
.
head
.
ref
,
...
@@ -108,6 +107,13 @@ module Gitlab
...
@@ -108,6 +107,13 @@ module Gitlab
def
issuable_type
def
issuable_type
'MergeRequest'
'MergeRequest'
end
end
def
github_identifiers
{
iid:
iid
,
issuable_type:
issuable_type
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/pull_request_review.rb
View file @
7581f866
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
attr_reader
:attributes
attr_reader
:attributes
expose_attribute
:author
,
:note
,
:review_type
,
:submitted_at
,
:
github_id
,
:merge_request
_id
expose_attribute
:author
,
:note
,
:review_type
,
:submitted_at
,
:
merge_request_id
,
:review
_id
def
self
.
from_api_response
(
review
)
def
self
.
from_api_response
(
review
)
user
=
Representation
::
User
.
from_api_response
(
review
.
user
)
if
review
.
user
user
=
Representation
::
User
.
from_api_response
(
review
.
user
)
if
review
.
user
...
@@ -20,7 +20,7 @@ module Gitlab
...
@@ -20,7 +20,7 @@ module Gitlab
note:
review
.
body
,
note:
review
.
body
,
review_type:
review
.
state
,
review_type:
review
.
state
,
submitted_at:
review
.
submitted_at
,
submitted_at:
review
.
submitted_at
,
github
_id:
review
.
id
review
_id:
review
.
id
)
)
end
end
...
@@ -43,6 +43,13 @@ module Gitlab
...
@@ -43,6 +43,13 @@ module Gitlab
def
approval?
def
approval?
review_type
==
'APPROVED'
review_type
==
'APPROVED'
end
end
def
github_identifiers
{
review_id:
review_id
,
merge_request_id:
merge_request_id
}
end
end
end
end
end
end
end
...
...
lib/gitlab/github_import/representation/user.rb
View file @
7581f866
...
@@ -17,7 +17,6 @@ module Gitlab
...
@@ -17,7 +17,6 @@ module Gitlab
def
self
.
from_api_response
(
user
)
def
self
.
from_api_response
(
user
)
new
(
new
(
id:
user
.
id
,
id:
user
.
id
,
github_id:
user
.
id
,
login:
user
.
login
login:
user
.
login
)
)
end
end
...
...
spec/lib/gitlab/github_import/representation/diff_note_spec.rb
View file @
7581f866
...
@@ -51,7 +51,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
...
@@ -51,7 +51,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
end
end
it
'includes the GitHub ID'
do
it
'includes the GitHub ID'
do
expect
(
note
.
github
_id
).
to
eq
(
1
)
expect
(
note
.
note
_id
).
to
eq
(
1
)
end
end
it
'returns the noteable type'
do
it
'returns the noteable type'
do
...
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
...
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'note'
=>
'Hello world'
,
'note'
=>
'Hello world'
,
'created_at'
=>
created_at
.
to_s
,
'created_at'
=>
created_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'
github
_id'
=>
1
'
note
_id'
=>
1
}
}
end
end
...
@@ -124,7 +124,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
...
@@ -124,7 +124,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'note'
=>
'Hello world'
,
'note'
=>
'Hello world'
,
'created_at'
=>
created_at
.
to_s
,
'created_at'
=>
created_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'
github
_id'
=>
1
'
note
_id'
=>
1
}
}
note
=
described_class
.
from_json_hash
(
hash
)
note
=
described_class
.
from_json_hash
(
hash
)
...
@@ -154,7 +154,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
...
@@ -154,7 +154,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
'note'
=>
'Hello world'
,
'note'
=>
'Hello world'
,
'created_at'
=>
created_at
.
to_s
,
'created_at'
=>
created_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'
github
_id'
=>
1
'
note
_id'
=>
1
)
)
expect
(
note
.
diff_hash
).
to
eq
(
expect
(
note
.
diff_hash
).
to
eq
(
...
@@ -167,4 +167,18 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
...
@@ -167,4 +167,18 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote do
)
)
end
end
end
end
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
noteable_id:
42
,
noteable_type:
'MergeRequest'
,
note_id:
1
}
other_attributes
=
{
something_else:
'_something_else_'
}
note
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
note
.
github_identifiers
).
to
eq
(
github_identifiers
)
end
end
end
end
spec/lib/gitlab/github_import/representation/issue_spec.rb
View file @
7581f866
...
@@ -181,4 +181,17 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do
...
@@ -181,4 +181,17 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do
expect
(
object
.
truncated_title
).
to
eq
(
'foo'
)
expect
(
object
.
truncated_title
).
to
eq
(
'foo'
)
end
end
end
end
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
iid:
42
,
issuable_type:
'MergeRequest'
}
other_attributes
=
{
pull_request:
true
,
something_else:
'_something_else_'
}
issue
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
issue
.
github_identifiers
).
to
eq
(
github_identifiers
)
end
end
end
end
spec/lib/gitlab/github_import/representation/lfs_object_spec.rb
0 → 100644
View file @
7581f866
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
GithubImport
::
Representation
::
LfsObject
do
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
oid:
42
}
other_attributes
=
{
something_else:
'_something_else_'
}
lfs_object
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
lfs_object
.
github_identifiers
).
to
eq
(
github_identifiers
)
end
end
end
spec/lib/gitlab/github_import/representation/note_spec.rb
View file @
7581f866
...
@@ -40,8 +40,8 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
...
@@ -40,8 +40,8 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
expect
(
note
.
updated_at
).
to
eq
(
updated_at
)
expect
(
note
.
updated_at
).
to
eq
(
updated_at
)
end
end
it
'includes the
GitHub
ID'
do
it
'includes the
note
ID'
do
expect
(
note
.
github
_id
).
to
eq
(
1
)
expect
(
note
.
note
_id
).
to
eq
(
1
)
end
end
end
end
end
end
...
@@ -84,7 +84,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
...
@@ -84,7 +84,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
'note'
=>
'Hello world'
,
'note'
=>
'Hello world'
,
'created_at'
=>
created_at
.
to_s
,
'created_at'
=>
created_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'
github
_id'
=>
1
'
note
_id'
=>
1
}
}
end
end
...
@@ -98,7 +98,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
...
@@ -98,7 +98,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
'note'
=>
'Hello world'
,
'note'
=>
'Hello world'
,
'created_at'
=>
created_at
.
to_s
,
'created_at'
=>
created_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'updated_at'
=>
updated_at
.
to_s
,
'
github
_id'
=>
1
'
note
_id'
=>
1
}
}
note
=
described_class
.
from_json_hash
(
hash
)
note
=
described_class
.
from_json_hash
(
hash
)
...
@@ -106,4 +106,18 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
...
@@ -106,4 +106,18 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do
expect
(
note
.
author
).
to
be_nil
expect
(
note
.
author
).
to
be_nil
end
end
end
end
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
noteable_id:
42
,
noteable_type:
'Issue'
,
note_id:
1
}
other_attributes
=
{
something_else:
'_something_else_'
}
note
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
note
.
github_identifiers
).
to
eq
(
github_identifiers
)
end
end
end
end
spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb
View file @
7581f866
...
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
...
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
expect
(
review
.
note
).
to
eq
(
'note'
)
expect
(
review
.
note
).
to
eq
(
'note'
)
expect
(
review
.
review_type
).
to
eq
(
'APPROVED'
)
expect
(
review
.
review_type
).
to
eq
(
'APPROVED'
)
expect
(
review
.
submitted_at
).
to
eq
(
submitted_at
)
expect
(
review
.
submitted_at
).
to
eq
(
submitted_at
)
expect
(
review
.
github
_id
).
to
eq
(
999
)
expect
(
review
.
review
_id
).
to
eq
(
999
)
expect
(
review
.
merge_request_id
).
to
eq
(
42
)
expect
(
review
.
merge_request_id
).
to
eq
(
42
)
end
end
end
end
...
@@ -50,7 +50,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
...
@@ -50,7 +50,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
describe
'.from_json_hash'
do
describe
'.from_json_hash'
do
let
(
:hash
)
do
let
(
:hash
)
do
{
{
'
github
_id'
=>
999
,
'
review
_id'
=>
999
,
'merge_request_id'
=>
42
,
'merge_request_id'
=>
42
,
'note'
=>
'note'
,
'note'
=>
'note'
,
'review_type'
=>
'APPROVED'
,
'review_type'
=>
'APPROVED'
,
...
@@ -75,4 +75,17 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
...
@@ -75,4 +75,17 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
expect
(
review
.
submitted_at
).
to
be_nil
expect
(
review
.
submitted_at
).
to
be_nil
end
end
end
end
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
review_id:
999
,
merge_request_id:
42
}
other_attributes
=
{
something_else:
'_something_else_'
}
review
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
review
.
github_identifiers
).
to
eq
(
github_identifiers
)
end
end
end
end
spec/lib/gitlab/github_import/representation/pull_request_spec.rb
View file @
7581f866
...
@@ -288,4 +288,16 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do
...
@@ -288,4 +288,16 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do
expect
(
object
.
truncated_title
).
to
eq
(
'foo'
)
expect
(
object
.
truncated_title
).
to
eq
(
'foo'
)
end
end
end
end
describe
'#github_identifiers'
do
it
'returns a hash with needed identifiers'
do
github_identifiers
=
{
iid:
1
}
other_attributes
=
{
something_else:
'_something_else_'
}
pr
=
described_class
.
new
(
github_identifiers
.
merge
(
other_attributes
))
expect
(
pr
.
github_identifiers
).
to
eq
(
github_identifiers
.
merge
(
issuable_type:
'MergeRequest'
))
end
end
end
end
spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
View file @
7581f866
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
GithubImport
::
ObjectImporter
do
RSpec
.
describe
Gitlab
::
GithubImport
::
ObjectImporter
,
:aggregate_failures
do
let
(
:worker
)
do
let
(
:worker
)
do
Class
.
new
do
Class
.
new
do
def
self
.
name
def
self
.
name
...
@@ -26,9 +26,15 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -26,9 +26,15 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
let
(
:importer_class
)
{
double
(
:importer_class
,
name:
'klass_name'
)
}
let
(
:importer_class
)
{
double
(
:importer_class
,
name:
'klass_name'
)
}
let
(
:importer_instance
)
{
double
(
:importer_instance
)
}
let
(
:importer_instance
)
{
double
(
:importer_instance
)
}
let
(
:client
)
{
double
(
:client
)
}
let
(
:client
)
{
double
(
:client
)
}
let
(
:github_identifiers
)
do
{
some_id:
1
,
some_type:
'_some_type_'
}
end
before
do
let
(
:representation_class
)
do
stub_const
(
'MockRepresantation'
,
Class
.
new
do
Class
.
new
do
include
Gitlab
::
GithubImport
::
Representation
::
ToHash
include
Gitlab
::
GithubImport
::
Representation
::
ToHash
include
Gitlab
::
GithubImport
::
Representation
::
ExposeAttribute
include
Gitlab
::
GithubImport
::
Representation
::
ExposeAttribute
...
@@ -41,7 +47,20 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -41,7 +47,20 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
def
initialize
(
attributes
)
def
initialize
(
attributes
)
@attributes
=
attributes
@attributes
=
attributes
end
end
end
)
def
github_identifiers
{
some_id:
1
,
some_type:
'_some_type_'
}
end
end
end
let
(
:stubbed_representation
)
{
representation_class
}
before
do
stub_const
(
'MockRepresantation'
,
stubbed_representation
)
end
end
describe
'#import'
,
:clean_gitlab_redis_cache
do
describe
'#import'
,
:clean_gitlab_redis_cache
do
...
@@ -64,7 +83,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -64,7 +83,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
expect
(
Gitlab
::
GithubImport
::
Logger
)
expect
(
Gitlab
::
GithubImport
::
Logger
)
.
to
receive
(
:info
)
.
to
receive
(
:info
)
.
with
(
.
with
(
github_id
:
1
,
github_id
entifiers:
github_identifiers
,
message:
'starting importer'
,
message:
'starting importer'
,
project_id:
project
.
id
,
project_id:
project
.
id
,
importer:
'klass_name'
importer:
'klass_name'
...
@@ -73,7 +92,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -73,7 +92,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
expect
(
Gitlab
::
GithubImport
::
Logger
)
expect
(
Gitlab
::
GithubImport
::
Logger
)
.
to
receive
(
:info
)
.
to
receive
(
:info
)
.
with
(
.
with
(
github_id
:
1
,
github_id
entifiers:
github_identifiers
,
message:
'importer finished'
,
message:
'importer finished'
,
project_id:
project
.
id
,
project_id:
project
.
id
,
importer:
'klass_name'
importer:
'klass_name'
...
@@ -101,7 +120,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -101,7 +120,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
expect
(
Gitlab
::
GithubImport
::
Logger
)
expect
(
Gitlab
::
GithubImport
::
Logger
)
.
to
receive
(
:info
)
.
to
receive
(
:info
)
.
with
(
.
with
(
github_id
:
1
,
github_id
entifiers:
github_identifiers
,
message:
'starting importer'
,
message:
'starting importer'
,
project_id:
project
.
id
,
project_id:
project
.
id
,
importer:
'klass_name'
importer:
'klass_name'
...
@@ -125,21 +144,25 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
...
@@ -125,21 +144,25 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
expect
(
project
.
import_failures
.
last
.
exception_message
).
to
eq
(
'some error'
)
expect
(
project
.
import_failures
.
last
.
exception_message
).
to
eq
(
'some error'
)
end
end
it
'logs error when representation does not have a github_i
d'
do
context
'without github_identifiers define
d'
do
expect
(
importer_class
).
not_to
receive
(
:new
)
let
(
:stubbed_representation
)
{
representation_class
.
instance_eval
{
undef_method
:github_identifiers
}
}
expect
(
Gitlab
::
Import
::
ImportFailureService
)
it
'logs error when representation does not have a github_id'
do
.
to
receive
(
:track
)
expect
(
importer_class
).
not_to
receive
(
:new
)
.
with
(
project_id:
project
.
id
,
exception:
a_kind_of
(
KeyError
),
error_source:
'klass_name'
,
fail_import:
true
)
.
and_call_original
expect
{
worker
.
import
(
project
,
client
,
{
'number'
=>
10
})
}
expect
(
Gitlab
::
Import
::
ImportFailureService
)
.
to
raise_error
(
KeyError
,
'key not found: :github_id'
)
.
to
receive
(
:track
)
.
with
(
project_id:
project
.
id
,
exception:
a_kind_of
(
NoMethodError
),
error_source:
'klass_name'
,
fail_import:
true
)
.
and_call_original
expect
{
worker
.
import
(
project
,
client
,
{
'number'
=>
10
})
}
.
to
raise_error
(
NoMethodError
,
/^undefined method `github_identifiers/
)
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment