Class: Flowdock::Git::Builder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/flowdock/git/builder.rb

Overview

Class used to build Git payload

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(opts) ⇒ Builder

Returns a new instance of Builder.


81
82
83
84
85
86
87
# File 'lib/flowdock/git/builder.rb', line 81

def initialize(opts)
  @repo = opts[:repo]
  @ref = opts[:ref]
  @before = opts[:before]
  @after = opts[:after]
  @opts = opts
end

Instance Method Details

#commitsObject


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/flowdock/git/builder.rb', line 89

def commits
  @repo.commits_between(@before, @after).map do |commit|
    {
      url: @opts[:commit_url] ? @opts[:commit_url] % [commit.sha] : nil,
      id: commit.sha,
      message: commit.message,
      author: {
        name: commit.author_name,
        email: commit.author_email
      }
    }
  end
end

#ref_nameObject


103
104
105
# File 'lib/flowdock/git/builder.rb', line 103

def ref_name
  @ref.to_s.sub(%r{\Arefs/(heads|tags)/}, '')
end

#to_hashesObject


107
108
109
110
111
# File 'lib/flowdock/git/builder.rb', line 107

def to_hashes
  commits.map do |commit|
    Commit.new(external_thread_id, thread, @opts[:tags], commit).to_hash
  end
end