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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
d3f5fd33
Commit
d3f5fd33
authored
Feb 04, 2019
by
Felipe Artur
Committed by
Sean McGivern
Feb 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix template labels
parent
fa3a2f9e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
3 deletions
+71
-3
app/models/project.rb
app/models/project.rb
+1
-1
changelogs/unreleased/issue_55744.yml
changelogs/unreleased/issue_55744.yml
+5
-0
db/post_migrate/20190131122559_fix_null_type_labels.rb
db/post_migrate/20190131122559_fix_null_type_labels.rb
+23
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/fix_null_type_labels_spec.rb
spec/migrations/fix_null_type_labels_spec.rb
+36
-0
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+5
-1
No files found.
app/models/project.rb
View file @
d3f5fd33
...
...
@@ -1068,7 +1068,7 @@ class Project < ActiveRecord::Base
# rubocop: disable CodeReuse/ServiceClass
def
create_labels
Label
.
templates
.
each
do
|
label
|
params
=
label
.
attributes
.
except
(
'id'
,
'template'
,
'created_at'
,
'updated_at'
)
params
=
label
.
attributes
.
except
(
'id'
,
'template'
,
'created_at'
,
'updated_at'
,
'type'
)
Labels
::
FindOrCreateService
.
new
(
nil
,
self
,
params
).
execute
(
skip_authorization:
true
)
end
end
...
...
changelogs/unreleased/issue_55744.yml
0 → 100644
View file @
d3f5fd33
---
title
:
Fix template labels not being created on new projects
merge_request
:
24803
author
:
type
:
fixed
db/post_migrate/20190131122559_fix_null_type_labels.rb
0 → 100644
View file @
d3f5fd33
# frozen_string_literal: true
class
FixNullTypeLabels
<
ActiveRecord
::
Migration
[
5.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
update_column_in_batches
(
:labels
,
:type
,
'ProjectLabel'
)
do
|
table
,
query
|
query
.
where
(
table
[
:project_id
].
not_eq
(
nil
)
.
and
(
table
[
:template
].
eq
(
false
))
.
and
(
table
[
:type
].
eq
(
nil
))
)
end
end
def
down
# no action
end
end
db/schema.rb
View file @
d3f5fd33
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201901
24200344
)
do
ActiveRecord
::
Schema
.
define
(
version:
201901
31122559
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/fix_null_type_labels_spec.rb
0 → 100644
View file @
d3f5fd33
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20190131122559_fix_null_type_labels'
)
describe
FixNullTypeLabels
,
:migration
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:labels
)
{
table
(
:labels
)
}
before
do
group
=
namespaces
.
create
(
name:
'labels-test-project'
,
path:
'labels-test-project'
,
type:
'Group'
)
project
=
projects
.
create!
(
namespace_id:
group
.
id
,
name:
'labels-test-group'
,
path:
'labels-test-group'
)
@template_label
=
labels
.
create
(
title:
'template'
,
template:
true
)
@project_label
=
labels
.
create
(
title:
'project label'
,
project_id:
project
.
id
,
type:
'ProjectLabel'
)
@group_label
=
labels
.
create
(
title:
'group_label'
,
group_id:
group
.
id
,
type:
'GroupLabel'
)
@broken_label_1
=
labels
.
create
(
title:
'broken 1'
,
project_id:
project
.
id
)
@broken_label_2
=
labels
.
create
(
title:
'broken 2'
,
project_id:
project
.
id
)
end
describe
'#up'
do
it
'fix labels with type missing'
do
migration
.
up
# Labels that requires type change
expect
(
@broken_label_1
.
reload
.
type
).
to
eq
(
'ProjectLabel'
)
expect
(
@broken_label_2
.
reload
.
type
).
to
eq
(
'ProjectLabel'
)
# Labels out of scope
expect
(
@template_label
.
reload
.
type
).
to
be_nil
expect
(
@project_label
.
reload
.
type
).
to
eq
(
'ProjectLabel'
)
expect
(
@group_label
.
reload
.
type
).
to
eq
(
'GroupLabel'
)
end
end
end
spec/services/projects/create_service_spec.rb
View file @
d3f5fd33
...
...
@@ -16,7 +16,11 @@ describe Projects::CreateService, '#execute' do
Label
.
create
(
title:
"bug"
,
template:
true
)
project
=
create_project
(
user
,
opts
)
expect
(
project
.
labels
).
not_to
be_empty
created_label
=
project
.
reload
.
labels
.
last
expect
(
created_label
.
type
).
to
eq
(
'ProjectLabel'
)
expect
(
created_label
.
project_id
).
to
eq
(
project
.
id
)
expect
(
created_label
.
title
).
to
eq
(
'bug'
)
end
context
'user namespace'
do
...
...
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