Welcome to mirror list, hosted at ThFree Co, Russian Federation.

job.rb « api « tooling « lib « tooling - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1660f349833f688e9d6d5add405f80cd79d63f2f (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
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'pathname'

module Tooling
  module API
    class Job
      RSPEC_FILENAME_REGEX = /rspec '?([^\s:\[']+)[:\[]/

      def initialize(api_token, project_id, job_id)
        @api_token = api_token
        @project_id = project_id
        @job_id = job_id
      end

      def rspec_failed_files
        log = get_job_log
        extract_rspec_filenames(log)
      end

      private

      attr_reader :api_token, :project_id, :job_id

      def extract_rspec_filenames(log)
        log.scan(RSPEC_FILENAME_REGEX).map do |match|
          path = match[0]
          Pathname.new(path).relative_path_from('.').to_s
        end.uniq
      end

      def get_job_log
        uri = URI("https://gitlab.com/api/v4/projects/#{project_id}/jobs/#{job_id}/trace")
        response = Request.get(api_token, uri)

        response.body
      end
    end
  end
end