class Flowdock::Git::Builder

Class used to build Git payload

Public Class Methods

new(opts) click to toggle source
# 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

Public Instance Methods

commits() click to toggle source
# File lib/flowdock/git/builder.rb, line 89
def commits
  @repo.commits_between(@before, @after).map do |commit|
    {
      url: if @opts[:commit_url] then @opts[:commit_url] % [commit.sha] end,
      id: commit.sha,
      message: commit.message,
      author: {
        name: commit.author.name,
        email: commit.author.email
      }
    }
  end
end
ref_name() click to toggle source
# File lib/flowdock/git/builder.rb, line 103
def ref_name
  @ref.to_s.sub(/\Arefs\/(heads|tags)\//, '')
end
to_hashes() click to toggle source
# 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

Private Instance Methods

external_thread_id() click to toggle source
# File lib/flowdock/git/builder.rb, line 140
def external_thread_id
  @external_thread_id ||=
    if permanent?
      SecureRandom.hex
    else
      @ref
    end
end
permanent?() click to toggle source
# File lib/flowdock/git/builder.rb, line 122
def permanent?
  @permanent ||= @opts[:permanent_refs].select do |regex|
    regex.match(@ref)
  end.size > 0
end
thread() click to toggle source
# File lib/flowdock/git/builder.rb, line 115
def thread
  @thread ||= {
    title: thread_title,
    external_url: @opts[:repo_url]
  }
end
thread_title() click to toggle source
# File lib/flowdock/git/builder.rb, line 128
def thread_title
  action = if permanent?
             "updated"
           end
  type = if @ref.match(%r(^refs/heads/))
           "branch"
         else
           "tag"
         end
  [@opts[:repo_name], type, ref_name, action].compact.join(" ")
end