Class: Flaky::Providers::Semaphore

Inherits:
Base
  • Object
show all
Defined in:
lib/flaky/providers/semaphore.rb

Constant Summary collapse

TEST_BLOCKS =
["Unit Tests", "System Tests"].freeze

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Flaky::Providers::Base

Instance Method Details

#fetch_jobs(pipeline_id:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flaky/providers/semaphore.rb', line 17

def fetch_jobs(pipeline_id:)
  output = run_cmd("sem get pipelines #{pipeline_id}")
  data = YAML.safe_load(output, permitted_classes: [Date, Time])
  blocks = data&.[]("blocks")
  return [] unless blocks

  blocks.flat_map do |block|
    block_name = block["name"]
    next [] unless TEST_BLOCKS.include?(block_name)

    (block["jobs"] || []).map do |job|
      {
        id: job["jobid"],
        name: job["name"],
        block_name: block_name,
        result: block["result"]
      }
    end
  end
end

#fetch_log(job_id:) ⇒ Object



38
39
40
# File 'lib/flaky/providers/semaphore.rb', line 38

def fetch_log(job_id:)
  run_cmd("sem logs #{job_id}")
end

#fetch_workflows(age: "24h") ⇒ Object



11
12
13
14
15
# File 'lib/flaky/providers/semaphore.rb', line 11

def fetch_workflows(age: "24h")
  output = run_cmd("sem get workflows -p #{config.project} --age #{age}")
  lines = output.lines.drop(1) # skip header
  lines.filter_map { |line| parse_workflow_line(line) }
end