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
ba08811d
Commit
ba08811d
authored
Dec 02, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move note emoji-award implementation to note model (feature envy)
parent
22d87b74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
24 deletions
+33
-24
app/models/note.rb
app/models/note.rb
+33
-0
app/services/notes/create_service.rb
app/services/notes/create_service.rb
+0
-24
No files found.
app/models/note.rb
View file @
ba08811d
...
...
@@ -72,6 +72,7 @@ class Note < ActiveRecord::Base
serialize
:st_diff
before_create
:set_diff
,
if:
->
(
n
)
{
n
.
line_code
.
present?
}
before_validation
:set_award!
class
<<
self
def
discussions_from_notes
(
notes
)
...
...
@@ -349,4 +350,36 @@ class Note < ActiveRecord::Base
def
editable?
!
system
?
end
# Checks if note is an award added from an issue comment.
#
# If note is an award, this method sets is_award to true,
# and changes note content to award-emoji name.
#
# Awards are only supported for issue comments.
#
# Method is executed as a before_validation callback.
#
def
set_award!
return
unless
issue_comment?
&&
contains_emoji_only?
self
.
is_award
=
true
self
.
note
=
award_emoji_name
end
private
def
issue_comment?
noteable
.
kind_of?
(
Issue
)
end
def
contains_emoji_only?
(
note
=~
/\A:[-_+[:alnum:]]*:\s?\z/
)
?
true
:
false
end
def
award_emoji_name
return
nil
unless
contains_emoji_only?
note
.
match
(
/\A:([-_+[:alnum:]]*):\s?/
)[
1
]
end
end
app/services/notes/create_service.rb
View file @
ba08811d
...
...
@@ -5,11 +5,6 @@ module Notes
note
.
author
=
current_user
note
.
system
=
false
if
award_emoji_note?
note
.
is_award
=
true
note
.
note
=
emoji_name
end
if
note
.
save
notification_service
.
new_note
(
note
)
...
...
@@ -33,24 +28,5 @@ module Notes
note
.
project
.
execute_hooks
(
note_data
,
:note_hooks
)
note
.
project
.
execute_services
(
note_data
,
:note_hooks
)
end
private
def
award_emoji_note?
# We support award-emojis only in issue discussion
issue_comment?
&&
contains_emoji_only?
end
def
contains_emoji_only?
params
[
:note
]
=~
/\A:[-_+[:alnum:]]*:\s?\z/
end
def
issue_comment?
params
[
:noteable_type
]
==
'Issue'
end
def
emoji_name
params
[
:note
].
match
(
/\A:([-_+[:alnum:]]*):\s?/
)[
1
]
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