summaryrefslogtreecommitdiff
path: root/qa/qa/support/formatters/allure_metadata_formatter.rb
blob: 10769ba5c575acb4dafb9d91668fd2c57896b8b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module QA
  module Support
    module Formatters
      class AllureMetadataFormatter < ::RSpec::Core::Formatters::BaseFormatter
        ::RSpec::Core::Formatters.register(
          self,
          :example_started
        )

        # Starts example
        # @param [RSpec::Core::Notifications::ExampleNotification] example_notification
        # @return [void]
        def example_started(example_notification)
          example = example_notification.example

          quarantine_issue = example.metadata.dig(:quarantine, :issue)
          example.issue('Quarantine issue', quarantine_issue) if quarantine_issue

          spec_file = example.file_path.split('/').last
          example.issue(
            'Failure issues',
            "https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=#{spec_file}"
          )
          return unless Runtime::Env.running_in_ci?

          example.add_link(name: "Job(#{Runtime::Env.ci_job_name})", url: Runtime::Env.ci_job_url)
        end
      end
    end
  end
end