diff --git a/judges/quality-of-service/quality-of-service.rb b/judges/quality-of-service/quality-of-service.rb index 0445bdf0..aa03b9bd 100644 --- a/judges/quality-of-service/quality-of-service.rb +++ b/judges/quality-of-service/quality-of-service.rb @@ -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| @@ -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| @@ -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') diff --git a/judges/quality-of-service/simple-collect.yml b/judges/quality-of-service/simple-collect.yml index 1fb1b970..5a95b24d 100644 --- a/judges/quality-of-service/simple-collect.yml +++ b/judges/quality-of-service/simple-collect.yml @@ -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] \ No newline at end of file + - /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] \ No newline at end of file