-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
79 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,23 +24,22 @@ | |
# Job that emails if exception occurs. | ||
# | ||
class JobEmailed | ||
def initialize(name, github, repo, job) | ||
@name = name | ||
@github = github | ||
@repo = repo | ||
def initialize(vcs, job) | ||
@vcs = vcs | ||
@job = job | ||
end | ||
|
||
def proceed | ||
@job.proceed | ||
rescue Exception => e | ||
yaml = @repo.config | ||
yaml = @vcs.repo.config | ||
emails = yaml['errors'] || [] | ||
emails << '[email protected]' | ||
trace = e.message + "\n\n" + e.backtrace.join("\n") | ||
name = @name | ||
repo_owner_login = repo_user_login(name) | ||
name = @vcs.repo.name | ||
repo_owner_login = repo_user_login | ||
repo_owner_email = user_email(repo_owner_login) | ||
repository_link = @vcs.repository_link | ||
emails.each do |email| | ||
mail = Mail.new do | ||
from '0pdd <[email protected]>' | ||
|
@@ -49,7 +48,7 @@ def proceed | |
text_part do | ||
content_type 'text/plain; charset=UTF-8' | ||
body "Hey,\n\n\ | ||
There is a problem in https://github.com/#{name}:\n\n\ | ||
There is a problem in #{repository_link}:\n\n\ | ||
#{trace}\n\n\ | ||
If you think it's our bug, please submit it to GitHub: \ | ||
https://github.com/yegor256/0pdd/issues\n\n\ | ||
|
@@ -60,7 +59,7 @@ def proceed | |
content_type 'text/html; charset=UTF-8' | ||
body "<html><body><p>Hey,</p> | ||
<p>There is a problem in | ||
<a href='https://github.com/#{name}'>#{name}</a>:</p> | ||
<a href='#{repository_link}'>#{name}</a>:</p> | ||
<pre>#{trace}</pre> | ||
<p>If you think it's our bug, please submit it to | ||
<a href='https://github.com/yegor256/0pdd/issues'>GitHub</a>. | ||
|
@@ -77,11 +76,11 @@ def proceed | |
|
||
private | ||
|
||
def repo_user_login(repo_name) | ||
repo_name.split('/').first | ||
def repo_user_login | ||
@vcs.repo.name.split('/').first | ||
end | ||
|
||
def user_email(login) | ||
@github.user(login)[:email] | ||
def user_email(username) | ||
@vcs.user(username)[:email] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,21 +38,21 @@ def fake_job | |
|
||
def test_simple_scenario | ||
repo = FakeRepo.new | ||
github = FakeGithub.new | ||
vcs = FakeGithub.new(repo: repo) | ||
job = fake_job | ||
JobEmailed.new('yegor256/0pdd', github, repo, job).proceed | ||
JobEmailed.new(vcs, job).proceed | ||
end | ||
|
||
def test_exception_mail_to_repo_owner_as_cc | ||
exception_class = Exception | ||
repo = FakeRepo.new | ||
github = FakeGithub.new | ||
vcs = FakeGithub.new(repo: repo) | ||
job = fake_job | ||
job.expects(:proceed).raises(exception_class) | ||
Mail::Message.any_instance.stubs(:deliver!) | ||
Mail::Message.any_instance.expects(:cc=).with('[email protected]') | ||
assert_raise Exception do | ||
JobEmailed.new('yegor256/0pdd', github, repo, job).proceed | ||
JobEmailed.new(vcs, job).proceed | ||
end | ||
end | ||
end |