Class: Fief::Runs

Inherits:
Object
  • Object
show all
Defined in:
lib/fief/metrics/runs.rb

Overview

GitHub Action Runs in one GitHub repository.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2023 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(api, repo, opts) ⇒ Runs

Returns a new instance of Runs.



26
27
28
29
30
# File 'lib/fief/metrics/runs.rb', line 26

def initialize(api, repo, opts)
  @api = api
  @repo = repo
  @opts = opts
end

Instance Method Details

#take(loog) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fief/metrics/runs.rb', line 32

def take(loog)
  master = @api.repository(@repo)[:default_branch]
  json = @api.repository_workflow_runs(@repo, branch: master)
  workflows = []
  failures = 0
  json[:workflow_runs].take(32).each do |run|
    workflow = run[:workflow_id]
    next if workflows.include?(workflow)
    workflows << workflow
    next if run[:status] != 'completed'
    conclusion = run[:conclusion]
    loog.debug("Workflow run '#{run[:name]}' in #{@repo} is '#{conclusion}'")
    if conclusion == 'failure'
      loog.debug("Workflow run '#{run[:name]}' is failed")
      failures += 1
    end
  end
  [
    {
      title: 'CI failures',
      value: failures,
      alert: failures > 0
    }
  ]
end