Skip to content

Commit

Permalink
#412: average_release_hoc_size
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 18, 2024
1 parent 4d11ef6 commit 197a584
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
56 changes: 56 additions & 0 deletions judges/quality-of-service/average_release_hoc_size.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

# MIT License
#
# Copyright (c) 2024 Zerocracy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'fbe/octo'
require 'fbe/unmask_repos'

# Release hoc and commit size
#
# This function is called from the "quality-of-service.rb".
#
# @param [Factbase::Fact] fact The fact just under processing
# @return [Hash] Map with keys as fact attributes and values as integers
def average_release_hoc_size(fact)
repo_releases = {}
hocs = []
commits = []
Fbe.unmask_repos.each do |repo|
Fbe.octo.releases(repo).each do |json|
break if json[:published_at] < fact.since
(repo_releases[repo] ||= []) << json
end
end
repo_releases.each do |repo, releases|
releases.reverse.each_cons(2) do |first, last|
Fbe.octo.compare(repo, first[:tag_name], last[:tag_name]).then do |json|
hocs << json[:files].map { |file| file[:changes] }.sum
commits << json[:total_commits]
end
end
end
{
average_release_hoc_size: hocs.empty? ? 0 : hocs.sum.to_f / hocs.size,
average_release_commits_size: commits.empty? ? 0 : commits.sum.to_f / commits.size
}
end
21 changes: 0 additions & 21 deletions judges/quality-of-service/quality-of-service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,6 @@
send(n, f).each { |k, v| f = Fbe.overwrite(f, k.to_s, v) }
end

# Release hoc and commit size
repo_releases = {}
hocs = []
commits = []
Fbe.unmask_repos.each do |repo|
Fbe.octo.releases(repo).each do |json|
break if json[:published_at] < f.since
(repo_releases[repo] ||= []) << json
end
end
repo_releases.each do |repo, releases|
releases.reverse.each_cons(2) do |first, last|
Fbe.octo.compare(repo, first[:tag_name], last[:tag_name]).then do |json|
hocs << json[:files].map { |file| file[:changes] }.sum
commits << json[:total_commits]
end
end
end
f.average_release_hoc_size = hocs.empty? ? 0 : hocs.sum.to_f / hocs.size
f.average_release_commits_size = commits.empty? ? 0 : commits.sum.to_f / commits.size

# Issue and PR lifetimes:
{ issue: 'average_issue_lifetime', pr: 'average_pull_lifetime' }.each do |type, prop|
ages = []
Expand Down

0 comments on commit 197a584

Please sign in to comment.