Class: Codestatus::Repositories::BitbucketRepository

Inherits:
Base
  • Object
show all
Defined in:
lib/codestatus/repositories/bitbucket_repository.rb

Constant Summary collapse

BITBUCKET_API_ENDPOINT =

repositories/atlassian/aui

'https://api.bitbucket.org/2.0/'

Instance Attribute Summary

Attributes inherited from Base

#slug

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Codestatus::Repositories::Base

Instance Method Details

#html_urlObject



29
30
31
# File 'lib/codestatus/repositories/bitbucket_repository.rb', line 29

def html_url
  repository.dig('links', 'html', 'href')
end

#status(ref = main_branch) ⇒ Object

This combined status is generated by the rule of GitHub’s

https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/codestatus/repositories/bitbucket_repository.rb', line 9

def status(ref = main_branch)
  statuses = statuses(ref)

  sha = statuses['values'].map {|x| x.dig('commit', 'hash') }.compact.first
  states = statuses['values'].map { |status| status['state'] }

  state = if states.any? { |x| ['STOPPED', 'FAILED'].include?(x) }
            BuildStatus::FAILURE
          elsif states.empty? || states.all? { |x| x == 'INPROGRESS' }
            BuildStatus::PENDING
          elsif states.all? { |x| x == 'SUCCESSFUL' }
            BuildStatus::SUCCESS
          else
            BuildStatus::UNDEFINED
          end

  BuildStatus.new(sha: sha, status: state)
end