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
Jérome Perrin
gitlab-ce
Commits
0e8dd599
Commit
0e8dd599
authored
Oct 11, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move common logic to reference group/project label to Label#to_reference
parent
247859c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
48 deletions
+31
-48
app/models/group_label.rb
app/models/group_label.rb
+1
-26
app/models/label.rb
app/models/label.rb
+28
-0
app/models/project_label.rb
app/models/project_label.rb
+2
-22
No files found.
app/models/group_label.rb
View file @
0e8dd599
...
...
@@ -3,32 +3,7 @@ class GroupLabel < Label
validates
:group
,
presence:
true
##
# Returns the String necessary to reference this GroupLabel in Markdown
#
# format - Symbol format to use (default: :id, optional: :name)
#
# Examples:
#
# GroupLabel.first.to_reference # => "~1"
# GroupLabel.first.to_reference(format: :name) # => "~\"bug\""
#
# Returns a String
#
def
to_reference
(
source_project
=
nil
,
target_project
=
nil
,
format: :id
)
format_reference
=
label_format_reference
(
format
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
if
cross_project_reference?
(
source_project
,
target_project
)
source_project
.
to_reference
+
reference
else
reference
end
end
private
def
cross_project_reference?
(
source_project
,
target_project
)
source_project
&&
target_project
&&
source_project
!=
target_project
super
(
source_project
,
target_project
,
format:
format
)
end
end
app/models/label.rb
View file @
0e8dd599
...
...
@@ -97,8 +97,36 @@ class Label < ActiveRecord::Base
write_attribute
(
:title
,
sanitize_title
(
value
))
if
value
.
present?
end
##
# Returns the String necessary to reference this Label in Markdown
#
# format - Symbol format to use (default: :id, optional: :name)
#
# Examples:
#
# Label.first.to_reference # => "~1"
# Label.first.to_reference(format: :name) # => "~\"bug\""
# Label.first.to_reference(project1, project2) # => "gitlab-org/gitlab-ce~1"
#
# Returns a String
#
def
to_reference
(
source_project
=
nil
,
target_project
=
nil
,
format: :id
)
format_reference
=
label_format_reference
(
format
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
if
cross_project_reference?
(
source_project
,
target_project
)
source_project
.
to_reference
+
reference
else
reference
end
end
private
def
cross_project_reference?
(
source_project
,
target_project
)
source_project
&&
target_project
&&
source_project
!=
target_project
end
def
issues_count
(
user
,
params
=
{})
IssuesFinder
.
new
(
user
,
{
label_name:
title
,
scope:
'all'
}.
merge
(
params
))
.
execute
...
...
app/models/project_label.rb
View file @
0e8dd599
...
...
@@ -7,28 +7,8 @@ class ProjectLabel < Label
delegate
:group
,
to: :project
,
allow_nil:
true
##
# Returns the String necessary to reference this ProjectLabel in Markdown
#
# format - Symbol format to use (default: :id, optional: :name)
#
# Examples:
#
# ProjectLabel.first.to_reference # => "~1"
# ProjectLabel.first.to_reference(format: :name) # => "~\"bug\""
# ProjectLabel.first.to_reference(project) # => "gitlab-org/gitlab-ce~1"
#
# Returns a String
#
def
to_reference
(
from_project
=
nil
,
format: :id
)
format_reference
=
label_format_reference
(
format
)
reference
=
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
if
cross_project_reference?
(
from_project
)
project
.
to_reference
+
reference
else
reference
end
def
to_reference
(
target_project
=
nil
,
format: :id
)
super
(
project
,
target_project
,
format:
format
)
end
private
...
...
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