BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
75415663
Commit
75415663
authored
May 21, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename handlers and introduce Handler.for
parent
ee548b6e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
64 deletions
+74
-64
handler.rb
lib/gitlab/email/handler.rb
+9
-48
base_handler.rb
lib/gitlab/email/handler/base_handler.rb
+57
-0
create_issue_handler.rb
lib/gitlab/email/handler/create_issue_handler.rb
+3
-3
create_note_handler.rb
lib/gitlab/email/handler/create_note_handler.rb
+3
-3
receiver.rb
lib/gitlab/email/receiver.rb
+2
-10
No files found.
lib/gitlab/email/handler.rb
View file @
75415663
require
'gitlab/email/handler/create_note_handler'
require
'gitlab/email/handler/create_issue_handler'
module
Gitlab
module
Email
class
Handler
attr_reader
:mail
,
:mail_key
def
initialize
(
mail
,
mail_key
)
@mail
=
mail
@mail_key
=
mail_key
end
def
message
@message
||=
process_message
end
def
author
raise
NotImplementedError
end
def
project
raise
NotImplementedError
end
private
def
validate_permission!
(
permission
)
raise
UserNotFoundError
unless
author
raise
UserBlockedError
if
author
.
blocked?
raise
ProjectNotFound
unless
author
.
can?
(
:read_project
,
project
)
raise
UserNotAuthorizedError
unless
author
.
can?
(
permission
,
project
)
end
def
process_message
add_attachments
(
ReplyParser
.
new
(
mail
).
execute
.
strip
)
end
def
add_attachments
(
reply
)
attachments
=
Email
::
AttachmentUploader
.
new
(
mail
).
execute
(
project
)
reply
+
attachments
.
map
do
|
link
|
"
\n\n
#{
link
[
:markdown
]
}
"
end
.
join
end
def
verify_record
(
record
,
exception
,
error_title
)
return
if
record
.
persisted?
msg
=
error_title
+
record
.
errors
.
full_messages
.
map
do
|
error
|
"
\n\n
-
#{
error
}
"
end
.
join
raise
exception
,
msg
module
Handler
def
self
.
for
(
mail
,
mail_key
)
[
CreateNoteHandler
,
CreateIssueHandler
].
find
do
|
klass
|
handler
=
klass
.
new
(
mail
,
mail_key
)
break
handler
if
handler
.
can_handle?
end
end
end
end
...
...
lib/gitlab/email/handler/base_handler.rb
0 → 100644
View file @
75415663
module
Gitlab
module
Email
module
Handler
class
BaseHandler
attr_reader
:mail
,
:mail_key
def
initialize
(
mail
,
mail_key
)
@mail
=
mail
@mail_key
=
mail_key
end
def
message
@message
||=
process_message
end
def
author
raise
NotImplementedError
end
def
project
raise
NotImplementedError
end
private
def
validate_permission!
(
permission
)
raise
UserNotFoundError
unless
author
raise
UserBlockedError
if
author
.
blocked?
raise
ProjectNotFound
unless
author
.
can?
(
:read_project
,
project
)
raise
UserNotAuthorizedError
unless
author
.
can?
(
permission
,
project
)
end
def
process_message
add_attachments
(
ReplyParser
.
new
(
mail
).
execute
.
strip
)
end
def
add_attachments
(
reply
)
attachments
=
Email
::
AttachmentUploader
.
new
(
mail
).
execute
(
project
)
reply
+
attachments
.
map
do
|
link
|
"
\n\n
#{
link
[
:markdown
]
}
"
end
.
join
end
def
verify_record
(
record
,
exception
,
error_title
)
return
if
record
.
persisted?
msg
=
error_title
+
record
.
errors
.
full_messages
.
map
do
|
error
|
"
\n\n
-
#{
error
}
"
end
.
join
raise
exception
,
msg
end
end
end
end
end
lib/gitlab/email/handler/create_issue.rb
→
lib/gitlab/email/handler/create_issue
_handler
.rb
View file @
75415663
require
'gitlab/email/handler'
require
'gitlab/email/handler
/base_handler
'
module
Gitlab
module
Email
class
Handler
class
CreateIssue
<
Handler
module
Handler
class
CreateIssue
Handler
<
Base
Handler
def
can_handle?
!!
project
end
...
...
lib/gitlab/email/handler/create_note.rb
→
lib/gitlab/email/handler/create_note
_handler
.rb
View file @
75415663
require
'gitlab/email/handler'
require
'gitlab/email/handler
/base_handler
'
module
Gitlab
module
Email
class
Handler
class
CreateNote
<
Handler
module
Handler
class
CreateNote
Handler
<
Base
Handler
def
can_handle?
!!
sent_notification
end
...
...
lib/gitlab/email/receiver.rb
View file @
75415663
require
'gitlab/email/handler/create_note'
require
'gitlab/email/handler/create_issue'
require
'gitlab/email/handler'
# Inspired in great part by Discourse's Email::Receiver
module
Gitlab
...
...
@@ -31,7 +30,7 @@ module Gitlab
raise
SentNotificationNotFoundError
unless
mail_key
if
handler
=
find_handle
r
(
mail
,
mail_key
)
if
handler
=
Handler
.
fo
r
(
mail
,
mail_key
)
handler
.
execute
elsif
mail_key
=~
%r{/|
\+
}
# Sent Notification mail_key would not have / or +
...
...
@@ -65,13 +64,6 @@ module Gitlab
break
key
if
key
end
end
def
find_handler
(
mail
,
mail_key
)
[
Handler
::
CreateNote
,
Handler
::
CreateIssue
].
find
do
|
klass
|
handler
=
klass
.
new
(
mail
,
mail_key
)
break
handler
if
handler
.
can_handle?
end
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