Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gpt
large_projects
gitlabhq1
Commits
35017655
Commit
35017655
authored
6 years ago
by
Jarka Košanová
Browse files
Options
Download
Email Patches
Plain Diff
Prepare banzai for extracting epics in EE
parent
6ea674d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
14 deletions
+35
-14
lib/banzai/filter/issuable_state_filter.rb
lib/banzai/filter/issuable_state_filter.rb
+6
-2
lib/banzai/issuable_extractor.rb
lib/banzai/issuable_extractor.rb
+29
-12
No files found.
lib/banzai/filter/issuable_state_filter.rb
View file @
35017655
...
...
@@ -18,7 +18,7 @@ module Banzai
issuables
=
extractor
.
extract
([
doc
])
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
)
node
.
content
+=
" (
#{
issuable
.
state
}
)"
...
...
@@ -31,7 +31,11 @@ module Banzai
private
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
)
issuable
.
project
!=
project
||
(
issuable
.
respond_to?
(
:group
)
&&
issuable
.
group
!=
group
)
end
def
can_read_cross_project?
...
...
This diff is collapsed.
Click to expand it.
lib/banzai/issuable_extractor.rb
View file @
35017655
...
...
@@ -9,10 +9,7 @@ module Banzai
# so we can avoid N+1 queries problem
class
IssuableExtractor
QUERY
=
%q(
descendant-or-self::a[contains(concat(" ", @class, " "), " gfm ")]
[@data-reference-type="issue" or @data-reference-type="merge_request"]
)
.
freeze
prepend
EE
::
Banzai
::
IssuableExtractor
attr_reader
:context
...
...
@@ -24,21 +21,41 @@ module Banzai
# Returns Hash in the form { node => issuable_instance }
def
extract
(
documents
)
nodes
=
documents
.
flat_map
do
|
document
|
document
.
xpath
(
QUERY
)
document
.
xpath
(
query
)
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
def
issuables_for_nodes
(
nodes
)
result
=
{}
parsers
.
each
do
|
parser
|
result
.
merge!
(
parser
.
records_for_nodes
(
nodes
))
end
merge_request_parser
=
result
end
def
parsers
[
Banzai
::
ReferenceParser
::
IssueParser
.
new
(
context
),
Banzai
::
ReferenceParser
::
MergeRequestParser
.
new
(
context
)
]
end
issuables_for_nodes
=
issue_parser
.
records_for_nodes
(
nodes
).
merge
(
merge_request_parser
.
records_for_nodes
(
nodes
)
def
query
%Q(
descendant-or-self::a[contains(concat(" ", @class, " "), " gfm ")]
[
#{
reference_types
}
]
)
end
# The project for the issue/MR might be pending for deletion!
# Filter them out because we don't care about them.
issuables_for_nodes
.
select
{
|
node
,
issuable
|
issuable
.
project
}
def
reference_types
'@data-reference-type="issue" or @data-reference-type="merge_request"'
end
end
end
This diff is collapsed.
Click to expand it.
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