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
4beba749
Commit
4beba749
authored
Nov 20, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Messagee::RepositoryPush
parent
e2f937ce
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
64 deletions
+68
-64
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+3
-3
lib/gitlab/email/message/repository_push.rb
lib/gitlab/email/message/repository_push.rb
+65
-61
No files found.
app/mailers/emails/projects.rb
View file @
4beba749
...
@@ -65,20 +65,20 @@ module Emails
...
@@ -65,20 +65,20 @@ module Emails
@project
=
repository_push
.
project
@project
=
repository_push
.
project
@current_user
=
@author
=
repository_push
.
author
@current_user
=
@author
=
repository_push
.
author
@reverse_compare
=
repository_push
.
reverse_compare
@compare
=
repository_push
.
compare
@compare
=
repository_push
.
compare
@ref_name
=
repository_push
.
ref_name
@ref_name
=
repository_push
.
ref_name
@ref_type
=
repository_push
.
ref_type
@ref_type
=
repository_push
.
ref_type
@action
=
repository_push
.
action
@action
=
repository_push
.
action
@action_name
=
repository_push
.
action_name
@action_name
=
repository_push
.
action_name
@disable_diffs
=
repository_push
.
disable_diffs
@commits
=
repository_push
.
commits
@commits
=
repository_push
.
commits
@diffs
=
repository_push
.
diffs
@diffs
=
repository_push
.
diffs
@target_url
=
repository_push
.
target_url
@target_url
=
repository_push
.
target_url
@disable_diffs
=
repository_push
.
disable_diffs?
@reverse_compare
=
repository_push
.
reverse_compare?
@disable_footer
=
true
@disable_footer
=
true
mail
(
from:
sender
(
repository_push
.
author_id
,
mail
(
from:
sender
(
repository_push
.
author_id
,
repository_push
.
send_from_committer_email
),
repository_push
.
send_from_committer_email
?
),
reply_to:
repository_push
.
reply_to
,
reply_to:
repository_push
.
reply_to
,
to:
repository_push
.
recipient
,
to:
repository_push
.
recipient
,
subject:
repository_push
.
subject
)
subject:
repository_push
.
subject
)
...
...
lib/gitlab/email/message/repository_push.rb
View file @
4beba749
...
@@ -2,53 +2,57 @@ module Gitlab
...
@@ -2,53 +2,57 @@ module Gitlab
module
Email
module
Email
module
Message
module
Message
class
RepositoryPush
class
RepositoryPush
attr_reader
:compare
,
:reverse_compare
,
:send_from_committer_email
,
:disable_diffs
,
:action
,
:ref
,
:author_id
attr_accessor
:recipient
attr_accessor
:recipient
attr_reader
:author_id
,
:ref
,
:action
def
initialize
(
notify
,
project_id
,
recipient
,
opts
=
{})
def
initialize
(
notify
,
project_id
,
recipient
,
opts
=
{})
raise
ArgumentError
,
'Missing
argument
s: author_id, ref, action'
unless
raise
ArgumentError
,
'Missing
option
s: author_id, ref, action'
unless
opts
[
:author_id
]
&&
opts
[
:ref
]
&&
opts
[
:action
]
opts
[
:author_id
]
&&
opts
[
:ref
]
&&
opts
[
:action
]
@notify
=
notify
@notify
=
notify
@project_id
=
project_id
@project_id
=
project_id
@recipient
=
recipient
@recipient
=
recipient
@opts
=
opts
@author_id
=
opts
[
:author_id
]
@author_id
=
opts
.
delete
(
:author_id
)
@ref
=
opts
[
:ref
]
@ref
=
opts
.
delete
(
:ref
)
@action
=
opts
[
:action
]
@action
=
opts
.
delete
(
:action
)
@compare
=
opts
[
:compare
]
||
nil
@reverse_compare
=
opts
[
:reverse_compare
]
||
false
@send_from_committer_email
=
opts
[
:send_from_committer_email
]
||
false
@disable_diffs
=
opts
[
:disable_diffs
]
||
false
@author
=
author
@project
=
project
@commits
=
commits
@diffs
=
diffs
@ref_name
=
ref_name
@ref_type
=
ref_type
@action_name
=
action_name
end
end
def
project
def
project
Project
.
find
(
@project_id
)
@project
||=
Project
.
find
(
@project_id
)
end
end
def
author
def
author
User
.
find
(
@author_id
)
@author
||=
User
.
find
(
@author_id
)
end
end
def
commits
def
commits
Commit
.
decorate
(
@compare
.
commits
,
@project
)
if
@compare
@commits
||=
(
Commit
.
decorate
(
compare
.
commits
,
project
)
if
compare
)
end
end
def
diffs
def
diffs
@compare
.
diffs
if
@compare
@diffs
||=
(
compare
.
diffs
if
compare
)
end
def
compare
@opts
[
:compare
]
end
def
reverse_compare?
@opts
[
:reverse_compare
]
||
false
end
def
disable_diffs?
@opts
[
:disable_diffs
]
||
false
end
def
send_from_committer_email?
@opts
[
:send_from_committer_email
]
||
false
end
end
def
action_name
def
action_name
@action_name
||=
case
@action
case
@action
when
:create
when
:create
'pushed new'
'pushed new'
...
@@ -59,61 +63,61 @@ module Gitlab
...
@@ -59,61 +63,61 @@ module Gitlab
end
end
end
end
def
subject
subject_text
=
'[Git]'
subject_text
<<
"[
#{
@project
.
path_with_namespace
}
]"
subject_text
<<
"[
#{
@ref_name
}
]"
if
@action
==
:push
subject_text
<<
' '
if
@action
==
:push
if
@commits
.
length
>
1
subject_text
<<
"Deleted "
if
@reverse_compare
subject_text
<<
"
#{
@commits
.
length
}
commits:
#{
@commits
.
first
.
title
}
"
else
subject_text
<<
"Deleted 1 commit: "
if
@reverse_compare
subject_text
<<
@commits
.
first
.
title
end
else
subject_action
=
@action_name
.
dup
subject_action
[
0
]
=
subject_action
[
0
].
capitalize
subject_text
<<
"
#{
subject_action
}
#{
@ref_type
}
#{
@ref_name
}
"
end
end
def
ref_name
def
ref_name
Gitlab
::
Git
.
ref_name
(
@ref
)
@ref_name
||=
Gitlab
::
Git
.
ref_name
(
@ref
)
end
end
def
ref_type
def
ref_type
Gitlab
::
Git
.
tag_ref?
(
@ref
)
?
'tag'
:
'branch'
@ref_type
||=
Gitlab
::
Git
.
tag_ref?
(
@ref
)
?
'tag'
:
'branch'
end
end
def
target_url
def
target_url
if
@action
==
:push
if
@action
==
:push
if
@commits
.
length
>
1
if
commits
.
length
>
1
&&
compare
@notify
.
namespace_project_compare_url
(
@
project
.
namespace
,
@notify
.
namespace_project_compare_url
(
project
.
namespace
,
@
project
,
project
,
from:
Commit
.
new
(
@compare
.
base
,
@
project
),
from:
Commit
.
new
(
compare
.
base
,
project
),
to:
Commit
.
new
(
@compare
.
head
,
@
project
))
to:
Commit
.
new
(
compare
.
head
,
project
))
else
else
@notify
.
namespace_project_commit_url
(
@
project
.
namespace
,
@notify
.
namespace_project_commit_url
(
project
.
namespace
,
@project
,
@
commits
.
first
)
project
,
commits
.
first
)
end
end
else
else
unless
@action
==
:delete
unless
@action
==
:delete
@notify
.
namespace_project_tree_url
(
@
project
.
namespace
,
@notify
.
namespace_project_tree_url
(
project
.
namespace
,
@project
,
@
ref_name
)
project
,
ref_name
)
end
end
end
end
end
end
def
reply_to
def
reply_to
if
@send_from_committer_email
&&
@notify
.
can_send_from_user_email?
(
@
author
)
if
send_from_committer_email?
&&
@notify
.
can_send_from_user_email?
(
author
)
@
author
.
email
author
.
email
else
else
Gitlab
.
config
.
gitlab
.
email_reply_to
Gitlab
.
config
.
gitlab
.
email_reply_to
end
end
end
end
def
subject
subject_text
=
'[Git]'
subject_text
<<
"[
#{
project
.
path_with_namespace
}
]"
subject_text
<<
"[
#{
ref_name
}
]"
if
@action
==
:push
subject_text
<<
' '
if
@action
==
:push
if
commits
.
length
>
1
subject_text
<<
"Deleted "
if
reverse_compare?
subject_text
<<
"
#{
commits
.
length
}
commits:
#{
commits
.
first
.
title
}
"
else
subject_text
<<
"Deleted 1 commit: "
if
reverse_compare?
subject_text
<<
commits
.
first
.
title
end
else
subject_action
=
action_name
.
dup
subject_action
[
0
]
=
subject_action
[
0
].
capitalize
subject_text
<<
"
#{
subject_action
}
#{
ref_type
}
#{
ref_name
}
"
end
end
end
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