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
Léo-Paul Géneau
gitlab-ce
Commits
1f5d5590
Commit
1f5d5590
authored
May 24, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge the places where exceptions could be raised
parent
863d8e5a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
6 deletions
+16
-6
app/workers/email_receiver_worker.rb
app/workers/email_receiver_worker.rb
+2
-0
lib/gitlab/email/handler/create_issue_handler.rb
lib/gitlab/email/handler/create_issue_handler.rb
+2
-1
lib/gitlab/email/handler/create_note_handler.rb
lib/gitlab/email/handler/create_note_handler.rb
+2
-1
lib/gitlab/email/receiver.rb
lib/gitlab/email/receiver.rb
+2
-4
spec/lib/gitlab/email/receiver_spec.rb
spec/lib/gitlab/email/receiver_spec.rb
+8
-0
No files found.
app/workers/email_receiver_worker.rb
View file @
1f5d5590
...
@@ -24,6 +24,8 @@ class EmailReceiverWorker
...
@@ -24,6 +24,8 @@ class EmailReceiverWorker
reason
=
nil
reason
=
nil
case
e
case
e
when
Gitlab
::
Email
::
UnknownIncomingEmail
reason
=
"We couldn't figure out what the email is for."
when
Gitlab
::
Email
::
SentNotificationNotFoundError
when
Gitlab
::
Email
::
SentNotificationNotFoundError
reason
=
"We couldn't figure out what the email is in reply to. Please create your comment through the web interface."
reason
=
"We couldn't figure out what the email is in reply to. Please create your comment through the web interface."
when
Gitlab
::
Email
::
ProjectNotFound
when
Gitlab
::
Email
::
ProjectNotFound
...
...
lib/gitlab/email/handler/create_issue_handler.rb
View file @
1f5d5590
...
@@ -14,10 +14,11 @@ module Gitlab
...
@@ -14,10 +14,11 @@ module Gitlab
end
end
def
can_handle?
def
can_handle?
!!
(
project_namespace
&&
project
)
!!
authentication_token
end
end
def
execute
def
execute
raise
ProjectNotFound
unless
project
validate_permission!
(
:create_issue
)
validate_permission!
(
:create_issue
)
verify_record!
(
verify_record!
(
...
...
lib/gitlab/email/handler/create_note_handler.rb
View file @
1f5d5590
...
@@ -6,7 +6,8 @@ module Gitlab
...
@@ -6,7 +6,8 @@ module Gitlab
module
Handler
module
Handler
class
CreateNoteHandler
<
BaseHandler
class
CreateNoteHandler
<
BaseHandler
def
can_handle?
def
can_handle?
!!
(
mail_key
&&
sent_notification
)
# We want to raise SentNotificationNotFoundError for missing key
!!
(
mail_key
.
nil?
||
mail_key
=~
/\A\w+\z/
)
end
end
def
execute
def
execute
...
...
lib/gitlab/email/receiver.rb
View file @
1f5d5590
...
@@ -16,6 +16,7 @@ module Gitlab
...
@@ -16,6 +16,7 @@ module Gitlab
class
NoteableNotFoundError
<
ProcessingError
;
end
class
NoteableNotFoundError
<
ProcessingError
;
end
class
InvalidNoteError
<
ProcessingError
;
end
class
InvalidNoteError
<
ProcessingError
;
end
class
InvalidIssueError
<
ProcessingError
;
end
class
InvalidIssueError
<
ProcessingError
;
end
class
UnknownIncomingEmail
<
ProcessingError
;
end
class
Receiver
class
Receiver
def
initialize
(
raw
)
def
initialize
(
raw
)
...
@@ -30,11 +31,8 @@ module Gitlab
...
@@ -30,11 +31,8 @@ module Gitlab
if
handler
=
Handler
.
for
(
mail
,
mail_key
)
if
handler
=
Handler
.
for
(
mail
,
mail_key
)
handler
.
execute
handler
.
execute
elsif
mail_key
=~
%r{/|
\+
}
# Sent Notification mail_key would not have / or +
raise
ProjectNotFound
else
else
raise
SentNotificationNotFoundError
raise
UnknownIncomingEmail
end
end
end
end
...
...
spec/lib/gitlab/email/receiver_spec.rb
View file @
1f5d5590
...
@@ -30,6 +30,14 @@ describe Gitlab::Email::Receiver, lib: true do
...
@@ -30,6 +30,14 @@ describe Gitlab::Email::Receiver, lib: true do
)
)
end
end
context
"when we cannot find a capable handler"
do
let
(
:email_raw
)
{
fixture_file
(
'emails/valid_reply.eml'
).
gsub
(
mail_key
,
"!!!"
)
}
it
"raises a UnknownIncomingEmail"
do
expect
{
receiver
.
execute
}.
to
raise_error
(
Gitlab
::
Email
::
UnknownIncomingEmail
)
end
end
context
"when the recipient address doesn't include a mail key"
do
context
"when the recipient address doesn't include a mail key"
do
let
(
:email_raw
)
{
fixture_file
(
'emails/valid_reply.eml'
).
gsub
(
mail_key
,
""
)
}
let
(
:email_raw
)
{
fixture_file
(
'emails/valid_reply.eml'
).
gsub
(
mail_key
,
""
)
}
...
...
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