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
ad9a98a3
Commit
ad9a98a3
authored
May 08, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
565c2fc4
3f6f40b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
2 deletions
+47
-2
changelogs/unreleased/27987-use-findorcreateservice-to-create-labels.yml
...leased/27987-use-findorcreateservice-to-create-labels.yml
+5
-0
lib/gitlab/bitbucket_import/importer.rb
lib/gitlab/bitbucket_import/importer.rb
+1
-1
spec/features/issuables/markdown_references/jira_spec.rb
spec/features/issuables/markdown_references/jira_spec.rb
+1
-1
spec/lib/gitlab/bitbucket_import/importer_spec.rb
spec/lib/gitlab/bitbucket_import/importer_spec.rb
+40
-0
No files found.
changelogs/unreleased/27987-use-findorcreateservice-to-create-labels.yml
0 → 100644
View file @
ad9a98a3
---
title
:
Use FindOrCreateService to create labels and check for existing ones
merge_request
:
27987
author
:
Matt Duren
type
:
fixed
lib/gitlab/bitbucket_import/importer.rb
View file @
ad9a98a3
...
...
@@ -135,7 +135,7 @@ module Gitlab
def
create_labels
LABELS
.
each
do
|
label_params
|
label
=
::
Labels
::
CreateService
.
new
(
label_params
).
execute
(
project:
project
)
label
=
::
Labels
::
FindOrCreateService
.
new
(
nil
,
project
,
label_params
).
execute
(
skip_authorization:
true
)
if
label
.
valid?
@labels
[
label_params
[
:title
]]
=
label
else
...
...
spec/features/issuables/markdown_references/jira_spec.rb
View file @
ad9a98a3
require
"rails_helper"
describe
"Jira"
,
:js
,
:quarantine
do
describe
"Jira"
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:actual_project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
target_project:
actual_project
,
source_project:
actual_project
)
}
...
...
spec/lib/gitlab/bitbucket_import/importer_spec.rb
View file @
ad9a98a3
...
...
@@ -222,6 +222,46 @@ describe Gitlab::BitbucketImport::Importer do
body:
{}.
to_json
)
end
context
'creating labels on project'
do
before
do
allow
(
importer
).
to
receive
(
:import_wiki
)
end
it
'creates labels as expected'
do
expect
{
importer
.
execute
}.
to
change
{
Label
.
count
}.
from
(
0
).
to
(
Gitlab
::
BitbucketImport
::
Importer
::
LABELS
.
size
)
end
it
'does not fail if label is already existing'
do
label
=
Gitlab
::
BitbucketImport
::
Importer
::
LABELS
.
first
::
Labels
::
CreateService
.
new
(
label
).
execute
(
project:
project
)
expect
{
importer
.
execute
}.
not_to
raise_error
end
it
'does not create new labels'
do
Gitlab
::
BitbucketImport
::
Importer
::
LABELS
.
each
do
|
label
|
create
(
:label
,
project:
project
,
title:
label
[
:title
])
end
expect
{
importer
.
execute
}.
not_to
change
{
Label
.
count
}
end
it
'does not update existing ones'
do
label_title
=
Gitlab
::
BitbucketImport
::
Importer
::
LABELS
.
first
[
:title
]
existing_label
=
create
(
:label
,
project:
project
,
title:
label_title
)
# Reload label from database so we avoid timestamp comparison issues related to time precision when comparing
# attributes later.
existing_label
.
reload
Timecop
.
freeze
(
Time
.
now
+
1
.
minute
)
do
importer
.
execute
label_after_import
=
project
.
labels
.
find
(
existing_label
.
id
)
expect
(
label_after_import
.
attributes
).
to
eq
(
existing_label
.
attributes
)
end
end
end
it
'maps statuses to open or closed'
do
allow
(
importer
).
to
receive
(
:import_wiki
)
...
...
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