Skip to content

Commit f91be5e

Browse files
committedDec 19, 2024··
#412: total_commits_pushed
1 parent 98d57bf commit f91be5e

File tree

3 files changed

+78
-61
lines changed

3 files changed

+78
-61
lines changed
 

‎judges/quantity-of-deliverables/quantity-of-deliverables.rb

+1-17
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
require 'fbe/fb'
26-
require 'fbe/octo'
2725
require 'fbe/overwrite'
28-
require 'fbe/unmask_repos'
26+
require 'fbe/octo'
2927
require 'fbe/regularly'
3028

3129
start = Time.now
@@ -44,18 +42,4 @@
4442
require_relative rb
4543
send(n, f).each { |k, v| f = Fbe.overwrite(f, k.to_s, v) }
4644
end
47-
48-
# Number of commits pushed and their hits-of-code:
49-
commits = 0
50-
hoc = 0
51-
Fbe.unmask_repos.each do |repo|
52-
next if Fbe.octo.repository(repo)[:size].zero?
53-
54-
Fbe.octo.commits_since(repo, f.since).each do |json|
55-
commits += 1
56-
hoc += Fbe.octo.commit(repo, json[:sha])[:stats][:total]
57-
end
58-
end
59-
f.total_commits_pushed = commits
60-
f.total_hoc_committed = hoc
6145
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2024 Zerocracy
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
require 'fbe/octo'
26+
require 'fbe/unmask_repos'
27+
28+
# Number of commits pushed and their hits-of-code:
29+
#
30+
# This function is called from the "quantity-of-deliverables.rb".
31+
#
32+
# @param [Factbase::Fact] fact The fact just under processing
33+
# @return [Hash] Map with keys as fact attributes and values as integers
34+
def total_commits_pushed(fact)
35+
commits = 0
36+
hoc = 0
37+
Fbe.unmask_repos.each do |repo|
38+
next if Fbe.octo.repository(repo)[:size].zero?
39+
Fbe.octo.commits_since(repo, fact.since).each do |json|
40+
commits += 1
41+
hoc += Fbe.octo.commit(repo, json[:sha])[:stats][:total]
42+
end
43+
end
44+
{
45+
total_commits_pushed: commits,
46+
total_hoc_committed: hoc
47+
}
48+
end

‎test/judges/test-quantity-of-deliverables.rb

+29-44
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
require 'minitest/autorun'
2929
require 'webmock/minitest'
3030
require 'judges/options'
31+
require_relative '../test__helper'
3132

3233
# Test.
3334
# Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -37,58 +38,48 @@ class TestQuantityOfDeliverables < Minitest::Test
3738
def test_counts_commits
3839
WebMock.disable_net_connect!
3940
stub_github('https://api.github.com/rate_limit', body: {})
40-
stub_request(:get, 'https://api.github.com/user/42').to_return(
41-
body: { id: 42, login: 'torvalds' }.to_json, headers: {
42-
'content-type': 'application/json'
43-
}
41+
stub_github(
42+
'https://api.github.com/user/42',
43+
body: { id: 42, login: 'torvalds' }
4444
)
45-
stub_request(:get, 'https://api.github.com/repos/foo/foo').to_return(
46-
body: { id: 42, full_name: 'foo/foo', open_issues: 0, size: 10 }.to_json, headers: {
47-
'content-type': 'application/json'
48-
}
45+
stub_github(
46+
'https://api.github.com/repos/foo/foo',
47+
body: { id: 42, full_name: 'foo/foo', open_issues: 0, size: 10 }
4948
)
50-
stub_request(:get, 'https://api.github.com/repos/foo/foo/commits?per_page=100&since=2024-07-15T21:00:00%2B00:00').to_return(
49+
stub_github(
50+
'https://api.github.com/repos/foo/foo/commits?per_page=100&since=2024-07-15T21:00:00%2B00:00',
5151
body: [
5252
{
5353
sha: 'bcb3cd5c2a6f3daebe1a2ab16a195a0bf2609943'
5454
},
5555
{
5656
sha: '0d705c564abc9e5088f00310c42b82bc9f192a3d'
5757
}
58-
].to_json,
59-
headers: {
60-
'content-type': 'application/json'
61-
}
58+
]
6259
)
63-
stub_request(:get, 'https://api.github.com/repos/foo/foo/commits/bcb3cd5c2a6f3daebe1a2ab16a195a0bf2609943').to_return(
60+
stub_github(
61+
'https://api.github.com/repos/foo/foo/commits/bcb3cd5c2a6f3daebe1a2ab16a195a0bf2609943',
6462
body: {
6563
stats: {
6664
total: 10
6765
}
68-
}.to_json,
69-
headers: {
70-
'content-type': 'application/json'
7166
}
7267
)
73-
stub_request(:get, 'https://api.github.com/repos/foo/foo/commits/0d705c564abc9e5088f00310c42b82bc9f192a3d').to_return(
68+
stub_github(
69+
'https://api.github.com/repos/foo/foo/commits/0d705c564abc9e5088f00310c42b82bc9f192a3d',
7470
body: {
7571
stats: {
7672
total: 10
7773
}
78-
}.to_json,
79-
headers: {
80-
'content-type': 'application/json'
8174
}
8275
)
83-
stub_request(:get, 'https://api.github.com/repos/foo/foo/issues?per_page=100&since=%3E2024-07-15').to_return(
76+
stub_github(
77+
'https://api.github.com/repos/foo/foo/issues?per_page=100&since=%3E2024-07-15',
8478
body: [
8579
{
8680
pull_request: {}
8781
}
88-
].to_json,
89-
headers: {
90-
'content-type': 'application/json'
91-
}
82+
]
9283
)
9384
stub_github(
9485
'https://api.github.com/repos/foo/foo/releases?per_page=100',
@@ -113,32 +104,26 @@ def test_counts_commits
113104
def test_processes_empty_repository
114105
WebMock.disable_net_connect!
115106
stub_github('https://api.github.com/rate_limit', body: {})
116-
stub_request(:get, 'https://api.github.com/user/42').to_return(
117-
body: { id: 42, login: 'torvalds' }.to_json, headers: {
118-
'content-type': 'application/json'
119-
}
107+
stub_github(
108+
'https://api.github.com/user/42',
109+
body: { id: 42, login: 'torvalds' }
120110
)
121-
stub_request(:get, 'https://api.github.com/repos/foo/foo').to_return(
122-
body: { id: 42, full_name: 'foo/foo', open_issues: 0, size: 0 }.to_json, headers: {
123-
'content-type': 'application/json'
124-
}
111+
stub_github(
112+
'https://api.github.com/repos/foo/foo',
113+
body: { id: 42, full_name: 'foo/foo', open_issues: 0, size: 0 }
125114
)
126-
stub_request(:get, 'https://api.github.com/repos/foo/foo/commits?per_page=100&since=2024-07-15T21:00:00%2B00:00').to_return(
115+
stub_github(
116+
'https://api.github.com/repos/foo/foo/commits?per_page=100&since=2024-07-15T21:00:00%2B00:00',
127117
status: 409,
128-
body: [].to_json,
129-
headers: {
130-
'content-type': 'application/json'
131-
}
118+
body: []
132119
)
133-
stub_request(:get, 'https://api.github.com/repos/foo/foo/issues?per_page=100&since=%3E2024-07-15').to_return(
120+
stub_github(
121+
'https://api.github.com/repos/foo/foo/issues?per_page=100&since=%3E2024-07-15',
134122
body: [
135123
{
136124
pull_request: {}
137125
}
138-
].to_json,
139-
headers: {
140-
'content-type': 'application/json'
141-
}
126+
]
142127
)
143128
stub_github(
144129
'https://api.github.com/repos/foo/foo/releases?per_page=100',

0 commit comments

Comments
 (0)
Please sign in to comment.