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
a3ac684e
Commit
a3ac684e
authored
Nov 20, 2017
by
micael.bergeron
Committed by
Micaël Bergeron
Dec 07, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for commit (in mr) to reference filter
parent
78f9fa5a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
12 deletions
+76
-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
+36
-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 @
a3ac684e
...
...
@@ -3,7 +3,7 @@ module RendersNotes
preload_noteable_for_regular_notes
(
notes
)
preload_max_access_for_authors
(
notes
,
@project
)
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
end
...
...
@@ -26,4 +26,13 @@ module RendersNotes
notes
.
each
{
|
n
|
n
.
specialize_for_first_contribution!
(
noteable
)}
end
def
noteable_context
(
noteable
)
case
noteable
when
MergeRequest
{
merge_request:
noteable
}
else
{}
end
end
end
app/models/merge_request.rb
View file @
a3ac684e
...
...
@@ -1042,4 +1042,13 @@ class MergeRequest < ActiveRecord::Base
project
.
merge_requests
.
merged
.
where
(
author_id:
author_id
).
empty?
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
app/models/note.rb
View file @
a3ac684e
...
...
@@ -379,6 +379,42 @@ class Note < ActiveRecord::Base
Gitlab
::
EtagCaching
::
Store
.
new
.
touch
(
key
)
end
def
touch
(
*
args
)
# We're not using an explicit transaction here because this would in all
# cases result in all future queries going to the primary, even if no writes
# are performed.
#
# We touch the noteable first so its SELECT query can run before our writes,
# ensuring it runs on a secondary (if no prior write took place).
touch_noteable
super
end
# By default Rails will issue an "SELECT *" for the relation, which is
# overkill for just updating the timestamps. To work around this we manually
# touch the data so we can SELECT only the columns we need.
def
touch_noteable
# Commits are not stored in the DB so we can't touch them.
return
if
for_commit?
assoc
=
association
(:
noteable
)
noteable_object
=
if
assoc
.
loaded?
noteable
else
# If the object is not loaded (e.g. when notes are loaded async) we
# _only_ want the data we actually need.
assoc
.
scope
.
select
(
:id
,
:
updated_at
).
take
end
noteable_object
&
.
touch
end
def
banzai_render_context
(
field
)
super
.
merge
(
noteable:
noteable
)
end
private
def
keep_around_commit
...
...
app/views/projects/commits/_commit.html.haml
View file @
a3ac684e
...
...
@@ -4,7 +4,7 @@
-
ref
=
local_assigns
.
fetch
(
:ref
)
{
merge_request
&
.
source_branch
}
-
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
)
-# EE-only
...
...
lib/banzai/filter/commit_reference_filter.rb
View file @
a3ac684e
...
...
@@ -24,8 +24,18 @@ module Banzai
def
url_for_object
(
commit
,
project
)
h
=
Gitlab
::
Routing
.
url_helpers
h
.
project_commit_url
(
project
,
commit
,
only_path:
context
[
:only_path
])
noteable
=
context
[
:merge_request
]
||
context
[
:noteable
]
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
def
object_link_text_extras
(
object
,
matches
)
...
...
lib/banzai/object_renderer.rb
View file @
a3ac684e
...
...
@@ -18,10 +18,10 @@ module Banzai
# project - A Project to use for redacting Markdown.
# user - The user viewing the Markdown/HTML documents, if any.
# 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
@user
=
user
@
redaction_context
=
redaction_context
@
context
=
base_context
.
merge
(
context
)
end
# Renders and redacts an Array of objects.
...
...
@@ -48,7 +48,8 @@ module Banzai
pipeline
=
HTML
::
Pipeline
.
new
([])
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
...
...
@@ -73,20 +74,19 @@ module Banzai
# Returns a Banzai context for the given object and attribute.
def
context_for
(
object
,
attribute
)
base_
context
.
merge
(
object
.
banzai_render_context
(
attribute
))
@
context
.
merge
(
object
.
banzai_render_context
(
attribute
))
end
def
base_context
@base_context
||=
@redaction_context
.
merge
(
{
current_user:
user
,
project:
project
,
skip_redaction:
true
)
}
end
def
save_options
return
{}
unless
base_context
[
:xhtml
]
return
{}
unless
@context
[
:xhtml
]
{
save_with:
Nokogiri
::
XML
::
Node
::
SaveOptions
::
AS_XHTML
}
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