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
3d8fbd12
Commit
3d8fbd12
authored
Nov 20, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for commit (in mr) to reference filter
parent
6b3f0fee
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
12 deletions
+44
-12
app/controllers/concerns/renders_notes.rb
app/controllers/concerns/renders_notes.rb
+10
-1
app/models/merge_request.rb
app/models/merge_request.rb
+9
-0
app/models/note.rb
app/models/note.rb
+4
-0
app/views/projects/commits/_commit.html.haml
app/views/projects/commits/_commit.html.haml
+1
-1
lib/banzai/filter/commit_reference_filter.rb
lib/banzai/filter/commit_reference_filter.rb
+12
-2
lib/banzai/object_renderer.rb
lib/banzai/object_renderer.rb
+8
-8
No files found.
app/controllers/concerns/renders_notes.rb
View file @
3d8fbd12
...
@@ -3,7 +3,7 @@ module RendersNotes
...
@@ -3,7 +3,7 @@ module RendersNotes
preload_noteable_for_regular_notes
(
notes
)
preload_noteable_for_regular_notes
(
notes
)
preload_max_access_for_authors
(
notes
,
@project
)
preload_max_access_for_authors
(
notes
,
@project
)
preload_first_time_contribution_for_authors
(
noteable
,
notes
)
preload_first_time_contribution_for_authors
(
noteable
,
notes
)
Notes
::
RenderService
.
new
(
current_user
).
execute
(
notes
,
@project
)
Notes
::
RenderService
.
new
(
current_user
).
execute
(
notes
,
@project
,
noteable_context
(
noteable
)
)
notes
notes
end
end
...
@@ -26,4 +26,13 @@ module RendersNotes
...
@@ -26,4 +26,13 @@ module RendersNotes
notes
.
each
{
|
n
|
n
.
specialize_for_first_contribution!
(
noteable
)}
notes
.
each
{
|
n
|
n
.
specialize_for_first_contribution!
(
noteable
)}
end
end
def
noteable_context
(
noteable
)
case
noteable
when
MergeRequest
{
merge_request:
noteable
}
else
{}
end
end
end
end
app/models/merge_request.rb
View file @
3d8fbd12
...
@@ -1021,4 +1021,13 @@ class MergeRequest < ActiveRecord::Base
...
@@ -1021,4 +1021,13 @@ class MergeRequest < ActiveRecord::Base
project
.
merge_requests
.
merged
.
where
(
author_id:
author_id
).
empty?
project
.
merge_requests
.
merged
.
where
(
author_id:
author_id
).
empty?
end
end
def
banzai_render_context
(
field
)
# this will be used to reference these commit in the context of the MR
# the URL are built differently
{
merge_request:
self
,
mr_commit_shas:
all_commit_shas
}
end
end
end
app/models/note.rb
View file @
3d8fbd12
...
@@ -405,6 +405,10 @@ class Note < ActiveRecord::Base
...
@@ -405,6 +405,10 @@ class Note < ActiveRecord::Base
noteable_object
&
.
touch
noteable_object
&
.
touch
end
end
def
banzai_render_context
(
field
)
super
.
merge
(
noteable:
noteable
)
end
private
private
def
keep_around_commit
def
keep_around_commit
...
...
app/views/projects/commits/_commit.html.haml
View file @
3d8fbd12
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
-
ref
=
local_assigns
.
fetch
(
:ref
)
{
merge_request
&
.
source_branch
}
-
ref
=
local_assigns
.
fetch
(
:ref
)
{
merge_request
&
.
source_branch
}
-
link
=
commit_path
(
project
,
commit
,
merge_request:
merge_request
)
-
link
=
commit_path
(
project
,
commit
,
merge_request:
merge_request
)
-
cache_key
=
[
project
.
full_path
,
commit
.
id
,
current_application_settings
,
@path
.
presence
,
current_controller?
(
:commits
),
merge_request
.
iid
,
view_details
,
I18n
.
locale
]
-
cache_key
=
[
project
.
full_path
,
commit
.
id
,
current_application_settings
,
@path
.
presence
,
current_controller?
(
:commits
),
merge_request
&
.
iid
,
view_details
,
I18n
.
locale
]
-
cache_key
.
push
(
commit
.
status
(
ref
))
if
commit
.
status
(
ref
)
-
cache_key
.
push
(
commit
.
status
(
ref
))
if
commit
.
status
(
ref
)
=
cache
(
cache_key
,
expires_in:
1
.
day
)
do
=
cache
(
cache_key
,
expires_in:
1
.
day
)
do
...
...
lib/banzai/filter/commit_reference_filter.rb
View file @
3d8fbd12
...
@@ -24,8 +24,18 @@ module Banzai
...
@@ -24,8 +24,18 @@ module Banzai
def
url_for_object
(
commit
,
project
)
def
url_for_object
(
commit
,
project
)
h
=
Gitlab
::
Routing
.
url_helpers
h
=
Gitlab
::
Routing
.
url_helpers
h
.
project_commit_url
(
project
,
commit
,
noteable
=
context
[
:merge_request
]
||
context
[
:noteable
]
only_path:
context
[
:only_path
])
if
noteable
.
is_a?
(
MergeRequest
)
&&
noteable
.
all_commit_shas
.
include?
(
commit
.
id
)
# the internal shas are in the context?
# why not preload in the object?, just make sure we have the same ref
# in all the rendering
h
.
diffs_project_merge_request_url
(
project
,
noteable
,
commit_id:
commit
.
id
)
else
h
.
project_commit_url
(
project
,
commit
,
only_path:
context
[
:only_path
])
end
end
end
def
object_link_text_extras
(
object
,
matches
)
def
object_link_text_extras
(
object
,
matches
)
...
...
lib/banzai/object_renderer.rb
View file @
3d8fbd12
...
@@ -18,10 +18,10 @@ module Banzai
...
@@ -18,10 +18,10 @@ module Banzai
# project - A Project to use for redacting Markdown.
# project - A Project to use for redacting Markdown.
# user - The user viewing the Markdown/HTML documents, if any.
# user - The user viewing the Markdown/HTML documents, if any.
# context - A Hash containing extra attributes to use during redaction
# context - A Hash containing extra attributes to use during redaction
def
initialize
(
project
,
user
=
nil
,
redaction_
context
=
{})
def
initialize
(
project
,
user
=
nil
,
context
=
{})
@project
=
project
@project
=
project
@user
=
user
@user
=
user
@
redaction_context
=
redaction_context
@
context
=
base_context
.
merge
(
context
)
end
end
# Renders and redacts an Array of objects.
# Renders and redacts an Array of objects.
...
@@ -48,7 +48,8 @@ module Banzai
...
@@ -48,7 +48,8 @@ module Banzai
pipeline
=
HTML
::
Pipeline
.
new
([])
pipeline
=
HTML
::
Pipeline
.
new
([])
objects
.
map
do
|
object
|
objects
.
map
do
|
object
|
pipeline
.
to_document
(
Banzai
.
render_field
(
object
,
attribute
))
context
=
context_for
(
object
,
attribute
)
pipeline
.
to_document
(
Banzai
.
render_field
(
object
,
attribute
,
context
))
end
end
end
end
...
@@ -73,20 +74,19 @@ module Banzai
...
@@ -73,20 +74,19 @@ module Banzai
# Returns a Banzai context for the given object and attribute.
# Returns a Banzai context for the given object and attribute.
def
context_for
(
object
,
attribute
)
def
context_for
(
object
,
attribute
)
base_
context
.
merge
(
object
.
banzai_render_context
(
attribute
))
@
context
.
merge
(
object
.
banzai_render_context
(
attribute
))
end
end
def
base_context
def
base_context
@base_context
||=
@redaction_context
.
merge
(
{
current_user:
user
,
current_user:
user
,
project:
project
,
project:
project
,
skip_redaction:
true
skip_redaction:
true
)
}
end
end
def
save_options
def
save_options
return
{}
unless
base_context
[
:xhtml
]
return
{}
unless
@context
[
:xhtml
]
{
save_with:
Nokogiri
::
XML
::
Node
::
SaveOptions
::
AS_XHTML
}
{
save_with:
Nokogiri
::
XML
::
Node
::
SaveOptions
::
AS_XHTML
}
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