BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d45a6b29
Unverified
Commit
d45a6b29
authored
Jul 29, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate issue/mr labels from act_as_taggable to own labels
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
6fb9badc
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
45 additions
and
23 deletions
+45
-23
base_finder.rb
app/finders/base_finder.rb
+1
-1
labels_helper.rb
app/helpers/labels_helper.rb
+3
-3
issuable.rb
app/models/concerns/issuable.rb
+2
-0
issue.rb
app/models/issue.rb
+0
-3
label.rb
app/models/label.rb
+5
-0
merge_request.rb
app/models/merge_request.rb
+0
-3
project.rb
app/models/project.rb
+2
-9
20140729152420_migrate_taggable_labels.rb
db/migrate/20140729152420_migrate_taggable_labels.rb
+27
-0
schema.rb
db/schema.rb
+1
-1
issues_labels.rb
lib/gitlab/issues_labels.rb
+4
-3
No files found.
app/finders/base_finder.rb
View file @
d45a6b29
...
@@ -125,7 +125,7 @@ class BaseFinder
...
@@ -125,7 +125,7 @@ class BaseFinder
def
by_label
(
items
)
def
by_label
(
items
)
if
params
[
:label_name
].
present?
if
params
[
:label_name
].
present?
items
=
items
.
tagged_with
(
params
[
:label_name
])
items
=
items
.
joins
(
:labels
).
where
(
"labels.title = ?"
,
params
[
:label_name
])
end
end
items
items
...
...
app/helpers/labels_helper.rb
View file @
d45a6b29
module
LabelsHelper
module
LabelsHelper
def
issue_label_names
def
issue_label_names
@project
.
issues_labels
.
map
(
&
:nam
e
)
@project
.
labels
.
pluck
(
:titl
e
)
end
end
def
labels_autocomplete_source
def
labels_autocomplete_source
labels
=
@project
.
issues_
labels
labels
=
@project
.
labels
labels
=
labels
.
map
{
|
l
|
{
label:
l
.
name
,
value:
l
.
name
}
}
labels
=
labels
.
map
{
|
l
|
{
label:
l
.
name
,
value:
l
.
name
}
}
labels
.
to_json
labels
.
to_json
end
end
...
...
app/models/concerns/issuable.rb
View file @
d45a6b29
...
@@ -13,6 +13,8 @@ module Issuable
...
@@ -13,6 +13,8 @@ module Issuable
belongs_to
:assignee
,
class_name:
"User"
belongs_to
:assignee
,
class_name:
"User"
belongs_to
:milestone
belongs_to
:milestone
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:notes
,
as: :noteable
,
dependent: :destroy
has_many
:label_links
,
as: :target
,
dependent: :destroy
has_many
:labels
,
through: :label_links
validates
:author
,
presence:
true
validates
:author
,
presence:
true
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
...
...
app/models/issue.rb
View file @
d45a6b29
...
@@ -32,9 +32,6 @@ class Issue < ActiveRecord::Base
...
@@ -32,9 +32,6 @@ class Issue < ActiveRecord::Base
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:of_user_team
,
->
(
team
)
{
where
(
project_id:
team
.
project_ids
,
assignee_id:
team
.
member_ids
)
}
scope
:of_user_team
,
->
(
team
)
{
where
(
project_id:
team
.
project_ids
,
assignee_id:
team
.
member_ids
)
}
acts_as_taggable_on
:labels
scope
:cared
,
->
(
user
)
{
where
(
assignee_id:
user
)
}
scope
:cared
,
->
(
user
)
{
where
(
assignee_id:
user
)
}
scope
:open_for
,
->
(
user
)
{
opened
.
assigned_to
(
user
)
}
scope
:open_for
,
->
(
user
)
{
opened
.
assigned_to
(
user
)
}
...
...
app/models/label.rb
View file @
d45a6b29
...
@@ -4,4 +4,9 @@ class Label < ActiveRecord::Base
...
@@ -4,4 +4,9 @@ class Label < ActiveRecord::Base
validates
:color
,
format:
{
with:
/\A\#[0-9A-Fa-f]{3}{1,2}+\Z/
},
allow_blank:
true
validates
:color
,
format:
{
with:
/\A\#[0-9A-Fa-f]{3}{1,2}+\Z/
},
allow_blank:
true
validates
:project
,
presence:
true
validates
:project
,
presence:
true
validates
:title
,
presence:
true
def
name
title
end
end
end
app/models/merge_request.rb
View file @
d45a6b29
...
@@ -47,9 +47,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -47,9 +47,6 @@ class MergeRequest < ActiveRecord::Base
attr_accessor
:can_be_created
,
:compare_failed
,
attr_accessor
:can_be_created
,
:compare_failed
,
:compare_commits
,
:compare_diffs
:compare_commits
,
:compare_diffs
ActsAsTaggableOn
.
strict_case_match
=
true
acts_as_taggable_on
:labels
state_machine
:state
,
initial: :opened
do
state_machine
:state
,
initial: :opened
do
event
:close
do
event
:close
do
transition
[
:reopened
,
:opened
]
=>
:closed
transition
[
:reopened
,
:opened
]
=>
:closed
...
...
app/models/project.rb
View file @
d45a6b29
...
@@ -41,8 +41,7 @@ class Project < ActiveRecord::Base
...
@@ -41,8 +41,7 @@ class Project < ActiveRecord::Base
default_value_for
:snippets_enabled
,
gitlab_config_features
.
snippets
default_value_for
:snippets_enabled
,
gitlab_config_features
.
snippets
ActsAsTaggableOn
.
strict_case_match
=
true
ActsAsTaggableOn
.
strict_case_match
=
true
acts_as_taggable_on
:tags
acts_as_taggable_on
:tags
,
:issues_default_labels
attr_accessor
:new_default_branch
attr_accessor
:new_default_branch
...
@@ -71,6 +70,7 @@ class Project < ActiveRecord::Base
...
@@ -71,6 +70,7 @@ class Project < ActiveRecord::Base
# Merge requests from source project should be kept when source project was removed
# 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
:fork_merge_requests
,
foreign_key:
"source_project_id"
,
class_name:
MergeRequest
has_many
:issues
,
->
{
order
"state DESC, created_at DESC"
},
dependent: :destroy
has_many
:issues
,
->
{
order
"state DESC, created_at DESC"
},
dependent: :destroy
has_many
:labels
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:services
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:events
,
dependent: :destroy
has_many
:milestones
,
dependent: :destroy
has_many
:milestones
,
dependent: :destroy
...
@@ -282,13 +282,6 @@ class Project < ActiveRecord::Base
...
@@ -282,13 +282,6 @@ class Project < ActiveRecord::Base
self
.
id
self
.
id
end
end
# Tags are shared by issues and merge requests
def
issues_labels
@issues_labels
||=
(
issues_default_labels
+
merge_requests
.
tags_on
(
:labels
)
+
issues
.
tags_on
(
:labels
)).
uniq
.
sort_by
(
&
:name
)
end
def
issue_exists?
(
issue_id
)
def
issue_exists?
(
issue_id
)
if
used_default_issues_tracker?
if
used_default_issues_tracker?
self
.
issues
.
where
(
iid:
issue_id
).
first
.
present?
self
.
issues
.
where
(
iid:
issue_id
).
first
.
present?
...
...
db/migrate/20140729152420_migrate_taggable_labels.rb
0 → 100644
View file @
d45a6b29
class
MigrateTaggableLabels
<
ActiveRecord
::
Migration
def
up
taggings
=
ActsAsTaggableOn
::
Tagging
.
where
(
taggable_type:
[
'Issue'
,
'MergeRequest'
],
context:
'labels'
)
taggings
.
find_each
(
batch_size:
500
)
do
|
tagging
|
create_label_from_tagging
(
tagging
)
end
end
def
down
Label
.
destroy_all
LabelLink
.
destroy_all
end
private
def
create_label_from_tagging
(
tagging
)
target
=
tagging
.
taggable
label_name
=
tagging
.
tag
.
name
label
=
target
.
project
.
labels
.
find_or_create_by
(
title:
label_name
)
if
LabelLink
.
create
(
label:
label
,
target:
target
)
print
'.'
else
print
'F'
end
end
end
db/schema.rb
View file @
d45a6b29
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201407291
45339
)
do
ActiveRecord
::
Schema
.
define
(
version:
201407291
52420
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
lib/gitlab/issues_labels.rb
View file @
d45a6b29
...
@@ -18,10 +18,11 @@ module Gitlab
...
@@ -18,10 +18,11 @@ module Gitlab
end
end
def
generate
(
project
)
def
generate
(
project
)
labels
=
important_labels
+
warning_labels
+
neutral_labels
+
positive_labels
label
_name
s
=
important_labels
+
warning_labels
+
neutral_labels
+
positive_labels
project
.
issues_default_label_list
=
labels
label_names
.
each
do
|
label_name
|
project
.
save
project
.
labels
.
create
(
title:
label_name
)
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