Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3dc88d0
fixed api_spec_acceptence.rb
twohorse0311 Oct 25, 2023
76d7a75
deleted binding.pry in all files
twohorse0311 Nov 2, 2023
e2a116f
<fix: rubocop_spec and skip some test>
twohorse0311 Nov 8, 2023
e6c9122
<fix: spec/tests_unit/appraisal_odm_spec.rb>
twohorse0311 Nov 8, 2023
8a41981
<fix: spec/tests_unit/appraisal_odm_spec.rb>
twohorse0311 Nov 8, 2023
fc60b70
<fix:spec/tests_unit/metrics/comment_spec.rb and update .rubocop.yml …
twohorse0311 Nov 8, 2023
c8eff9b
<fix: spec/tests_unit/metrics/complexity_spec.rb>
twohorse0311 Nov 8, 2023
1eaaa80
fix: spec/tests_unit/metrics/idiomaticity_spec.rb
twohorse0311 Nov 8, 2023
f2b4bb8
fixed: skip the test inspec/tests_integration/layers_integration/cont…
twohorse0311 Nov 9, 2023
d018832
fixed: fix the bug in spec/tests_integration/service_integration/add_…
twohorse0311 Nov 9, 2023
61ba582
fixed: spec/tests_integration/service_integration/appraise_project_sp…
twohorse0311 Nov 9, 2023
8302366
<chore:updated README for setting up for the test>
twohorse0311 Nov 10, 2023
992435a
<chore:updated README for setting up for the test>
twohorse0311 Nov 10, 2023
19f6363
<fixed: ruby code parsing error>
twohorse0311 Nov 13, 2023
7a0fc9b
<chore: update to catch parsing error>
twohorse0311 Nov 23, 2023
94380ec
Merge pull request #49 from codepraise/fix/parser_gem
twohorse0311 Nov 28, 2023
0dc28f9
fix: contributor_measure_spec
twohorse0311 Nov 29, 2023
78edd63
fix: file_measure_spec
twohorse0311 Nov 29, 2023
2711866
fix: credit_share_spec.rb
twohorse0311 Nov 29, 2023
eae25c8
test: remove delete repo
twohorse0311 Mar 20, 2024
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
Binary file added .DS_Store
Binary file not shown.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ Status

- 201: project stored (happy)
- 404: project or folder not found on Github (sad)
- 500: problems storing the project (bad)
- 500: problems storing the project (bad)

### Set up for test

1. Run `RACK_ENV=test rake db:migrate` if you never run the test.
2. Open a new kernal and run `rake worker:run:test`.
3. Run `rake spec` or any other sperate file on the first kernal to go through the test.

Binary file added app/.DS_Store
Binary file not shown.
91 changes: 80 additions & 11 deletions app/domain/models/contributions/mappers/method_parser.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,109 @@
# frozen_string_literal: true

require 'parser/current'
require 'parser/ruby31'

module CodePraise
module Mapper
# Find all method in a file
module MethodParser
def self.parse_methods(line_entities)
ast = Parser::CurrentRuby.parse(line_of_code(line_entities).dump)
ast = Parser::Ruby31.parse(line_of_code(line_entities).dump)
all_methods_hash(ast, line_entities)
end

def self.line_of_code(line_entities)
line_entities.map(&:code).join("\n")
line_entities.map(&:code).join("\n")
end

def self.all_methods_hash(ast, line_entities)
methods_ast = []
find_methods_tree(ast, methods_ast)

methods_ast.inject([]) do |result, method_ast|
dsf_array = distinguish_success_or_fail_entities(methods_ast, line_entities)
dsf_array = adjust_dsf_array(methods_ast, line_entities, dsf_array)

result = []
dsf_array.each_with_index do |item, index|
method_ast = methods_ast[index]
result.push(name: method_name(method_ast),
lines: select_entities(method_ast, line_entities),
lines: line_entities[item[0]..item[1]],
type: method_type(method_ast))
end
result
# methods_ast.inject([]) do |result, method_ast|
# if method_ast.class == Hash
# result.push(name: method_ast[:name],
# lines: line_entities[dsf_array[index][0]..dsf_array[index][1]],
# type: method_ast[:type])
# else
# result.push(name: method_name(method_ast),
# lines: select_entities(method_ast, line_entities),
# type: method_type(method_ast))
# end
# index += 1
# result
# end
end

def self.select_entities(method_ast, line_entities)
first_no = method_ast.loc.first_line - 1
last_no = method_ast.loc.last_line - 1
line_entities[first_no..last_no]
def self.select_entities(methods_ast, line_entities)
success_parse_entity = []
methods_ast.each{ |method_ast|
if method_ast.class != Hash
first_no = method_ast.loc.first_line - 1
last_no = method_ast.loc.last_line - 1
success_parse_entity.append([first_no, last_no])
end
}
success_parse_entity
end

private

def self.distinguish_success_or_fail_entities(methods_ast, line_entities)
success_parse_entity = select_entities(methods_ast, line_entities)
return success_parse_entity if !methods_ast.to_s.include?('unknow method')

adjust_success_array(success_parse_entity)
end

def self.method_type(method_ast)
method_ast.type.to_s
if method_ast.is_a?(Hash)
method_ast[:type]
else
method_ast.type.to_s
end
end

def self.method_name(method_ast)
method_ast.loc.expression.source_line
if method_ast.is_a?(Hash)
method_ast[:name]
else
method_ast.loc.expression.source_line
end
end

def self.adjust_dsf_array(methods_ast, line_entities, dsf_array)
if methods_ast[0].instance_of?(Hash)
begin
head_pointer = dsf_array[0][0]
dsf_array.insert(0, [0, head_pointer - 1])
rescue NoMethodError
dsf_array.insert(0, [0, line_entities.length - 1])
end
end
dsf_array
end

def self.adjust_success_array(success_parse_entity)
(success_parse_entity.length - 1).downto(1) do |i|
current_end = success_parse_entity[i - 1][1]
next_start = success_parse_entity[i][0]

if current_end + 1 != next_start && current_end + 1 != next_start - 1
success_parse_entity.insert(i, [current_end + 1, next_start - 1])
end
end
success_parse_entity
end

def self.find_methods_tree(ast, methods_ast)
Expand All @@ -49,7 +113,12 @@ def self.find_methods_tree(ast, methods_ast)
methods_ast.append(ast)
else
ast.children.each do |child_ast|
child_ast = Parser::Ruby31.parse(child_ast) if child_ast.instance_of?(String)
find_methods_tree(child_ast, methods_ast)
rescue Parser::SyntaxError => e
puts "Parsing error :
#{e.message}"
methods_ast.append({'name': 'unknow method', 'lines': child_ast, 'type': 'SyntaxError'})
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Mapper
# Find the testcase in test file by using AST (ruby-parser gem)
module TestCaseParser
def self.parse(code)
ast = Parser::CurrentRuby.parse(code.dump)
ast = Parser::Ruby31.parse(code.dump)
test_cases = []
find_test_cases(ast, test_cases)
test_cases.map do |test_case|
Expand Down
Binary file added app/infrastructure/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions app/infrastructure/database/odms/appraisal_odm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def save
end
end

def self.all
COLLECTION.find.map do |doc|
build_object(doc)
end
end


def delete
COLLECTION.delete_one(@document)
end
Expand Down
Binary file added app/presentation/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def self.reload!
end

configure :development, :test, :data do
ENV['MONGODB_URI'] = 'mongodb://' + config.MONGO_URL
ENV['MONGODB_URL'] = 'mongodb://' + config.MONGO_URL
end

configure :development, :data do
Expand Down Expand Up @@ -75,7 +75,7 @@ def self.DB # rubocop:disable Naming/MethodName
end

require 'mongo'
MONGO = Mongo::Client.new(ENV['MONGODB_URI'])
MONGO = Mongo::Client.new(ENV['MONGODB_URL'])

def self.mongo
MONGO
Expand Down
Loading