Class: Jiminy::Reporting::CIProviders::CircleCI::Pipeline

Inherits:
Base
  • Object
show all
Defined in:
lib/jiminy/reporting/ci_providers/circle_ci/pipeline.rb

Constant Summary collapse

MAX_PAGE_LOOKUP =
20

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

define_attribute_readers, fetch_api_resource, #initialize

Constructor Details

This class inherits a constructor from Jiminy::Reporting::CIProviders::CircleCI::Base

Class Method Details

.fetch_page_from_api(page_token) ⇒ Object



26
27
28
29
30
31
# File 'lib/jiminy/reporting/ci_providers/circle_ci/pipeline.rb', line 26

def self.fetch_page_from_api(page_token)
  query = "org-slug=gh/#{Jiminy.config.project_username}&mine=false"
  query += "&page-token=#{page_token}" if page_token
  url = "pipeline?#{query}"
  fetch_api_resource(url)
end

.find_by_revision(git_revision:, pr_number:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/jiminy/reporting/ci_providers/circle_ci/pipeline.rb', line 15

def self.find_by_revision(git_revision:, pr_number:)
  attempt_count = 0
  matching_pipeline = nil
  until matching_pipeline || attempt_count >= MAX_PAGE_LOOKUP
    page_pipelines = fetch_page_from_api(next_token)
    matching_pipeline = page_pipelines.detect { |p| pipeline_match?(p, git_revision, pr_number) }
    attempt_count += 1
  end
  matching_pipeline
end

.pipeline_match?(pipeline, git_revision, _pr_number) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'lib/jiminy/reporting/ci_providers/circle_ci/pipeline.rb', line 33

def self.pipeline_match?(pipeline, git_revision, _pr_number)
  return false unless pipeline.project_slug.to_s.downcase.end_with?(Jiminy.config.repo_path.downcase)

  pipeline.vcs.revision == git_revision

  # TODO: Get PR comparison working too
  # pipeline.vcs.review_url.end_with?("pull/#{pr_number}")
end

Instance Method Details

#vcsObject



42
43
44
# File 'lib/jiminy/reporting/ci_providers/circle_ci/pipeline.rb', line 42

def vcs
  VCS.new(attributes["vcs"])
end