Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d3f5fd33
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d3f5fd33
编写于
2月 04, 2019
作者:
F
Felipe Artur
提交者:
Sean McGivern
2月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix template labels
上级
fa3a2f9e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
71 addition
and
3 deletion
+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
未找到文件。
app/models/project.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录