Class: Magnum::Payload::Bitbucket

Inherits:
Base
  • Object
show all
Defined in:
lib/magnum/payload/bitbucket.rb

Constant Summary

Constants inherited from Base

Magnum::Payload::Base::GIT_ZERO_SHA

Constants included from MessageParser

MessageParser::REGEX_SKIP

Instance Attribute Summary

Attributes inherited from Base

#author, #author_email, #branch, #commit, #commit_url, #committer, #committer_email, #compare_url, #data, #message, #raw_data, #skip, #test

Instance Method Summary collapse

Methods inherited from Base

#attributes_hash, #initialize, #skip?

Methods included from MessageParser

#skip_message?

Constructor Details

This class inherits a constructor from Magnum::Payload::Base

Instance Method Details

#make_url(path = nil) ⇒ Object


30
31
32
# File 'lib/magnum/payload/bitbucket.rb', line 30

def make_url(path=nil)
  [site_url, repo_url, path].compact.join
end

#parse!Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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) ⇒ Object


42
43
44
45
46
47
48
49
50
# 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_urlObject


38
39
40
# File 'lib/magnum/payload/bitbucket.rb', line 38

def repo_url
  data.repository.absolute_url
end

#site_urlObject


34
35
36
# File 'lib/magnum/payload/bitbucket.rb', line 34

def site_url
  data.canon_url
end