class Magnum::Payload::Bitbucket

Public Instance Methods

make_url(path=nil) click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 30
def make_url(path=nil)
  [site_url, repo_url, path].compact.join
end
parse!() click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 3
def parse!
  if data.push && data.push.changes
    return parse_new_payload
  end

  if data.commits.nil? || data.commits.empty?
    raise Magnum::Payload::PayloadError, "Payload has no commits"
  end

  commit = Hashr.new(data.commits.last)

  branch   = commit.branch || commit.branches.first || 'none'
  revision = commit.revision || commit.raw_node
  author   = parse_author(commit.raw_author)

  @commit       = revision
  @author       = author.name
  @author_email = author.email
  @message      = commit.message.strip
  @branch       = branch
  @commit_url   = make_url("commits/#{revision}")

  if data.commits.size > 1
    parse_compare_url(revision)
  end
end
parse_author(str) click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 42
def parse_author(str)
  case str
  when /<.+>/
    m, name, email = *str.match(/(.*) <(.+?)>/)
    Hashr.new(:name => name, :email => email)
  else
    Hashr.new(:name => str)
  end
end
repo_url() click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 38
def repo_url
  data.repository.absolute_url
end
site_url() click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 34
def site_url
  data.canon_url
end

Private Instance Methods

parse_compare_url(revision) click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 54
def parse_compare_url(revision)
  first_commit = Hashr.new(data.commits.first)
  rev_start    = first_commit.revision || first_commit.raw_node
  rev_end      = revision
  @compare_url = make_url("compare/#{rev_start}..#{rev_end}")
end
parse_new_payload() click to toggle source
# File lib/magnum/payload/bitbucket.rb, line 61
def parse_new_payload
  changes = Hashr.new(data.push.changes[0])
  commit  = changes[:new]
  author  = parse_author(commit.target.author.raw)

  @branch       = commit.name
  @commit       = commit.target[:hash]
  @message      = commit.target[:message].to_s.strip
  @author       = author.name
  @author_email = author.email
  @commit_url   = commit.target.links.html.href

  if changes.links.html
    @compare_url = changes.links.html.href
  end
end