Class: Github::Commit::Mailer::GithubCommitMailer
- Inherits:
-
Object
- Object
- Github::Commit::Mailer::GithubCommitMailer
- Defined in:
- lib/github-commit-mailer.rb
Instance Method Summary collapse
-
#initialize(repo_dir, yml_cfg, last_commit_file) ⇒ GithubCommitMailer
constructor
A new instance of GithubCommitMailer.
- #run ⇒ Object
Constructor Details
#initialize(repo_dir, yml_cfg, last_commit_file) ⇒ GithubCommitMailer
Returns a new instance of GithubCommitMailer.
10 11 12 13 14 15 16 |
# File 'lib/github-commit-mailer.rb', line 10 def initialize(repo_dir, yml_cfg, last_commit_file) @repo_dir = repo_dir @yml_cfg = yml_cfg @last_commit_file = last_commit_file validate end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/github-commit-mailer.rb', line 18 def run last_rev = get_last_emailed_commit git_pull revs = get_new_commits(last_rev) if revs.length < 2 then puts "No new commits. Exiting." return end puts "Emailing the following commits:" revs.each { |r| puts "commit: '#{r}'" } rev_from = revs[revs.length - 1] rev_to = revs[0] cmd = "cd #{@repo_dir} && echo '#{rev_from} #{rev_to} refs/heads/master'|git-commit-notifier #{@yml_cfg}; cd -" puts "#{cmd}" raise "Error executing git-commit-notifier" if !system(cmd) puts "Saving '#{rev_to}' to '#{@last_commit_file}' ..." File.open(@last_commit_file, 'w') do |f| f.puts "#{rev_to}" end end |