Class: CaptainHook::Events::PostReceive

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PostReceive

Returns a new instance of PostReceive.



6
7
8
9
10
11
# File 'lib/captain_hook/events/post_receive.rb', line 6

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.



4
5
6
# File 'lib/captain_hook/events/post_receive.rb', line 4

def new_commit
  @new_commit
end

#old_commitObject

Returns the value of attribute old_commit.



4
5
6
# File 'lib/captain_hook/events/post_receive.rb', line 4

def old_commit
  @old_commit
end

#repoObject

Returns the value of attribute repo.



4
5
6
# File 'lib/captain_hook/events/post_receive.rb', line 4

def repo
  @repo
end

Instance Method Details

#authorObject

Returns the author of the most-recent revision



25
26
27
# File 'lib/captain_hook/events/post_receive.rb', line 25

def author
  new_commit.author
end

#commitsObject



13
14
15
# File 'lib/captain_hook/events/post_receive.rb', line 13

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

#messageObject

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



30
31
32
# File 'lib/captain_hook/events/post_receive.rb', line 30

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

#message_detailObject

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



35
36
37
38
39
40
41
42
# File 'lib/captain_hook/events/post_receive.rb', line 35

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

#ref_nameObject



17
18
19
20
21
22
# File 'lib/captain_hook/events/post_receive.rb', line 17

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