File tree Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Expand file tree Collapse file tree 3 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -120,15 +120,12 @@ It runs the https://hub.docker.com/r/codeclimate/codeclimate docker image under
120120 $ bundle binstubs codeclimate_diff
121121
122122
123- 6. Run the baseline and commit the result to the repo
123+ Add codeclimate_diff_baseline.json to .gitignore
124124
125- ```
126- ./bin/codeclimate_diff --baseline
127- ```
128125
129126# # Usage
130127
131- 1. Create a feature branch for your work, and reset the baseline + commit (5 mins)
128+ 1. Create a feature branch for your work
132129
1331302. Do some work
134131
@@ -137,7 +134,7 @@ It runs the https://hub.docker.com/r/codeclimate/codeclimate docker image under
137134 ` ` ` bash
138135 # runs on each file changed in your branch (about 10 secs per code file changed on your branch)
139136 ./bin/codeclimate_diff
140-
137+ # baseline is now generated on first run, to generate new baseline, delete the existing.
141138 OR
142139
143140 # filters the changed files in your branch futher by a grep pattern
Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ OptionParser.new do |opts|
2323 "Grep pattern to filter files. If provided, will filter the files changed on your branch further." )
2424end . parse! ( into : options )
2525
26- if options [ :baseline ]
27- CodeclimateDiff ::Runner . generate_baseline
28- elsif options [ :"new-only" ]
29- CodeclimateDiff ::Runner . run_diff_on_branch ( options [ :pattern ] , always_analyze_all_files : options [ :all ] , show_preexisting : false )
26+ if options [ :"new-only" ]
27+ CodeclimateDiff ::Runner . run_diff_on_branch ( options [ :pattern ] , always_analyze_all_files : options [ :all ] ,
28+ show_preexisting : false )
3029else
31- CodeclimateDiff ::Runner . run_diff_on_branch ( options [ :pattern ] , always_analyze_all_files : options [ :all ] , show_preexisting : true )
30+ CodeclimateDiff ::Runner . run_diff_on_branch ( options [ :pattern ] , always_analyze_all_files : options [ :all ] ,
31+ show_preexisting : true )
3232end
Original file line number Diff line number Diff line change @@ -86,8 +86,27 @@ def self.generate_baseline
8686 puts "Done!"
8787 end
8888
89+ def self . setup_baseline_for_branch
90+ main_branch = CodeclimateDiff . configuration [ "main_branch_name" ] || "main"
91+
92+ project_repo = `basename $(pwd)` . strip
93+
94+ puts "Creating a temp worktree to generate the baseline..."
95+ system ( "git worktree add ../temp-codeclimate #{ main_branch } " )
96+
97+ Dir . chdir ( "../temp-codeclimate" ) do
98+ generate_baseline
99+
100+ puts "Copying the baseline to #{ project_repo } ..."
101+ system ( "cp codeclimate_diff_baseline.json ../#{ project_repo } " )
102+ end
103+
104+ puts ( "Removing the temp worktree..." )
105+ system ( "git worktree remove ../temp-codeclimate" )
106+ end
107+
89108 def self . run_diff_on_branch ( pattern , always_analyze_all_files : false , show_preexisting : true )
90- CodeclimateWrapper . new . pull_latest_image
109+ setup_baseline_for_branch unless File . exist? ( "codeclimate_diff_baseline.json" )
91110
92111 changed_filenames = calculate_changed_filenames ( pattern )
93112
You can’t perform that action at this time.
0 commit comments