Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cfedd42b
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,体验更适合开发者的 AI 搜索 >>
提交
cfedd42b
编写于
9月 20, 2016
作者:
D
Douglas Barbosa Alexandre
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ProjectLabel model
上级
e2dd75c0
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
75 addition
and
52 deletion
+75
-52
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-1
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+4
-4
app/models/label.rb
app/models/label.rb
+0
-7
app/models/project.rb
app/models/project.rb
+4
-2
app/models/project_label.rb
app/models/project_label.rb
+5
-0
app/policies/project_label_policy.rb
app/policies/project_label_policy.rb
+1
-3
app/views/projects/labels/_form.html.haml
app/views/projects/labels/_form.html.haml
+1
-1
app/views/projects/labels/edit.html.haml
app/views/projects/labels/edit.html.haml
+1
-1
app/views/projects/labels/new.html.haml
app/views/projects/labels/new.html.haml
+1
-1
db/migrate/20160920191518_set_project_label_type_on_labels.rb
...igrate/20160920191518_set_project_label_type_on_labels.rb
+17
-0
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+1
-1
lib/gitlab/google_code_import/importer.rb
lib/gitlab/google_code_import/importer.rb
+1
-1
spec/factories/labels.rb
spec/factories/labels.rb
+1
-1
spec/models/label_spec.rb
spec/models/label_spec.rb
+24
-28
spec/models/project_label_spec.rb
spec/models/project_label_spec.rb
+11
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
未找到文件。
app/finders/issuable_finder.rb
浏览文件 @
cfedd42b
...
...
@@ -128,7 +128,8 @@ class IssuableFinder
@labels
=
Label
.
where
(
title:
label_names
)
if
projects
@labels
=
@labels
.
where
(
project:
projects
)
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
).
execute
.
select
(
:id
)
@labels
=
@labels
.
where
(
labels:
{
id:
label_ids
})
end
else
@labels
=
Label
.
none
...
...
app/helpers/labels_helper.rb
浏览文件 @
cfedd42b
...
...
@@ -57,21 +57,21 @@ module LabelsHelper
def
edit_label_path
(
label
)
case
label
when
GroupLabel
then
edit_group_label_path
(
label
.
group
,
label
)
else
edit_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
edit_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
def
destroy_label_path
(
label
)
case
label
when
GroupLabel
then
group_label_path
(
label
.
group
,
label
)
else
namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
def
toggle_subscription_label_path
(
label
)
case
label
when
GroupLabel
then
toggle_subscription_group_label_path
(
label
.
group
,
label
)
else
toggle_subscription_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
when
ProjectLabel
then
toggle_subscription_namespace_project_label_path
(
label
.
project
.
namespace
,
label
.
project
,
label
)
end
end
...
...
@@ -79,7 +79,7 @@ module LabelsHelper
title
,
icon
=
case
label
when
GroupLabel
then
[
'Group'
,
'folder-open'
]
else
[
'Project'
,
'bookmark'
]
when
ProjectLabel
then
[
'Project'
,
'bookmark'
]
end
options
[
:class
]
||=
''
...
...
app/models/label.rb
浏览文件 @
cfedd42b
...
...
@@ -15,15 +15,12 @@ class Label < ActiveRecord::Base
default_value_for
:color
,
DEFAULT_COLOR
belongs_to
:project
has_many
:lists
,
dependent: :destroy
has_many
:label_links
,
dependent: :destroy
has_many
:issues
,
through: :label_links
,
source: :target
,
source_type:
'Issue'
has_many
:merge_requests
,
through: :label_links
,
source: :target
,
source_type:
'MergeRequest'
validates
:color
,
color:
true
,
allow_blank:
false
validates
:project
,
presence:
true
,
if: :project_label?
# Don't allow ',' for label titles
validates
:title
,
presence:
true
,
format:
{
with:
/\A[^,]+\z/
}
...
...
@@ -137,10 +134,6 @@ class Label < ActiveRecord::Base
.
count
end
def
project_label?
type
.
blank?
&&
!
template?
end
def
label_format_reference
(
format
=
:id
)
raise
StandardError
,
'Unknown format'
unless
[
:id
,
:name
].
include?
(
format
)
...
...
app/models/project.rb
浏览文件 @
cfedd42b
...
...
@@ -107,7 +107,7 @@ class Project < ActiveRecord::Base
# Merge requests from source project should be kept when source project was removed
has_many
:fork_merge_requests
,
foreign_key:
'source_project_id'
,
class_name:
MergeRequest
has_many
:issues
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
has_many
:labels
,
dependent: :destroy
,
class_name:
'ProjectLabel'
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:milestones
,
dependent: :destroy
...
...
@@ -730,8 +730,10 @@ class Project < ActiveRecord::Base
def
create_labels
Label
.
templates
.
each
do
|
label
|
label
=
label
.
dup
label
.
template
=
nil
label
.
template
=
false
label
.
project_id
=
self
.
id
label
.
type
=
'ProjectLabel'
label
.
save
end
end
...
...
app/models/project_label.rb
0 → 100644
浏览文件 @
cfedd42b
class
ProjectLabel
<
Label
belongs_to
:project
validates
:project
,
presence:
true
end
app/policies/label_policy.rb
→
app/policies/
project_
label_policy.rb
浏览文件 @
cfedd42b
class
LabelPolicy
<
BasePolicy
class
Project
LabelPolicy
<
BasePolicy
def
rules
return
unless
@user
can!
:admin_label
if
Ability
.
allowed?
(
@user
,
:admin_label
,
@subject
.
project
)
end
end
app/views/projects/labels/_form.html.haml
浏览文件 @
cfedd42b
=
form_for
[
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@label
]
,
html:
{
class:
'form-horizontal label-form js-quick-submit js-requires-input'
}
do
|
f
|
=
form_for
@label
,
as: :label
,
url:
url
,
html:
{
class:
'form-horizontal label-form js-quick-submit js-requires-input'
}
do
|
f
|
=
form_errors
(
@label
)
.form-group
...
...
app/views/projects/labels/edit.html.haml
浏览文件 @
cfedd42b
...
...
@@ -7,4 +7,4 @@
=
icon
(
'bookmark'
)
Edit Project Label
%hr
=
render
'form'
=
render
'form'
,
url:
namespace_project_label_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
,
@label
)
app/views/projects/labels/new.html.haml
浏览文件 @
cfedd42b
...
...
@@ -7,4 +7,4 @@
=
icon
(
'bookmark'
)
New Project Label
%hr
=
render
'form'
=
render
'form'
,
url:
namespace_project_labels_path
(
@project
.
namespace
.
becomes
(
Namespace
),
@project
)
db/migrate/20160920191518_set_project_label_type_on_labels.rb
0 → 100644
浏览文件 @
cfedd42b
class
SetProjectLabelTypeOnLabels
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
update_column_in_batches
(
:labels
,
:type
,
'ProjectLabel'
)
do
|
table
,
query
|
query
.
where
(
table
[
:project_id
].
not_eq
(
nil
))
end
end
def
down
update_column_in_batches
(
:labels
,
:type
,
nil
)
do
|
table
,
query
|
query
.
where
(
table
[
:project_id
].
not_eq
(
nil
))
end
end
end
lib/banzai/filter/label_reference_filter.rb
浏览文件 @
cfedd42b
...
...
@@ -70,7 +70,7 @@ module Banzai
end
def
object_link_text
(
object
,
matches
)
if
object
.
project
.
nil?
||
object
.
project
==
context
[
:project
]
if
object
.
is_a?
(
GroupLabel
)
||
object
.
project
==
context
[
:project
]
LabelsHelper
.
render_colored_label
(
object
)
else
LabelsHelper
.
render_colored_cross_project_label
(
object
)
...
...
lib/gitlab/google_code_import/importer.rb
浏览文件 @
cfedd42b
...
...
@@ -237,7 +237,7 @@ module Gitlab
def
create_label
(
name
)
color
=
nice_label_color
(
name
)
Label
.
create!
(
project_id:
project
.
id
,
name:
name
,
color:
color
)
project
.
labels
.
create!
(
name:
name
,
color:
color
)
end
def
format_content
(
raw_content
)
...
...
spec/factories/labels.rb
浏览文件 @
cfedd42b
FactoryGirl
.
define
do
factory
:label
do
factory
:label
,
class:
ProjectLabel
do
sequence
(
:title
)
{
|
n
|
"label
#{
n
}
"
}
color
"#990000"
project
...
...
spec/models/label_spec.rb
浏览文件 @
cfedd42b
require
'spec_helper'
describe
Label
,
models:
true
do
let
(
:label
)
{
create
(
:label
)
}
describe
'modules'
do
it
{
is_expected
.
to
include_module
(
Referable
)
}
it
{
is_expected
.
to
include_module
(
Subscribable
)
}
end
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
have_many
(
:label_links
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:issues
).
through
(
:label_links
).
source
(
:target
)
}
it
{
is_expected
.
to
have_many
(
:label_links
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:lists
).
dependent
(
:destroy
)
}
end
describe
'modules'
do
subject
{
described_class
}
it
{
is_expected
.
to
include_module
(
Referable
)
}
end
describe
'validation'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:title
)
}
it
'validates color code'
do
expect
(
label
)
.
not_to
allow_value
(
'G-ITLAB'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'AABBCC'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'#AABBCCEE'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'GGHHII'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
'#'
).
for
(
:color
)
expect
(
label
)
.
not_to
allow_value
(
''
).
for
(
:color
)
expect
(
label
)
.
to
allow_value
(
'#AABBCC'
).
for
(
:color
)
expect
(
label
)
.
to
allow_value
(
'#abcdef'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'G-ITLAB'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'AABBCC'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'#AABBCCEE'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'GGHHII'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
'#'
).
for
(
:color
)
is_expected
.
not_to
allow_value
(
''
).
for
(
:color
)
is_expected
.
to
allow_value
(
'#AABBCC'
).
for
(
:color
)
is_expected
.
to
allow_value
(
'#abcdef'
).
for
(
:color
)
end
it
'validates title'
do
expect
(
label
)
.
not_to
allow_value
(
'G,ITLAB'
).
for
(
:title
)
expect
(
label
)
.
not_to
allow_value
(
''
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'GITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'gitlab'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'G?ITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
'G&ITLAB'
).
for
(
:title
)
expect
(
label
)
.
to
allow_value
(
"customer's request"
).
for
(
:title
)
is_expected
.
not_to
allow_value
(
'G,ITLAB'
).
for
(
:title
)
is_expected
.
not_to
allow_value
(
''
).
for
(
:title
)
is_expected
.
to
allow_value
(
'GITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'gitlab'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'G?ITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
'G&ITLAB'
).
for
(
:title
)
is_expected
.
to
allow_value
(
"customer's request"
).
for
(
:title
)
end
end
...
...
@@ -53,6 +47,8 @@ describe Label, models: true do
end
describe
'#to_reference'
do
let
(
:label
)
{
create
(
:label
)
}
context
'using id'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
...
...
spec/models/project_label_spec.rb
0 → 100644
浏览文件 @
cfedd42b
require
'spec_helper'
describe
ProjectLabel
,
models:
true
do
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
end
end
spec/models/project_spec.rb
浏览文件 @
cfedd42b
...
...
@@ -56,7 +56,7 @@ describe Project, models: true do
it
{
is_expected
.
to
have_many
(
:runners
)
}
it
{
is_expected
.
to
have_many
(
:variables
)
}
it
{
is_expected
.
to
have_many
(
:triggers
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:labels
).
class_name
(
'ProjectLabel'
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:users_star_projects
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:environments
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_many
(
:deployments
).
dependent
(
:destroy
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录