Skip to content

Commit

Permalink
#195: calculate total number of CI builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegorov committed Sep 22, 2024
1 parent a31f9b7 commit 8791867
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions judges/quantity-of-deliverables/count-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ expected:
- /fb/f[total_pulls_submitted != 0]
- /fb/f[total_releases_published != 0]
- /fb/f[total_reviews_submitted = 0]
- /fb/f[total_builds_ran != 0]
6 changes: 6 additions & 0 deletions judges/quantity-of-deliverables/quantity-of-deliverables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@
end
end
end

# Total number of CI builds executed in all repositories from since
f.total_builds_ran =
Fbe.unmask_repos.sum do |repo|
Fbe.octo.repository_workflow_runs(repo, created: ">#{f.since.utc.iso8601[0..9]}")[:total_count]
end
end
85 changes: 85 additions & 0 deletions test/judges/test-quantity-of-deliverables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def test_counts_commits
body: [{ id: 1, draft: false, published_at: Time.parse('2024-08-01 21:00:00 UTC') }]
)
stub_github('https://api.github.com/repos/foo/foo/pulls?per_page=100&state=all', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/actions/runs?created=%3E2024-07-15&per_page=100',
body: { total_count: 0, workflow_runs: [] }
)
fb = Factbase.new
Time.stub(:now, Time.parse('2024-08-12 21:00:00 UTC')) do
load_it('quantity-of-deliverables', fb)
Expand Down Expand Up @@ -139,6 +143,10 @@ def test_processes_empty_repository
body: [{ id: 1, draft: false, published_at: Time.parse('2024-08-01 21:00:00 UTC') }]
)
stub_github('https://api.github.com/repos/foo/foo/pulls?per_page=100&state=all', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/actions/runs?created=%3E2024-07-15&per_page=100',
body: { total_count: 0, workflow_runs: [] }
)
fb = Factbase.new
Time.stub(:now, Time.parse('2024-08-12 21:00:00 UTC')) do
load_it('quantity-of-deliverables', fb)
Expand Down Expand Up @@ -191,6 +199,10 @@ def test_quantity_of_deliverables_total_releases_published
]
)
stub_github('https://api.github.com/repos/foo/foo/pulls?per_page=100&state=all', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/actions/runs?created=%3E2024-08-02&per_page=100',
body: { total_count: 0, workflow_runs: [] }
)
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand Down Expand Up @@ -370,6 +382,13 @@ def test_quantity_of_deliverables_total_reviews_submitted
}
]
)
stub_github(
'https://api.github.com/repos/foo/foo/actions/runs?created=%3E2024-08-02&per_page=100',
body: {
total_count: 0,
workflow_runs: []
}
)
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
Expand All @@ -384,4 +403,70 @@ def test_quantity_of_deliverables_total_reviews_submitted
assert_equal(5, f.total_reviews_submitted)
end
end

def test_quantity_of_deliverables_total_builds_ran
WebMock.disable_net_connect!
stub_github(
'https://api.github.com/repos/foo/foo',
body: { id: 42, full_name: 'foo/foo', open_issues: 0, size: 100 }
)
stub_github(
'https://api.github.com/repos/foo/foo/commits?per_page=100&since=2024-08-02T21:00:00%2B00:00',
body: []
)
stub_github(
'https://api.github.com/repos/foo/foo/issues?per_page=100&since=%3E2024-08-02',
body: [{ pull_request: {} }]
)
stub_github('https://api.github.com/repos/foo/foo/releases?per_page=100', body: [])
stub_github('https://api.github.com/repos/foo/foo/pulls?per_page=100&state=all', body: [])
stub_github(
'https://api.github.com/repos/foo/foo/actions/runs?created=%3E2024-08-02&per_page=100',
body: {
total_count: 3,
workflow_runs: [
{
id: 710,
display_title: 'some title',
run_number: 2615,
event: 'dynamic',
status: 'completed',
conclusion: 'success',
workflow_id: 141
},
{
id: 708,
display_title: 'some title',
run_number: 2612,
event: 'schedule',
status: 'completed',
conclusion: 'success',
workflow_id: 141
},
{
id: 705,
display_title: 'some title',
run_number: 2610,
event: 'push',
status: 'completed',
conclusion: 'failure',
workflow_id: 141
}
]
}
)
fb = Factbase.new
f = fb.insert
f.what = 'pmp'
f.area = 'scope'
f.qod_days = 7
f.qod_interval = 3
Time.stub(:now, Time.parse('2024-08-09 21:00:00 UTC')) do
load_it('quantity-of-deliverables', fb)
f = fb.query('(eq what "quantity-of-deliverables")').each.to_a.first
assert_equal(Time.parse('2024-08-03 00:00:00 +03:00'), f.since)
assert_equal(Time.parse('2024-08-09 21:00:00 UTC'), f.when)
assert_equal(3, f.total_builds_ran)
end
end
end

0 comments on commit 8791867

Please sign in to comment.