class GitNotifiedOnTrello::Notifier
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/git_notified_on_trello.rb, line 14 def initialize(attrs = {}) @client = Trello::Client.new( :developer_public_key => attrs[:developer_public_key], :member_token => attrs[:member_token] ) @debug = attrs[:debug] == nil ? false : attrs[:debug] end
Public Instance Methods
notify(branch, commit, author, message)
click to toggle source
# File lib/git_notified_on_trello.rb, line 22 def notify(branch, commit, author, message) matches = message.match(/^.*?trello\.com\/\w\/([\w]+?)\b.*?$/) if ( matches && matches.size > 0 ) cardId = matches[1] card = @client.find(:card, cardId) cardMessage = (' '+message+' ').gsub(/https?[:\/\W]*?.trello.com[^ ]*/, "") cardMessage = "> " + cardMessage.gsub(/[\r\n]|([\\]n)/, " > ") print "Trello card \"#{card.name}\" was found with card id #{cardId}\n" comment = "\n" comment+= "** #{author} pushed a change to #{branch} **\n" comment+= "\n\n" comment+= "#{cardMessage}\n" comment+= "\n\n" comment+= "View this change on Github: [#{commit}](https://github.com/Extrabux/Extrabux-Complete/commit/#{commit})\n" if(@debug) print comment end card.add_comment(comment) else if(@debug) print "No Trello card was found in message \"#{message}\"\n" end end end