Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage/
*.db
.bundle/
_snippets/
_cache/
_cache/
.ruby-version
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AllCops:
Exclude:
- '_*/**/*'
# - '_snippets/**/*'
- 'app/infrastructure/git/repostore/**/*'
# - 'app/infrastructure/git/repostore/**/*'

# ignore block length in non-production code
Metrics/BlockLength:
Expand Down
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ gem 'aws-sdk-sqs', '~> 1'
gem 'hirb', '~> 0.7'
gem 'sequel', '~> 5.13'

# Ruby AST unparser
gem 'unparser'

# Git Operation by using git object
gem 'git', '~> 1.5'

group :development, :test do
gem 'database_cleaner'
gem 'sqlite3'
gem 'factory_bot', '~> 5.0', '>= 5.0.2'
end

group :production do
Expand Down
34 changes: 34 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
abstract_type (0.0.7)
activesupport (5.2.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
adamantium (0.2.0)
ice_nine (~> 0.11.0)
memoizable (~> 0.4.0)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
Expand All @@ -27,6 +36,9 @@ GEM
coderay (1.1.2)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concord (0.1.5)
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.1.3)
connection_pool (2.2.2)
cookiejar (0.3.3)
Expand All @@ -38,6 +50,7 @@ GEM
declarative-option (0.1.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.3)
docile (1.3.1)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
Expand Down Expand Up @@ -100,6 +113,8 @@ GEM
ethon (0.11.0)
ffi (>= 1.3.0)
eventmachine (1.2.7)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
Expand Down Expand Up @@ -127,6 +142,7 @@ GEM
multi_json (~> 1.0)
net-http-persistent (>= 2.7)
net-http-pipeline
git (1.5.0)
hashdiff (0.3.7)
highline (1.7.10)
hirb (0.7.3)
Expand All @@ -139,6 +155,8 @@ GEM
domain_name (~> 0.5)
http-form_data (2.1.1)
http_parser.rb (0.6.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
interception (0.5)
jaro_winkler (1.5.1)
Expand All @@ -151,6 +169,8 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (0.9.2)
minitest (5.11.3)
minitest-rg (5.2.0)
Expand All @@ -166,6 +186,7 @@ GEM
path_expander (1.0.3)
pg (0.21.0)
powerpack (0.1.2)
procto (0.0.3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand Down Expand Up @@ -249,11 +270,21 @@ GEM
typhoeus (~> 0.6, >= 0.6.8)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unicode-display_width (1.4.0)
unparser (0.4.2)
abstract_type (~> 0.0.7)
adamantium (~> 0.2.0)
concord (~> 0.1.5)
diff-lcs (~> 1.3)
equalizer (~> 0.0.9)
parser (>= 2.3.1.2, < 2.6)
procto (~> 0.0.2)
vcr (4.0.0)
virtus (1.0.5)
axiom-types (~> 0.1)
Expand Down Expand Up @@ -281,8 +312,10 @@ DEPENDENCIES
dry-types (~> 0.5)
dry-validation
econfig (~> 2.1)
factory_bot (~> 5.0, >= 5.0.2)
faye (~> 1)
flog
git (~> 1.5)
hirb (~> 0.7)
http (~> 3.0)
minitest (~> 5.11)
Expand All @@ -308,6 +341,7 @@ DEPENDENCIES
simplecov (~> 0.16)
sqlite3
travis
unparser
vcr (~> 4.0)
webmock (~> 3.4)

Expand Down
8 changes: 4 additions & 4 deletions app/application/services/appraise_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def find_project_details(input)
input[:project] = Repository::For.klass(Entity::Project).find_full_name(
input[:requested].owner_name, input[:requested].project_name
)

if input[:project]
Success(input)
else
Expand Down Expand Up @@ -59,10 +58,11 @@ def request_cloning_worker(input)
end

def appraise_contributions(input)
input[:folder] = Mapper::Contributions
.new(input[:gitrepo]).for_folder(input[:requested].folder_name)
contributions = Mapper::Contributions.new(input[:gitrepo])
input[:folder] = contributions.for_folder(input[:requested].folder_name)
input[:commits] = contributions.commits

Value::ProjectFolderContributions.new(input[:project], input[:folder])
Value::ProjectFolderContributions.new(input[:project], input[:folder], input[:commits])
.yield_self do |appraisal|
Success(Value::Result.new(status: :ok, message: appraisal))
end
Expand Down
2 changes: 1 addition & 1 deletion app/application/values/project_folder_contributions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
module CodePraise
module Value
# Contributions for a folder of a project
ProjectFolderContributions = Struct.new(:project, :folder)
ProjectFolderContributions = Struct.new(:project, :folder, :commits)
end
end
15 changes: 15 additions & 0 deletions app/domain/models/contributions/entities/children/complexity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module CodePraise
module Entity
# Complexity for file and methods of this file
class Complexity
attr_reader :average, :methods

def initialize(average:, methods:)
@average = average
@methods = methods
end
end
end
end
21 changes: 21 additions & 0 deletions app/domain/models/contributions/entities/children/file_change.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'dry-types'
require 'dry-struct'


module CodePraise
module Entity
# Entity for a single line of code contributed by a team-member
class FileChange < Dry::Struct

include Dry::Types.module

attribute :path, Strict::String
attribute :name, Strict::String
attribute :addition, Strict::Integer
attribute :deletion, Strict::Integer

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ module Entity
# Entity for file contributions
class FileContributions
include Mixins::ContributionsCalculator
include Mixins::CommentCalculator

DOT = '\.'
LINE_END = '$'
WANTED_EXTENSION = %w[rb js css html slim md].join('|')
EXTENSION_REGEX = /#{DOT}#{WANTED_EXTENSION}#{LINE_END}/.freeze

attr_reader :file_path, :lines
attr_reader :file_path, :lines, :complexity, :idiomaticity, :methods

def initialize(file_path:, lines:)
def initialize(file_path:, lines:, complexity:, idiomaticity:, methods:)
@file_path = Value::FilePath.new(file_path)
@lines = lines
@complexity = complexity
@idiomaticity = idiomaticity
@methods = methods
end

def total_credits
credit_share.total_credits
def total_line_credits
line_credit_share.total_credits
end

def credit_share
def line_credit_share
return Value::CreditShare.new if not_wanted

@credit_share ||= lines
Expand All @@ -32,7 +36,7 @@ def credit_share
end

def contributors
credit_share.contributors
line_credit_share.contributors
end

private
Expand Down
15 changes: 15 additions & 0 deletions app/domain/models/contributions/entities/children/idiomaticity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'dry-types'
require 'dry-struct'
require_relative 'offense'

module CodePraise
module Entity
class Idiomaticity < Dry::Struct
include Dry::Types.module

attribute :offenses, Strict::Array.of(Entity::Offense).optional
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative 'line_contribution'
require 'dry-types'
require 'dry-struct'

module CodePraise
module Entity
# Entity for a single method contributed by a team-member
class MethodContribution < Dry::Struct
include Dry::Types.module

attribute :name, Coercible::String
attribute :lines, Array.of(LineContribution)

def credit_share
@credit_share ||= lines.each_with_object(Value::CreditShare.new) do |line, credit|
credit.add_credit(line)
end
end

def share
credit_share.share
end

def contributors
credit_share.contributors
end
end
end
end
16 changes: 16 additions & 0 deletions app/domain/models/contributions/entities/children/offense.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require 'dry-types'
require 'dry-struct'

module CodePraise
module Entity
class Offense < Dry::Struct
include Dry::Types.module

attribute :type, Strict::String
attribute :message, Strict::String
attribute :location, Strict::Integer
end
end
end
2 changes: 1 addition & 1 deletion app/domain/models/contributions/entities/init.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

folders = %w[children root]
folders = %w[metrics children root]
folders.each do |folder|
require_relative "#{folder}/init.rb"
end
5 changes: 5 additions & 0 deletions app/domain/models/contributions/entities/metrics/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Dir.glob("#{__dir__}/*.rb").each do |file|
require file
end
33 changes: 33 additions & 0 deletions app/domain/models/contributions/entities/root/commit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require 'dry-types'
require 'dry-struct'
require_relative '../children/contributor'

module CodePraise
module Entity
# Entity for a single line of code contributed by a team-member
class Commit < Dry::Struct
include Dry::Types.module

attribute :committer, Contributor
attribute :sha, Strict::String
attribute :date, Params::DateTime
attribute :size, Strict::Integer
attribute :message, Strict::String
attribute :file_changes, Strict::Array.of(FileChange)

def total_additions
file_changes.map(&:addition).reduce(&:+)
end

def total_deletions
file_changes.map(&:deletion).reduce(&:+)
end

def total_files
file_changes.count
end
end
end
end
Loading