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
Tatuya Kamada
gitlab-ce
Commits
8c6db54e
Commit
8c6db54e
authored
Nov 17, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract repository_push_email to separate class
parent
79fb993a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
77 deletions
+135
-77
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+19
-77
lib/gitlab/email/repository_push.rb
lib/gitlab/email/repository_push.rb
+116
-0
No files found.
app/mailers/emails/projects.rb
View file @
8c6db54e
...
...
@@ -59,85 +59,27 @@ module Emails
subject:
subject
(
"Project was moved"
))
end
def
repository_push_email
(
project_id
,
recipient
,
author_id:
nil
,
ref:
nil
,
action:
nil
,
compare:
nil
,
reverse_compare:
false
,
send_from_committer_email:
false
,
disable_diffs:
false
)
unless
author_id
&&
ref
&&
action
raise
ArgumentError
,
"missing keywords: author_id, ref, action"
end
@project
=
Project
.
find
(
project_id
)
@current_user
=
@author
=
User
.
find
(
author_id
)
@reverse_compare
=
reverse_compare
@compare
=
compare
@ref_name
=
Gitlab
::
Git
.
ref_name
(
ref
)
@ref_type
=
Gitlab
::
Git
.
tag_ref?
(
ref
)
?
"tag"
:
"branch"
@action
=
action
@disable_diffs
=
disable_diffs
if
@compare
@commits
=
Commit
.
decorate
(
compare
.
commits
,
@project
)
@diffs
=
compare
.
diffs
end
@action_name
=
case
action
when
:create
"pushed new"
when
:delete
"deleted"
else
"pushed to"
end
@subject
=
"[Git]"
@subject
<<
"[
#{
@project
.
path_with_namespace
}
]"
@subject
<<
"[
#{
@ref_name
}
]"
if
action
==
:push
@subject
<<
" "
if
action
==
:push
if
@commits
.
length
>
1
@target_url
=
namespace_project_compare_url
(
@project
.
namespace
,
@project
,
from:
Commit
.
new
(
@compare
.
base
,
@project
),
to:
Commit
.
new
(
@compare
.
head
,
@project
))
@subject
<<
"Deleted "
if
@reverse_compare
@subject
<<
"
#{
@commits
.
length
}
commits:
#{
@commits
.
first
.
title
}
"
else
@target_url
=
namespace_project_commit_url
(
@project
.
namespace
,
@project
,
@commits
.
first
)
@subject
<<
"Deleted 1 commit: "
if
@reverse_compare
@subject
<<
@commits
.
first
.
title
end
else
unless
action
==
:delete
@target_url
=
namespace_project_tree_url
(
@project
.
namespace
,
@project
,
@ref_name
)
end
subject_action
=
@action_name
.
dup
subject_action
[
0
]
=
subject_action
[
0
].
capitalize
@subject
<<
"
#{
subject_action
}
#{
@ref_type
}
#{
@ref_name
}
"
end
def
repository_push_email
(
project_id
,
recipient
,
opts
=
{})
email
=
Gitlab
::
Email
::
RepositoryPush
.
new
(
project_id
,
recipient
,
opts
)
@project
=
email
.
project
@current_user
=
@author
=
email
.
author
@reverse_compare
=
email
.
reverse_compare
@compare
=
email
.
compare
@ref_name
=
email
.
ref_name
@ref_type
=
email
.
ref_type
@action
=
email
.
action
@disable_diffs
=
email
.
disable_diffs
@commits
=
email
.
commits
@diffs
=
email
.
diffs
@action_name
=
email
.
action_name
@target_url
=
email
.
target_url
@disable_footer
=
true
reply_to
=
if
send_from_committer_email
&&
can_send_from_user_email?
(
@author
)
@author
.
email
else
Gitlab
.
config
.
gitlab
.
email_reply_to
end
mail
(
from:
sender
(
author_id
,
send_from_committer_email
),
reply_to:
reply_to
,
to:
recipient
,
subject:
@subject
)
mail
(
from:
sender
(
email
.
author_id
,
email
.
send_from_committer_email
),
reply_to:
email
.
reply_to
,
to:
email
.
recipient
,
subject:
email
.
subject
)
end
end
end
lib/gitlab/email/repository_push.rb
0 → 100644
View file @
8c6db54e
module
Gitlab
module
Email
class
RepositoryPush
attr_reader
:compare
,
:reverse_compare
,
:send_from_cmmitter_email
,
:disable_diffs
,
:action
,
:ref
,
:author_id
def
initialize
(
project_id
,
recipient
,
opts
=
{})
raise
ArgumentError
,
'Missing arguments: author_id, ref, action'
unless
opts
[
:author_id
]
&&
opts
[
:ref
]
&&
opts
[
:action
]
@project_id
=
project_id
@recipient
=
recipient
@author_id
=
opts
[
:author_id
]
@ref
=
opts
[
:ref
]
@action
=
opts
[
: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
def
project
Project
.
find
(
@project_id
)
end
def
author
User
.
find
(
@author_id
)
end
def
commits
Commit
.
decorate
(
@compare
.
commits
,
@project
)
if
@compare
end
def
diffs
@compare
.
diffs
if
@compare
end
def
action_name
case
@action
when
:create
'pushed new'
when
:delete
'deleted'
else
'pushed to'
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
end
subject_action
=
@action_name
.
dup
subject_action
[
0
]
=
subject_action
[
0
].
capitalize
subject_text
<<
"
#{
subject_action
}
#{
@ref_type
}
#{
@ref_name
}
"
end
def
ref_name
Gitlab
::
Git
.
ref_name
(
@ref
)
end
def
ref_type
Gitlab
::
Git
.
tag_ref?
(
@ref
)
?
'tag'
:
'branch'
end
def
target_url
if
action
==
:push
if
@commits
.
length
>
1
namespace_project_compare_url
(
@project
.
namespace
,
@project
,
from:
Commit
.
new
(
@compare
.
base
,
@project
),
to:
Commit
.
new
(
@compare
.
head
,
@project
))
else
namespace_project_commit_url
(
@project
.
namespace
,
@project
,
@commits
.
first
)
end
end
if
action
!=
:delete
&&
action
!=
:push
namespace_project_tree_url
(
@project
.
namespace
,
@project
,
@ref_name
)
end
end
def
reply_to
if
@send_from_committer_email
&&
can_send_from_user_email?
(
@author
)
@author
.
email
else
Gitlab
.
config
.
gitlab
.
email_reply_to
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