Class: Vx::ServiceConnector::Bitbucket::Commits

Inherits:
Struct
  • Object
show all
Defined in:
lib/vx/service_connector/bitbucket/commits.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#repoObject

Returns the value of attribute repo

Returns:

  • (Object)

    the current value of repo



4
5
6
# File 'lib/vx/service_connector/bitbucket/commits.rb', line 4

def repo
  @repo
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



4
5
6
# File 'lib/vx/service_connector/bitbucket/commits.rb', line 4

def session
  @session
end

Instance Method Details

#last(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vx/service_connector/bitbucket/commits.rb', line 5

def last(options = {})
  begin
    commits = session.get "api/1.0/repositories/#{repo.full_name}/changesets/?limit=1"
    commit  = commits["changesets"].first
    author, email = commit["raw_author"].split(/[<>]/)
    sha = commit["raw_node"]
    branch = commit["branch"] || 'master'
    Model::Payload.from_hash(
      skip:          false,
      pull_request?: false,
      branch:        branch,
      branch_label:  branch,
      sha:           sha,
      message:       commit["message"],
      author:        author.strip,
      author_email:  email,
      web_url:       session.endpoint.to_s + "/#{repo.full_name}/commits/#{sha}"
    )
  rescue RequestError
    nil
  end
end