class Flowdock::Git::Commit
Public Class Methods
new(external_thread_id, thread, tags, commit)
click to toggle source
# File lib/flowdock/git/builder.rb, line 8 def initialize(external_thread_id, thread, tags, commit) @commit = commit @external_thread_id = external_thread_id @thread = thread @tags = tags end
Public Instance Methods
to_hash()
click to toggle source
# File lib/flowdock/git/builder.rb, line 15 def to_hash hash = { external_thread_id: @external_thread_id, event: "activity", author: { name: @commit[:author][:name], email: @commit[:author][:email] }, title: title, thread: @thread, body: body } hash[:tags] = @tags if @tags encode(hash) end
Private Instance Methods
body()
click to toggle source
# File lib/flowdock/git/builder.rb, line 55 def body content = @commit[:message][first_line.size..-1] content.strip! if content "<pre>#{content}</pre>" unless content.empty? end
encode(hash)
click to toggle source
# File lib/flowdock/git/builder.rb, line 33 def encode(hash) return hash unless "".respond_to? :encode encode_as_utf8(hash) end
encode_as_utf8(obj)
click to toggle source
This only works on Ruby 1.9
# File lib/flowdock/git/builder.rb, line 39 def encode_as_utf8(obj) if obj.is_a? Hash obj.each_pair do |key, val| encode_as_utf8(val) end elsif obj.is_a?(Array) obj.each do |val| encode_as_utf8(val) end elsif obj.is_a?(String) && obj.encoding != Encoding::UTF_8 if !obj.force_encoding("UTF-8").valid_encoding? obj.force_encoding("ISO-8859-1").encode!(Encoding::UTF_8, :invalid => :replace, :undef => :replace) end end end
first_line()
click to toggle source
# File lib/flowdock/git/builder.rb, line 61 def first_line @first_line ||= (@commit[:message].split("\n")[0] || @commit[:message]) end
message_title()
click to toggle source
# File lib/flowdock/git/builder.rb, line 74 def message_title CGI.escape_html(first_line.strip) end
title()
click to toggle source
# File lib/flowdock/git/builder.rb, line 65 def title commit_id = @commit[:id][0, 7] if @commit[:url] "<a href=\"#{@commit[:url]}\">#{commit_id}</a> #{message_title}" else "#{commit_id} #{message_title}" end end