File tree 3 files changed +28
-12
lines changed
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
120
120
$ bundle binstubs codeclimate_diff
121
121
122
122
123
- 6. Run the baseline and commit the result to the repo
123
+ Add codeclimate_diff_baseline.json to .gitignore
124
124
125
- ```
126
- ./bin/codeclimate_diff --baseline
127
- ```
128
125
129
126
# # Usage
130
127
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
132
129
133
130
2. Do some work
134
131
@@ -137,7 +134,7 @@ It runs the https://hub.docker.com/r/codeclimate/codeclimate docker image under
137
134
` ` ` bash
138
135
# runs on each file changed in your branch (about 10 secs per code file changed on your branch)
139
136
./bin/codeclimate_diff
140
-
137
+ # baseline is now generated on first run, to generate new baseline, delete the existing.
141
138
OR
142
139
143
140
# 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|
23
23
"Grep pattern to filter files. If provided, will filter the files changed on your branch further." )
24
24
end . parse! ( into : options )
25
25
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 )
30
29
else
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 )
32
32
end
Original file line number Diff line number Diff line change @@ -86,8 +86,27 @@ def self.generate_baseline
86
86
puts "Done!"
87
87
end
88
88
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
+
89
108
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" )
91
110
92
111
changed_filenames = calculate_changed_filenames ( pattern )
93
112
You can’t perform that action at this time.
0 commit comments