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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
07709c55
Commit
07709c55
authored
Sep 29, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unfold references for group labels when moving issue to another project
parent
484f19ed
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
275 additions
and
79 deletions
+275
-79
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+2
-2
app/models/group_label.rb
app/models/group_label.rb
+17
-0
app/models/label.rb
app/models/label.rb
+0
-24
app/models/project_label.rb
app/models/project_label.rb
+24
-0
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+36
-3
lib/gitlab/gfm/reference_rewriter.rb
lib/gitlab/gfm/reference_rewriter.rb
+17
-1
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+82
-0
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
+23
-3
spec/models/group_label_spec.rb
spec/models/group_label_spec.rb
+28
-0
spec/models/label_spec.rb
spec/models/label_spec.rb
+0
-46
spec/models/project_label_spec.rb
spec/models/project_label_spec.rb
+46
-0
No files found.
app/helpers/labels_helper.rb
View file @
07709c55
...
...
@@ -115,8 +115,8 @@ module LabelsHelper
span
.
html_safe
end
def
render_colored_cross_project_label
(
label
,
tooltip:
true
)
label_suffix
=
label
.
project
.
name_with_namespace
def
render_colored_cross_project_label
(
label
,
source_project
=
nil
,
tooltip:
true
)
label_suffix
=
source_project
?
source_project
.
name_with_namespace
:
label
.
project
.
name_with_namespace
label_suffix
=
" <i>in
#{
escape_once
(
label_suffix
)
}
</i>"
render_colored_label
(
label
,
label_suffix
,
tooltip:
tooltip
)
end
...
...
app/models/group_label.rb
View file @
07709c55
...
...
@@ -2,4 +2,21 @@ class GroupLabel < Label
belongs_to
:group
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
(
from_project
=
nil
,
format: :id
)
format_reference
=
label_format_reference
(
format
)
"
#{
self
.
class
.
reference_prefix
}#{
format_reference
}
"
end
end
app/models/label.rb
View file @
07709c55
...
...
@@ -73,30 +73,6 @@ class Label < ActiveRecord::Base
nil
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(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
end
def
open_issues_count
(
user
=
nil
,
project
=
nil
)
issues_count
(
user
,
project_id:
project
.
try
(
:id
)
||
project_id
,
state:
'opened'
)
end
...
...
app/models/project_label.rb
View file @
07709c55
...
...
@@ -7,6 +7,30 @@ 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
end
private
def
title_must_not_exist_at_group_level
...
...
lib/banzai/filter/label_reference_filter.rb
View file @
07709c55
...
...
@@ -70,11 +70,44 @@ module Banzai
end
def
object_link_text
(
object
,
matches
)
if
object
.
is_a?
(
GroupLabel
)
||
object
.
project
==
context
[
:project
]
if
same_group?
(
object
)
&&
namespace_match?
(
matches
)
render_same_project_label
(
object
)
elsif
same_project?
(
object
)
render_same_project_label
(
object
)
else
render_cross_project_label
(
object
,
matches
)
end
end
def
same_group?
(
object
)
object
.
is_a?
(
GroupLabel
)
&&
object
.
group
==
project
.
group
end
def
namespace_match?
(
matches
)
matches
[
:project
].
blank?
||
matches
[
:project
]
==
project
.
path_with_namespace
end
def
same_project?
(
object
)
object
.
is_a?
(
ProjectLabel
)
&&
object
.
project
==
project
end
def
project
context
[
:project
]
end
def
render_same_project_label
(
object
)
LabelsHelper
.
render_colored_label
(
object
)
end
def
render_cross_project_label
(
object
,
matches
)
source_project
=
if
matches
[
:project
]
Project
.
find_with_namespace
(
matches
[
:project
])
else
LabelsHelper
.
render_colored_cross_project_label
(
object
)
object
.
project
end
LabelsHelper
.
render_colored_cross_project_label
(
object
,
source_project
)
end
def
unescape_html_entities
(
text
)
...
...
lib/gitlab/gfm/reference_rewriter.rb
View file @
07709c55
...
...
@@ -58,7 +58,7 @@ module Gitlab
referable
=
find_referable
(
reference
)
return
reference
unless
referable
cross_reference
=
referable
.
to_reference
(
target_project
)
cross_reference
=
build_cross_reference
(
referable
,
target_project
)
return
reference
if
reference
==
cross_reference
new_text
=
before
+
cross_reference
+
after
...
...
@@ -72,6 +72,22 @@ module Gitlab
extractor
.
all
.
first
end
def
build_cross_reference
(
referable
,
target_project
)
if
referable
.
respond_to?
(
:project
)
referable
.
to_reference
(
target_project
)
else
to_reference
(
referable
,
target_project
)
end
end
def
to_reference
(
referable
,
target_project
)
if
@source_project
!=
target_project
@source_project
.
to_reference
+
referable
.
to_reference
else
referable
.
to_reference
end
end
def
substitution_valid?
(
substituted
)
@original_html
==
markdown
(
substituted
)
end
...
...
spec/lib/banzai/filter/label_reference_filter_spec.rb
View file @
07709c55
...
...
@@ -305,6 +305,58 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
describe
'group label references'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:group_label
)
{
create
(
:group_label
,
name:
'gfm references'
,
group:
group
)
}
context
'without project reference'
do
let
(
:reference
)
{
group_label
.
to_reference
(
format: :name
)
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
expect
(
doc
.
text
).
to
eq
'See gfm references'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
group_label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
%(Label #{Label.reference_prefix}"#{group_label.name.reverse}")
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'with project reference'
do
let
(
:reference
)
{
project
.
to_reference
+
group_label
.
to_reference
(
format: :name
)
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
group_label
.
name
)
expect
(
doc
.
text
).
to
eq
'See gfm references'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
group_label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
%(Label #{project.to_reference}#{Label.reference_prefix}"#{group_label.name.reverse}")
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
end
describe
'cross project label references'
do
context
'valid project referenced'
do
let
(
:another_project
)
{
create
(
:empty_project
,
:public
)
}
...
...
@@ -339,4 +391,34 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
end
describe
'cross group label references'
do
context
'valid project referenced'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
group
)
}
let
(
:another_group
)
{
create
(
:group
)
}
let
(
:another_project
)
{
create
(
:empty_project
,
:public
,
namespace:
another_group
)
}
let
(
:project_name
)
{
another_project
.
name_with_namespace
}
let
(
:group_label
)
{
create
(
:group_label
,
group:
another_group
,
color:
'#00ff00'
)
}
let
(
:reference
)
{
another_project
.
to_reference
+
group_label
.
to_reference
}
let!
(
:result
)
{
reference_filter
(
"See
#{
reference
}
"
,
project:
project
)
}
it
'points to referenced project issues page'
do
expect
(
result
.
css
(
'a'
).
first
.
attr
(
'href'
))
.
to
eq
urls
.
namespace_project_issues_url
(
another_project
.
namespace
,
another_project
,
label_name:
group_label
.
name
)
end
it
'has valid color'
do
expect
(
result
.
css
(
'a span'
).
first
.
attr
(
'style'
))
.
to
match
/background-color: #00ff00/
end
it
'contains cross project content'
do
expect
(
result
.
css
(
'a'
).
first
.
text
).
to
eq
"
#{
group_label
.
name
}
in
#{
project_name
}
"
end
end
end
end
spec/lib/gitlab/gfm/reference_rewriter_spec.rb
View file @
07709c55
...
...
@@ -2,8 +2,8 @@ require 'spec_helper'
describe
Gitlab
::
Gfm
::
ReferenceRewriter
do
let
(
:text
)
{
'some text'
}
let
(
:old_project
)
{
create
(
:project
)
}
let
(
:new_project
)
{
create
(
:project
)
}
let
(
:old_project
)
{
create
(
:project
,
name:
'old'
)
}
let
(
:new_project
)
{
create
(
:project
,
name:
'new'
)
}
let
(
:user
)
{
create
(
:user
)
}
before
{
old_project
.
team
<<
[
user
,
:guest
]
}
...
...
@@ -62,7 +62,7 @@ describe Gitlab::Gfm::ReferenceRewriter do
it
{
is_expected
.
to
eq
"
#{
ref
}
, `#1`,
#{
ref
}
, `#1`"
}
end
context
'description with labels'
do
context
'description with
project
labels'
do
let!
(
:label
)
{
create
(
:label
,
id:
123
,
name:
'test'
,
project:
old_project
)
}
let
(
:project_ref
)
{
old_project
.
to_reference
}
...
...
@@ -76,6 +76,26 @@ describe Gitlab::Gfm::ReferenceRewriter do
it
{
is_expected
.
to
eq
%Q{
#{
project_ref
}
#1 and
#{
project_ref
}
~123}
}
end
end
context
'description with group labels'
do
let
(
:old_group
)
{
create
(
:group
)
}
let!
(
:group_label
)
{
create
(
:group_label
,
id:
321
,
name:
'group label'
,
group:
old_group
)
}
let
(
:project_ref
)
{
old_project
.
to_reference
}
before
do
old_project
.
update
(
namespace:
old_group
)
end
context
'label referenced by id'
do
let
(
:text
)
{
'#1 and ~321'
}
it
{
is_expected
.
to
eq
%Q{
#{
project_ref
}
#1 and
#{
project_ref
}
~321}
}
end
context
'label referenced by text'
do
let
(
:text
)
{
'#1 and ~"group label"'
}
it
{
is_expected
.
to
eq
%Q{
#{
project_ref
}
#1 and
#{
project_ref
}
~321}
}
end
end
end
context
'reference contains milestone'
do
...
...
spec/models/group_label_spec.rb
View file @
07709c55
...
...
@@ -8,4 +8,32 @@ describe GroupLabel, models: true do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:group
)
}
end
describe
'#to_reference'
do
let
(
:label
)
{
create
(
:group_label
)
}
context
'using id'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
end
end
context
'using name'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
%(~"#{label.name}")
end
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
"~
#{
label
.
id
}
"
end
end
context
'using invalid format'
do
it
'raises error'
do
expect
{
label
.
to_reference
(
format: :invalid
)
}
.
to
raise_error
StandardError
,
/Unknown format/
end
end
end
end
spec/models/label_spec.rb
View file @
07709c55
...
...
@@ -45,50 +45,4 @@ describe Label, models: true do
expect
(
label
.
title
).
to
eq
(
'foo & bar?'
)
end
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
}
"
end
end
context
'using name'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
%(~"#{label.name}")
end
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
"~
#{
label
.
id
}
"
end
end
context
'using invalid format'
do
it
'raises error'
do
expect
{
label
.
to_reference
(
format: :invalid
)
}
.
to
raise_error
StandardError
,
/Unknown format/
end
end
context
'cross project reference'
do
let
(
:project
)
{
create
(
:project
)
}
context
'using name'
do
it
'returns cross reference with label name'
do
expect
(
label
.
to_reference
(
project
,
format: :name
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~"
#{
label
.
name
}
")
end
end
context
'using id'
do
it
'returns cross reference with label id'
do
expect
(
label
.
to_reference
(
project
,
format: :id
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~
#{
label
.
id
}
)
end
end
end
end
end
spec/models/project_label_spec.rb
View file @
07709c55
...
...
@@ -42,4 +42,50 @@ describe ProjectLabel, models: true do
end
end
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
}
"
end
end
context
'using name'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
%(~"#{label.name}")
end
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
expect
(
label
.
to_reference
(
format: :name
)).
to
eq
"~
#{
label
.
id
}
"
end
end
context
'using invalid format'
do
it
'raises error'
do
expect
{
label
.
to_reference
(
format: :invalid
)
}
.
to
raise_error
StandardError
,
/Unknown format/
end
end
context
'cross project reference'
do
let
(
:project
)
{
create
(
:project
)
}
context
'using name'
do
it
'returns cross reference with label name'
do
expect
(
label
.
to_reference
(
project
,
format: :name
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~"
#{
label
.
name
}
")
end
end
context
'using id'
do
it
'returns cross reference with label id'
do
expect
(
label
.
to_reference
(
project
,
format: :id
))
.
to
eq
%Q(
#{
label
.
project
.
to_reference
}
~
#{
label
.
id
}
)
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