Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
5918054ea053
Commit
5918054e
authored
May 12, 2016
by
Robert Speicher
Browse files
Reduce duplication and branching logic in EventsHelper
Remove unused methods from Event model
parent
1beee64e7408
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/helpers/events_helper.rb
View file @
5918054e
...
...
@@ -57,11 +57,7 @@
words
<<
event
.
ref_name
words
<<
"at"
elsif
event
.
commented?
if
event
.
commit_note?
words
<<
event
.
note_short_commit_id
else
words
<<
"#
#{
truncate
event
.
note_target_iid
}
"
end
words
<<
event
.
note_target_reference
words
<<
"at"
elsif
event
.
milestone?
words
<<
"#
#{
event
.
target_iid
}
"
if
event
.
target_iid
...
...
@@ -89,16 +85,7 @@
event
.
note_target
)
elsif
event
.
note?
if
event
.
note_target
if
event
.
commit_note?
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_commit_id
,
anchor:
dom_id
(
event
.
target
))
elsif
event
.
project_snippet_note?
namespace_project_snippet_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_target
)
else
event_note_target_path
(
event
)
end
event_note_target_path
(
event
)
end
elsif
event
.
push?
push_event_feed_url
(
event
)
...
...
@@ -135,8 +122,15 @@
def
event_note_target_path
(
event
)
if
event
.
note?
&&
event
.
commit_note?
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_target
)
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_target
,
anchor:
dom_id
(
event
.
target
))
elsif
event
.
project_snippet_note?
namespace_project_snippet_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_target
,
anchor:
dom_id
(
event
.
target
))
else
polymorphic_path
([
event
.
project
.
namespace
.
becomes
(
Namespace
),
event
.
project
,
event
.
note_target
],
...
...
@@ -140,9 +134,9 @@
else
polymorphic_path
([
event
.
project
.
namespace
.
becomes
(
Namespace
),
event
.
project
,
event
.
note_target
],
anchor:
dom_id
(
event
.
target
))
anchor:
dom_id
(
event
.
target
))
end
end
def
event_note_title_html
(
event
)
if
event
.
note_target
...
...
@@ -144,27 +138,9 @@
end
end
def
event_note_title_html
(
event
)
if
event
.
note_target
if
event
.
commit_note?
link_to
(
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_commit_id
,
anchor:
dom_id
(
event
.
target
)),
title:
event
.
target_title
,
class:
"commit_short_id"
)
do
"
#{
event
.
note_target_type
}
#{
event
.
note_short_commit_id
}
"
end
elsif
event
.
project_snippet_note?
link_to
(
namespace_project_snippet_path
(
event
.
project
.
namespace
,
event
.
project
,
event
.
note_target
),
title:
event
.
project
.
name
)
do
"
#{
event
.
note_target_type
}
#{
truncate
event
.
note_target
.
to_reference
}
"
end
else
link_to
event_note_target_path
(
event
),
title:
event
.
target_title
do
"
#{
event
.
note_target_type
}
#{
truncate
event
.
note_target
.
to_reference
}
"
end
link_to
(
event_note_target_path
(
event
),
title:
event
.
target_title
,
class:
'has-tooltip'
)
do
"
#{
event
.
note_target_type
}
#{
event
.
note_target_reference
}
"
end
else
...
...
@@ -169,8 +145,6 @@
end
else
content_tag
:strong
do
"(deleted)"
end
content_tag
(
:strong
,
'(deleted)'
)
end
end
...
...
app/models/event.rb
View file @
5918054e
...
...
@@ -266,11 +266,7 @@
branch?
&&
project
.
default_branch
!=
branch_name
end
def
note_commit_id
target
.
commit_id
end
def
target_iid
target
.
respond_to?
(
:iid
)
?
target
.
iid
:
target_id
end
...
...
@@ -273,11 +269,7 @@
def
target_iid
target
.
respond_to?
(
:iid
)
?
target
.
iid
:
target_id
end
def
note_short_commit_id
Commit
.
truncate_sha
(
note_commit_id
)
end
def
commit_note?
target
.
for_commit?
end
...
...
@@ -302,7 +294,10 @@
end
end
def
note_target_iid
if
note_target
.
respond_to?
(
:iid
)
note_target
.
iid
def
note_target_reference
return
unless
note_target
# Commit#to_reference returns the full SHA, but we want the short one here
if
commit_note?
note_target
.
short_id
else
...
...
@@ -308,6 +303,6 @@
else
note_target
_id
end
.
to_s
note_target
.
to_reference
end
end
def
note_target_type
...
...
app/models/project.rb
View file @
5918054e
...
...
@@ -50,6 +50,8 @@
attr_accessor
:new_default_branch
attr_accessor
:old_path_with_namespace
alias_attribute
:title
,
:name
# Relations
belongs_to
:creator
,
foreign_key:
'creator_id'
,
class_name:
'User'
belongs_to
:group
,
->
{
where
(
type:
Group
)
},
foreign_key:
'namespace_id'
...
...
Write
Preview
Supports
Markdown
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