Class: Flaky::Providers::Semaphore
- Inherits:
-
Base
- Object
- Base
- Flaky::Providers::Semaphore
show all
- Defined in:
- lib/flaky/providers/semaphore.rb
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#fetch_jobs(pipeline_id:) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/flaky/providers/semaphore.rb', line 51
def fetch_jobs(pipeline_id:)
data = api_get("pipelines/#{pipeline_id}", detailed: true)
blocks = data["blocks"] || []
test_blocks = config.test_blocks
blocks.flat_map do |block|
block_name = block["name"]
next [] unless test_blocks.include?(block_name)
(block["jobs"] || []).map do |job|
{
id: job["job_id"],
name: job["name"],
block_name: block_name,
result: job["result"]&.downcase == "passed" ? "passed" : "failed"
}
end
end
end
|
#fetch_log(job_id:) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/flaky/providers/semaphore.rb', line 71
def fetch_log(job_id:)
data = api_get("logs/#{job_id}")
events = data["events"] || []
events
.select { |e| e["event"] == "cmd_output" }
.map { |e| e["output"] }
.join
end
|
#fetch_workflows(age: "24h") ⇒ Object
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
41
42
43
44
45
46
47
48
49
|
# File 'lib/flaky/providers/semaphore.rb', line 13
def fetch_workflows(age: "24h")
cutoff = Time.now - AgeParser.to_seconds(age)
project_id = resolve_project_id
branch = config.branch
workflows = []
page = 1
loop do
data = api_get("plumber-workflows", project_id: project_id, page: page)
break if data.empty?
data.each do |wf|
created_at = Time.at(wf.dig("created_at", "seconds").to_i)
next unless wf["branch_name"] == branch
if created_at < cutoff
return workflows end
workflows << {
id: wf["wf_id"],
pipeline_id: wf["initial_ppl_id"],
branch: wf["branch_name"],
commit_sha: wf["commit_sha"],
created_at: created_at.strftime("%Y-%m-%d %H:%M:%S")
}
end
oldest = Time.at(data.last.dig("created_at", "seconds").to_i)
break if oldest < cutoff
page += 1
end
workflows
end
|