Class: CaptainHook::PostReceiveEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/captain_hook/post_receive_event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PostReceiveEvent

Returns a new instance of PostReceiveEvent.



5
6
7
8
9
10
# File 'lib/captain_hook/post_receive_event.rb', line 5

def initialize(options = {})
  @repo       = options[:repo]
  @old_commit = @repo.commit(options[:old_sha])
  @new_commit = @repo.commit(options[:new_sha])
  @full_ref_name   = options[:ref_name]
end

Instance Attribute Details

#new_commitObject

Returns the value of attribute new_commit.



3
4
5
# File 'lib/captain_hook/post_receive_event.rb', line 3

def new_commit
  @new_commit
end

#old_commitObject

Returns the value of attribute old_commit.



3
4
5
# File 'lib/captain_hook/post_receive_event.rb', line 3

def old_commit
  @old_commit
end

#repoObject

Returns the value of attribute repo.



3
4
5
# File 'lib/captain_hook/post_receive_event.rb', line 3

def repo
  @repo
end

Instance Method Details

#authorObject

Returns the author of the most-recent revision



24
25
26
# File 'lib/captain_hook/post_receive_event.rb', line 24

def author
  new_commit.author
end

#commitsObject



12
13
14
# File 'lib/captain_hook/post_receive_event.rb', line 12

def commits
  @commits ||= @repo.commits_between(new_commit, old_commit)
end

#messageObject

Returns the first line of the most recent revision’s commit message



29
30
31
# File 'lib/captain_hook/post_receive_event.rb', line 29

def message
  @message ||= new_commit.message.split("\n")[0]
end

#message_detailObject

Returns lines 1..n of the most recent revision’s commit message



34
35
36
37
38
39
40
41
# File 'lib/captain_hook/post_receive_event.rb', line 34

def message_detail
  @message_detail ||= begin
    new_commit.message.
      split("\n")[1..-1].
      reject{|s| s == ""}.
      join("\n")
    end
end

#ref_nameObject



16
17
18
19
20
21
# File 'lib/captain_hook/post_receive_event.rb', line 16

def ref_name
  @ref_name ||= begin
    @full_ref_name =~ %r{^refs/(?:tags|heads|remotes)/(.+)} ?
      $1 : "unknown"
  end
end