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
Boxiang Sun
gitlab-ce
Commits
1d7737ae
Commit
1d7737ae
authored
Oct 15, 2018
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare Banzai to work with group issuables
parent
11611708
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
lib/banzai/filter/issuable_state_filter.rb
lib/banzai/filter/issuable_state_filter.rb
+9
-2
lib/banzai/issuable_extractor.rb
lib/banzai/issuable_extractor.rb
+28
-13
No files found.
lib/banzai/filter/issuable_state_filter.rb
View file @
1d7737ae
...
@@ -18,7 +18,7 @@ module Banzai
...
@@ -18,7 +18,7 @@ module Banzai
issuables
=
extractor
.
extract
([
doc
])
issuables
=
extractor
.
extract
([
doc
])
issuables
.
each
do
|
node
,
issuable
|
issuables
.
each
do
|
node
,
issuable
|
next
if
!
can_read_cross_project?
&&
issuable
.
project
!=
project
next
if
!
can_read_cross_project?
&&
cross_reference?
(
issuable
)
if
VISIBLE_STATES
.
include?
(
issuable
.
state
)
&&
issuable_reference?
(
node
.
inner_html
,
issuable
)
if
VISIBLE_STATES
.
include?
(
issuable
.
state
)
&&
issuable_reference?
(
node
.
inner_html
,
issuable
)
node
.
content
+=
" (
#{
issuable
.
state
}
)"
node
.
content
+=
" (
#{
issuable
.
state
}
)"
...
@@ -31,7 +31,14 @@ module Banzai
...
@@ -31,7 +31,14 @@ module Banzai
private
private
def
issuable_reference?
(
text
,
issuable
)
def
issuable_reference?
(
text
,
issuable
)
text
==
issuable
.
reference_link_text
(
project
||
group
)
CGI
.
unescapeHTML
(
text
)
==
issuable
.
reference_link_text
(
project
||
group
)
end
def
cross_reference?
(
issuable
)
return
true
if
issuable
.
project
!=
project
return
true
if
issuable
.
respond_to?
(
:group
)
&&
issuable
.
group
!=
group
false
end
end
def
can_read_cross_project?
def
can_read_cross_project?
...
...
lib/banzai/issuable_extractor.rb
View file @
1d7737ae
...
@@ -9,13 +9,11 @@ module Banzai
...
@@ -9,13 +9,11 @@ module Banzai
# so we can avoid N+1 queries problem
# so we can avoid N+1 queries problem
class
IssuableExtractor
class
IssuableExtractor
QUERY
=
%q(
descendant-or-self::a[contains(concat(" ", @class, " "), " gfm ")]
[@data-reference-type="issue" or @data-reference-type="merge_request"]
)
.
freeze
attr_reader
:context
attr_reader
:context
ISSUE_REFERENCE_TYPE
=
'@data-reference-type="issue"'
.
freeze
MERGE_REQUEST_REFERENCE_TYPE
=
'@data-reference-type="merge_request"'
.
freeze
# context - An instance of Banzai::RenderContext.
# context - An instance of Banzai::RenderContext.
def
initialize
(
context
)
def
initialize
(
context
)
@context
=
context
@context
=
context
...
@@ -24,21 +22,38 @@ module Banzai
...
@@ -24,21 +22,38 @@ module Banzai
# Returns Hash in the form { node => issuable_instance }
# Returns Hash in the form { node => issuable_instance }
def
extract
(
documents
)
def
extract
(
documents
)
nodes
=
documents
.
flat_map
do
|
document
|
nodes
=
documents
.
flat_map
do
|
document
|
document
.
xpath
(
QUERY
)
document
.
xpath
(
query
)
end
end
issue_parser
=
Banzai
::
ReferenceParser
::
IssueParser
.
new
(
context
)
# The project or group for the issuable might be pending for deletion!
# Filter them out because we don't care about them.
issuables_for_nodes
(
nodes
).
select
{
|
node
,
issuable
|
issuable
.
project
||
issuable
.
group
}
end
private
merge_request_parser
=
def
issuables_for_nodes
(
nodes
)
parsers
.
each_with_object
({})
do
|
parser
,
result
|
result
.
merge!
(
parser
.
records_for_nodes
(
nodes
))
end
end
def
parsers
[
Banzai
::
ReferenceParser
::
IssueParser
.
new
(
context
),
Banzai
::
ReferenceParser
::
MergeRequestParser
.
new
(
context
)
Banzai
::
ReferenceParser
::
MergeRequestParser
.
new
(
context
)
]
end
issuables_for_nodes
=
issue_parser
.
records_for_nodes
(
nodes
).
merge
(
def
query
merge_request_parser
.
records_for_nodes
(
nodes
)
%Q(
descendant-or-self::a[contains(concat(" ", @class, " "), " gfm ")]
[
#{
reference_types
.
join
(
' or '
)
}
]
)
)
end
# The project for the issue/MR might be pending for deletion!
def
reference_types
# Filter them out because we don't care about them.
[
ISSUE_REFERENCE_TYPE
,
MERGE_REQUEST_REFERENCE_TYPE
]
issuables_for_nodes
.
select
{
|
node
,
issuable
|
issuable
.
project
}
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