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
iv
gitlab-ce
Commits
020e6168
Commit
020e6168
authored
May 12, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce duplication and branching logic in EventsHelper
Remove unused methods from Event model
parent
0ec2ee71
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
54 deletions
+25
-54
app/helpers/events_helper.rb
app/helpers/events_helper.rb
+15
-41
app/models/event.rb
app/models/event.rb
+8
-13
app/models/project.rb
app/models/project.rb
+2
-0
No files found.
app/helpers/events_helper.rb
View file @
020e6168
...
@@ -57,11 +57,7 @@ module EventsHelper
...
@@ -57,11 +57,7 @@ module EventsHelper
words
<<
event
.
ref_name
words
<<
event
.
ref_name
words
<<
"at"
words
<<
"at"
elsif
event
.
commented?
elsif
event
.
commented?
if
event
.
commit_note?
words
<<
event
.
note_target_reference
words
<<
event
.
note_short_commit_id
else
words
<<
"#
#{
truncate
event
.
note_target_iid
}
"
end
words
<<
"at"
words
<<
"at"
elsif
event
.
milestone?
elsif
event
.
milestone?
words
<<
"#
#{
event
.
target_iid
}
"
if
event
.
target_iid
words
<<
"#
#{
event
.
target_iid
}
"
if
event
.
target_iid
...
@@ -89,16 +85,7 @@ module EventsHelper
...
@@ -89,16 +85,7 @@ module EventsHelper
event
.
note_target
)
event
.
note_target
)
elsif
event
.
note?
elsif
event
.
note?
if
event
.
note_target
if
event
.
note_target
if
event
.
commit_note?
event_note_target_path
(
event
)
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
end
end
elsif
event
.
push?
elsif
event
.
push?
push_event_feed_url
(
event
)
push_event_feed_url
(
event
)
...
@@ -135,42 +122,29 @@ module EventsHelper
...
@@ -135,42 +122,29 @@ module EventsHelper
def
event_note_target_path
(
event
)
def
event_note_target_path
(
event
)
if
event
.
note?
&&
event
.
commit_note?
if
event
.
note?
&&
event
.
commit_note?
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
project
,
namespace_project_commit_path
(
event
.
project
.
namespace
,
event
.
note_target
)
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
else
polymorphic_path
([
event
.
project
.
namespace
.
becomes
(
Namespace
),
polymorphic_path
([
event
.
project
.
namespace
.
becomes
(
Namespace
),
event
.
project
,
event
.
note_target
],
event
.
project
,
event
.
note_target
],
anchor:
dom_id
(
event
.
target
))
anchor:
dom_id
(
event
.
target
))
end
end
end
end
def
event_note_title_html
(
event
)
def
event_note_title_html
(
event
)
if
event
.
note_target
if
event
.
note_target
if
event
.
commit_note?
link_to
(
event_note_target_path
(
event
),
title:
event
.
target_title
,
class:
'has-tooltip'
)
do
link_to
(
"
#{
event
.
note_target_type
}
#{
event
.
note_target_reference
}
"
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
end
end
else
else
content_tag
:strong
do
content_tag
(
:strong
,
'(deleted)'
)
"(deleted)"
end
end
end
end
end
...
...
app/models/event.rb
View file @
020e6168
...
@@ -266,18 +266,10 @@ class Event < ActiveRecord::Base
...
@@ -266,18 +266,10 @@ class Event < ActiveRecord::Base
branch?
&&
project
.
default_branch
!=
branch_name
branch?
&&
project
.
default_branch
!=
branch_name
end
end
def
note_commit_id
target
.
commit_id
end
def
target_iid
def
target_iid
target
.
respond_to?
(
:iid
)
?
target
.
iid
:
target_id
target
.
respond_to?
(
:iid
)
?
target
.
iid
:
target_id
end
end
def
note_short_commit_id
Commit
.
truncate_sha
(
note_commit_id
)
end
def
commit_note?
def
commit_note?
target
.
for_commit?
target
.
for_commit?
end
end
...
@@ -302,12 +294,15 @@ class Event < ActiveRecord::Base
...
@@ -302,12 +294,15 @@ class Event < ActiveRecord::Base
end
end
end
end
def
note_target_iid
def
note_target_reference
if
note_target
.
respond_to?
(
:iid
)
return
unless
note_target
note_target
.
iid
# Commit#to_reference returns the full SHA, but we want the short one here
if
commit_note?
note_target
.
short_id
else
else
note_target
_id
note_target
.
to_reference
end
.
to_s
end
end
end
def
note_target_type
def
note_target_type
...
...
app/models/project.rb
View file @
020e6168
...
@@ -50,6 +50,8 @@ class Project < ActiveRecord::Base
...
@@ -50,6 +50,8 @@ class Project < ActiveRecord::Base
attr_accessor
:new_default_branch
attr_accessor
:new_default_branch
attr_accessor
:old_path_with_namespace
attr_accessor
:old_path_with_namespace
alias_attribute
:title
,
:name
# Relations
# Relations
belongs_to
:creator
,
foreign_key:
'creator_id'
,
class_name:
'User'
belongs_to
:creator
,
foreign_key:
'creator_id'
,
class_name:
'User'
belongs_to
:group
,
->
{
where
(
type:
Group
)
},
foreign_key:
'namespace_id'
belongs_to
:group
,
->
{
where
(
type:
Group
)
},
foreign_key:
'namespace_id'
...
...
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