Skip to content

Commit

Permalink
#135: qos works in live
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 22, 2024
1 parent d65bd1b commit d76fb21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
19 changes: 16 additions & 3 deletions judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@
(gt when (minus (to_time (env 'TODAY' '#{Time.now}')) '7 days')))"
).each.to_a.empty?

$DAYS = 28
pmp = Fbe.fb.query('(and (eq what "pmp") (eq area "quality") (exists qos_days))').each.to_a.first
$DAYS = pmp.nil? ? 28 : pmp.qos_days
$SINCE = Time.now - ($DAYS * 24 * 60 * 60)

f = Fbe.fb.insert
f.what = $judge
f.when = Time.now

# Workflow runs:
total = 0
success = 0
Fbe.unmask_repos.each do |repo|
Fbe.octo.repository_workflow_runs(repo, created: ">#{$SINCE}")[:workflow_runs].each do |json|
total += 1
success += json[:conclusion] == 'success' ? 1 : 0
end
end
f.average_workflow_success_rate = total.zero? ? 0 : success.to_f / total

# Release intervals:
dates = []
Fbe.unmask_repos.each do |repo|
Fbe.octo.releases(repo).each do |json|
Expand All @@ -48,6 +61,7 @@
diffs = (1..dates.size - 1).map { |i| dates[i] - dates[i - 1] }
f.average_release_interval = diffs.empty? ? 0 : diffs.inject(&:+) / diffs.size

# Issue and PR lifetimes:
def lifetime(type)
ages = []
Fbe.unmask_repos.each do |repo|
Expand All @@ -59,8 +73,7 @@ def lifetime(type)
end
end
ages.compact!
ages.empty? ? 0 : ages.inject(&:+) / ages.size
ages.empty? ? 0 : ages.inject(&:+).to_f / ages.size
end

f.average_issue_lifetime = lifetime('issue')
f.average_pull_lifetime = lifetime('pr')
13 changes: 9 additions & 4 deletions judges/quality-of-service/simple-collect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ options:
repositories: yegor256/judges
# testing: true
input:
-
what: pmp
area: quality
qos_days: 7
-
what: quality-of-service
when: 2024-01-01T00:00:00
expected:
- /fb[count(f)=2]
- /fb/f[average_issue_lifetime=0]
- /fb/f[average_pull_lifetime=0]
- /fb/f[average_release_interval=0]
- /fb[count(f)=3]
- /fb/f[average_issue_lifetime != 0]
- /fb/f[average_pull_lifetime != 0]
- /fb/f[average_release_interval != 0]
- /fb/f[average_workflow_success_rate != 0]

0 comments on commit d76fb21

Please sign in to comment.