Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improving email format.

This includes a second line for testing.
  • Loading branch information...
commit d73a9e628b92c31390023d51ffa83b07500efff8 1 parent 564315c
@eric eric authored
Showing with 31 additions and 4 deletions.
  1. +1 −0  .gitignore
  2. +30 −4 services/email.rb
View
1  .gitignore
@@ -1,2 +1,3 @@
.DS_Store
deploy.rb
+*~
View
34 services/email.rb
@@ -1,6 +1,17 @@
service :email do |data, payload|
name_with_owner = File.join(payload['repository']['owner']['name'], payload['repository']['name'])
+
+ # Should be: first_commit = payload['commits'].first
+ first_commit_sha, first_commit = payload['commits'].select { |c| c }
+
+ # Shorten the elements of the subject
+ first_commit_sha = first_commit_sha[0..5]
+
+ first_commit_title = first_commit['message'][/^([^\n]+)/, 1]
+ if first_commit_title.length > 50
+ first_commit_title = first_commit_title.slice(0,50) << '...'
+ end
body = <<-EOH
Commits to #{name_with_owner}
@@ -10,20 +21,35 @@
EOH
+
payload['commits'].each do |gitsha, commit|
+ added = commit['added'].map { |f| ['A', f] }
+ removed = commit['removed'].map { |f| ['R', f] }
+ modified = commit['modified'].map { |f| ['M', f] }
+
+ changed_paths = (added + removed + modified).sort_by { |(char, file)| file }
+ changed_paths = changed_paths.collect { |entry| entry * ' ' }.join("\n ")
+
+ timestamp = Date.parse(commit['timestamp'])
+
body << <<-EOH
-#{commit['timestamp']} - #{commit['author']['name']} (#{commit['author']['email']})
-#{commit['url']}
+Commit: #{gitsha}
+Author: #{commit['author']['name']} <#{commit['author']['email']}>
+Date: #{timestamp} (#{timestamp.strftime('%a, %d %b %Y')})
+Url: #{commit['url']}
+
+Changed paths:
+ #{changed_paths}
#{commit['message']}
EOH
end
-
+
message = TMail::Mail.new
message.set_content_type('text', 'plain')
- message.subject = "[GitHub] Push: #{name_with_owner} - #{payload['ref'].split('/').last}"
+ message.subject = "[#{name_with_owner}] #{first_commit_sha}: #{first_commit_title}"
message.body = body
message.date = Time.now
Please sign in to comment.
Something went wrong with that request. Please try again.