Class: Inq::Sources::CI::Travis

Inherits:
Object
  • Object
show all
Defined in:
lib/inq/sources/ci/travis.rb

Overview

Fetches metadata about CI builds from travis-ci.org.

Constant Summary collapse

BadResponseError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(config, start_date, end_date, cache) ⇒ Travis

Returns a new instance of Travis.

Parameters:

  • repository (String)

    GitHub repository name, of the format user/repo.

  • start_date (String)

    Start date for the report being generated.

  • end_date (String)

    End date for the report being generated.

  • cache (Cacheable)

    Instance of Inq::Cacheable to cache API calls



21
22
23
24
25
26
27
28
29
# File 'lib/inq/sources/ci/travis.rb', line 21

def initialize(config, start_date, end_date, cache)
  @config = config
  @cache = cache
  @repository = config["repository"]
  raise "Travis.new() got nil repository." if @repository.nil?
  @start_date = DateTime.parse(start_date)
  @end_date = DateTime.parse(end_date)
  @default_branch = Okay.default
end

Instance Method Details

#buildsHash

Returns the builds for the default branch.

Returns:

  • (Hash)

    Hash containing the builds for the default branch.



48
49
50
51
52
53
54
55
# File 'lib/inq/sources/ci/travis.rb', line 48

def builds
  @cache.cached("travis_builds") do
    raw_builds \
      .map(&method(:normalize_build)) \
      .select(&method(:in_date_range?)) \
      .map(&method(:add_build_urls))
  end
end

#default_branchString

Returns The default branch name.

Returns:

  • (String)

    The default branch name.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/inq/sources/ci/travis.rb', line 32

def default_branch
  return @default_branch unless @default_branch == Okay.default

  response = fetch("branches", {"sort_by" => "default_branch"})
  validate_response!(response)

  branches = response["branches"]
  validate_branches!(branches)

  branch = branches.find { |b| b["default_branch"] == true }
  @default_branch = branch&.fetch("name", nil)
end