forked from whitesmith/rubycritic
-
Notifications
You must be signed in to change notification settings - Fork 1
Rubycritic compare b/w branches #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HemanthMudalaiah
wants to merge
45
commits into
master
Choose a base branch
from
rubycritic_compare_branches
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
6836dd9
This commit will have changes in rubycritic where you can compare two…
6e691f1
This commit has changes where we can decide which of the file changes…
675a08a
Comparing the diff with the whole branch for duplication analysis
c34ae94
Configuring smell link to point to feature branch code
3b77fd1
Changes in the content of the build details
a694137
Gitlab Integration
5560a78
Code cleanup
d52cdc4
Specs and code cleanup
c1a0938
Fix some ruby warnings thrown on rake test
tejasbubane bae045b
Merge pull request #183 from tejasbubane/fix-warnings
troessner de8d037
Code Cleanup & Refactoring
be7827f
Added specs and threshold option
879833a
Removing simplecov from dependency
13502f0
Refactoring compare module
57257da
Code cleanup
c251517
Options and compare changes
f34bf45
Revamp the web UI
rohitcy b977b62
Merge pull request #184 from cybrilla/new-web-ui
nunosilva800 0cb3f57
Bump to v3.1.0
nunosilva800 871a38e
Merge pull request #185 from whitesmith/bump-to-3.1
troessner 86557cc
Add screenshot of new ui [ci skip]
nav16 b5e532d
Merge pull request #186 from nav16/update-readme
troessner 4f70be6
Fixing the options fetaure spec
f25a40f
Code cleanup and changes
112e0a5
Spec fix
8d0ebe0
Abort message changes
eb9e54a
This commit will have changes in rubycritic where you can compare two…
696446c
This commit has changes where we can decide which of the file changes…
afe93c0
Comparing the diff with the whole branch for duplication analysis
1a515d7
Configuring smell link to point to feature branch code
1da67e7
Changes in the content of the build details
4621e76
Gitlab Integration
d1b7c8c
Code cleanup
928e0d5
Specs and code cleanup
a9c5816
Code Cleanup & Refactoring
1ffd473
Added specs and threshold option
e662df3
Refactoring compare module
920fe15
Code cleanup
6662c81
Options and compare changes
7ff1634
Fixing the options fetaure spec
d0713e2
Code cleanup and changes
4e32d16
Spec fix
317a3c9
Abort message changes
34d57e9
Adding links in the navbar
58d9ce1
Merge Fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,5 @@ tmp | |
| .idea/ | ||
| .ruby-gemset | ||
| .ruby-version | ||
| .DS_Store | ||
| *.DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module RubyCritic | ||
| class AnalysisSummary | ||
| def self.generate(analysed_modules) | ||
| new(analysed_modules).generate | ||
| end | ||
|
|
||
| def initialize(analysed_modules) | ||
| @analysed_modules = analysed_modules | ||
| end | ||
|
|
||
| def generate | ||
| %w(A B C D F).each_with_object({}) do |rating, summary| | ||
| summary[rating] = generate_for(rating) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :analysed_modules, :modules | ||
|
|
||
| def generate_for(rating) | ||
| @modules = analysed_modules.for_rating(rating) | ||
| { | ||
| files: modules.count, | ||
| churns: churns, | ||
| smells: smells | ||
| } | ||
| end | ||
|
|
||
| def churns | ||
| modules.inject(0) { |acc, elem| acc + elem.churn } | ||
| end | ||
|
|
||
| def smells | ||
| modules.inject(0) { |acc, elem| acc + elem.smells.count } | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # frozen_string_literal: true | ||
| require 'rubycritic/source_control_systems/base' | ||
| require 'rubycritic/analysers_runner' | ||
| require 'rubycritic/revision_comparator' | ||
| require 'rubycritic/reporter' | ||
| require 'rubycritic/commands/base' | ||
| require 'rubycritic/commands/default' | ||
|
|
||
| module RubyCritic | ||
| module Command | ||
| class Compare < Default | ||
| def initialize(options) | ||
| super | ||
| end | ||
|
|
||
| def execute | ||
| Config.no_browser = true | ||
| compare_branches | ||
| status_reporter.score = Config.feature_branch_score | ||
| status_reporter | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :paths, :status_reporter | ||
|
|
||
| def compare_branches | ||
| update_build_number | ||
| set_root_paths | ||
| analyse_branch(:base_branch) | ||
| analyse_branch(:feature_branch) | ||
| analyse_modified_files | ||
| compare_code_quality | ||
| end | ||
|
|
||
| # keep track of the number of builds and | ||
| # use this build number to create seperate directory for each build | ||
| def update_build_number | ||
| build_file_location = '/tmp/build_count.txt' | ||
| File.new(build_file_location, 'a') unless File.exist?(build_file_location) | ||
| @number = File.open(build_file_location).readlines.first.to_i + 1 | ||
| File.write(build_file_location, @number) | ||
| end | ||
|
|
||
| def set_root_paths | ||
| Config.base_root_directory = Pathname.new(branch_directory(:base_branch)) | ||
| Config.feature_root_directory = Pathname.new(branch_directory(:feature_branch)) | ||
| Config.build_root_directory = Pathname.new(build_directory) | ||
| end | ||
|
|
||
| # switch branch and analyse files | ||
| def analyse_branch(branch) | ||
| SourceControlSystem::Git.switch_branch(Config.send(branch)) | ||
| critic = critique(branch) | ||
| Config.send(:"#{branch}_score=", critic.score) | ||
| Config.root = branch_directory(branch) | ||
| report(critic) | ||
| end | ||
|
|
||
| # generate report only for modified files | ||
| def analyse_modified_files | ||
| Config.no_browser = false | ||
| defected_modules = Config.feature_branch_collection.where(modified_files) | ||
| analysed_modules = AnalysedModulesCollection.new(defected_modules.map(&:path), defected_modules) | ||
| Config.root = build_directory | ||
| report(analysed_modules) | ||
| end | ||
|
|
||
| def compare_code_quality | ||
| build_details | ||
| compare_threshold | ||
| end | ||
|
|
||
| # mark build as failed if the diff b/w the score of | ||
| # two branches is greater than threshold value | ||
| def compare_threshold | ||
| if mark_build_fail? | ||
| print("Threshold: #{Config.threshold_score}\n") | ||
| print("Difference: #{(Config.base_branch_score - Config.feature_branch_score).abs}\n") | ||
| abort('The score difference between the two branches is over the threshold.') | ||
| end | ||
| end | ||
|
|
||
| def mark_build_fail? | ||
| threshold_values_set? && threshold_reached? | ||
| end | ||
|
|
||
| def threshold_values_set? | ||
| Config.threshold_score > 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix this |
||
| end | ||
|
|
||
| def threshold_reached? | ||
| (Config.base_branch_score - Config.feature_branch_score).abs > Config.threshold_score | ||
| end | ||
|
|
||
| def branch_directory(branch) | ||
| "tmp/rubycritic/compare/#{Config.send(branch)}" | ||
| end | ||
|
|
||
| def build_directory | ||
| "tmp/rubycritic/compare/builds/build_#{@number}" | ||
| end | ||
|
|
||
| # create a txt file with the branch score details | ||
| def build_details | ||
| details = "Base branch (#{Config.base_branch}) score: #{Config.base_branch_score.to_s} \n"\ | ||
| "Feature branch (#{Config.feature_branch}) score: #{Config.feature_branch_score.to_s} \n" | ||
| File.open("#{Config.build_root_directory}/build_details.txt", 'w') { |file| file.write(details) } | ||
| end | ||
|
|
||
| # get the modified files in the feature branch | ||
| def modified_files | ||
| modified_files = SourceControlSystem::Git.modified_files | ||
| modified_files.split("\n").map do |line| | ||
| next if line.start_with?('D') | ||
| status, file_name = line.split("\t") | ||
| file_name | ||
| end.compact | ||
| end | ||
|
|
||
| # store the analysed moduled collection based on the branch | ||
| def critique(branch) | ||
| module_collection = AnalysersRunner.new(paths).run | ||
| Config.send(:"#{branch}_collection=", module_collection) | ||
| RevisionComparator.new(paths).set_statuses(module_collection) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention the use of this count file as a comment above the method.