andreausu / git-notifier

Get email notifications when someone stars or forks one of your GitHub repos and follows/unfollows you
MIT License
200 stars 16 forks source link

Improve the plaintext notification email by adding newlines. #12

Closed bamos closed 8 years ago

bamos commented 8 years ago

Hi @andreausu,

Sometimes I use a plaintext-only email client and the plaintext notifications look like:

Hello bamos :)
You have 2 new notifications!<br />Your last notification was received on Monday Dec 28 at  7:32.

userX starred repo1userY forked repo2 to userY/repo2

View your full notifications history: https://gitnotifier.io/?utm_source=notifications&utm_medium=email&utm_campaign=timeline&utm_content=daily

This pull request partially fixes the template for plaintext notifications by adding newlines.

I'm testing with the following script:

#!/usr/bin/env ruby

require 'erb'

notifications_text = "You have 2 new notifications!<br />Your last notification was received on Monday Dec 28 at  7:32."
events = [
  {'day' => '2015-12-28', 'text' => 'userX starred repo1'},
  {'text' => 'userY forked repo2 to userY/repo2'},
  {'day' => '2015-12-28', 'text' => 'userX starred repo1'}
]

site_url = "<site url>"
unsubscribe_url = "<unsubscribe url>"

notificationBody = ERB.new(File.read('notification.txt'))

print(notificationBody.result())

Original Output

Hello dear user :)
You have 2 new notifications!<br />Your last notification was received on Monday Dec 2
8 at  7:32.

2015-12-28userX starred repo1userY forked repo2 to userY/repo22015-12-28userX starred
repo1

View your full notifications history: <site url>

Unsubscribe: <unsubscribe url>

Improved Output

Hello dear user :)
You have 2 new notifications!<br />Your last notification was received on Monday Dec 28 at  7:32.

+ [2015-12-28] userX starred repo1
+ userY forked repo2 to userY/repo2
+ [2015-12-28] userX starred repo1

View your full notifications history: <site url>

Unsubscribe: <unsubscribe url>
bamos commented 8 years ago

Also, can you help remove the <br /> from notifications_text from line 75 of email_builder.rb in the plaintext version?

From looking at line 58 of email_builder.rb, maybe by running .gsub(/<br\s?\/?>/, "\r\n").gsub(/<\/?[^>]*>/, '') on everything in locals in send_email.rb before calling into the plaintext template?

andreausu commented 8 years ago

Thank you, that's much better :D

I've fixed the html problem with https://github.com/andreausu/git-notifier/commit/2989324abfa417caab41c4d171aa395f61cf71f3 :)

bamos commented 8 years ago

Awesome, thanks! :-)