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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
35d8bc44
Commit
35d8bc44
authored
Apr 19, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor banzai code that finds cross-project labels
parent
dcc45eda
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+21
-15
No files found.
lib/banzai/filter/label_reference_filter.rb
View file @
35d8bc44
...
@@ -18,9 +18,7 @@ module Banzai
...
@@ -18,9 +18,7 @@ module Banzai
def
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
def
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
text
.
gsub
(
pattern
)
do
|
match
|
project
=
project_from_ref
(
$~
[
:project
])
label
=
find_label
(
$~
[
:project
],
$~
[
:label_id
],
$~
[
:label_name
])
params
=
label_params
(
$~
[
:label_id
].
to_i
,
$~
[
:label_name
])
label
=
project
.
labels
.
find_by
(
params
)
if
project
if
label
if
label
yield
match
,
label
.
id
,
$~
[
:project
],
$~
yield
match
,
label
.
id
,
$~
[
:project
],
$~
...
@@ -30,18 +28,12 @@ module Banzai
...
@@ -30,18 +28,12 @@ module Banzai
end
end
end
end
def
url_for_object
(
label
,
project
)
def
find_label
(
project_ref
,
label_id
,
label_name
)
h
=
Gitlab
::
Routing
.
url_helpers
project
=
project_from_ref
(
project_ref
)
h
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
,
return
unless
project
only_path:
context
[
:only_path
])
end
def
object_link_text
(
object
,
matches
)
label_params
=
label_params
(
label_id
,
label_name
)
if
context
[
:project
]
==
object
.
project
project
.
labels
.
find_by
(
label_params
)
LabelsHelper
.
render_colored_label
(
object
)
else
LabelsHelper
.
render_colored_cross_project_label
(
object
)
end
end
end
# Parameters to pass to `Label.find_by` based on the given arguments
# Parameters to pass to `Label.find_by` based on the given arguments
...
@@ -55,7 +47,21 @@ module Banzai
...
@@ -55,7 +47,21 @@ module Banzai
if
name
if
name
{
name:
name
.
tr
(
'"'
,
''
)
}
{
name:
name
.
tr
(
'"'
,
''
)
}
else
else
{
id:
id
}
{
id:
id
.
to_i
}
end
end
def
url_for_object
(
label
,
project
)
h
=
Gitlab
::
Routing
.
url_helpers
h
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
,
only_path:
context
[
:only_path
])
end
def
object_link_text
(
object
,
matches
)
if
context
[
:project
]
==
object
.
project
LabelsHelper
.
render_colored_label
(
object
)
else
LabelsHelper
.
render_colored_cross_project_label
(
object
)
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