Class: TestFileFinder::MappingStrategies::GitlabMergeRequestRspecFailure

Inherits:
Object
  • Object
show all
Defined in:
lib/test_file_finder/mapping_strategies/gitlab_merge_request_rspec_failure.rb

Overview

GitlabMergeRequestRSpecFailure strategy finds test files that failed in a GitLab merge request, using the Unit Test Reports feature docs.gitlab.com/ee/ci/unit_test_reports.html

It uses the project path and merge request iid to fetch the test report of the merge request, which contains the test suites that ran in the CI pipeline.

It returns file names of rspec failures in the pipeline.

Constant Summary collapse

TEST_REPORTS_URL_TEMPLATE =
'https://gitlab.com/%{project_path}/-/merge_requests/%{merge_request_iid}/test_reports.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path:, merge_request_iid:) ⇒ GitlabMergeRequestRspecFailure

Returns a new instance of GitlabMergeRequestRspecFailure.



24
25
26
27
# File 'lib/test_file_finder/mapping_strategies/gitlab_merge_request_rspec_failure.rb', line 24

def initialize(project_path:, merge_request_iid:)
  @project_path = project_path
  @merge_request_iid = merge_request_iid
end

Instance Attribute Details

#merge_request_iidObject (readonly)

Returns the value of attribute merge_request_iid.



22
23
24
# File 'lib/test_file_finder/mapping_strategies/gitlab_merge_request_rspec_failure.rb', line 22

def merge_request_iid
  @merge_request_iid
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



22
23
24
# File 'lib/test_file_finder/mapping_strategies/gitlab_merge_request_rspec_failure.rb', line 22

def project_path
  @project_path
end

Instance Method Details

#match(_files = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/test_file_finder/mapping_strategies/gitlab_merge_request_rspec_failure.rb', line 29

def match(_files = nil)
  test_suites.each_with_object(Set.new) do |suite, result|
    unresolved_failures(suite).each do |failure|
      rspec_file(failure) do |spec|
        result << spec
      end
    end
  end.to_a
end