Skip to content

Commit 235804f

Browse files
Merge pull request #3 from boost/skip-cli-wrapper-dependency
Skip cli wrapper dependency
2 parents 550679f + a991c7b commit 235804f

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
codeclimate_diff (0.1.4)
4+
codeclimate_diff (0.1.5)
55
colorize
66
json
77
optparse

README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
99

1010
## Installation
1111

12-
1. Install the codeclimate cli:
13-
```bash
14-
brew tap codeclimate/formulae
15-
brew install codeclimate
16-
```
12+
1. Make sure docker is installed and running
1713

1814
2. Add a `.codeclimate.yml` config file eg:
1915
```yml
@@ -90,7 +86,7 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
9086

9187
4. Add a `.codecimate_diff.yml` configuration file
9288
```
93-
main_branch_name: main # defaults to main
89+
main_branch_name: master # defaults to main
9490
```
9591
9692
5. Install the gem

lib/codeclimate_diff/codeclimate_wrapper.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
module CodeclimateDiff
77
class CodeclimateWrapper
88
def run_codeclimate(filename = "")
9-
`codeclimate analyze -f json #{filename}`
9+
`docker run \
10+
--interactive --tty --rm \
11+
--env CODECLIMATE_CODE="$PWD" \
12+
--volume "$PWD":/code \
13+
--volume /var/run/docker.sock:/var/run/docker.sock \
14+
--volume /tmp/cc:/tmp/cc \
15+
codeclimate/codeclimate analyze -f json #{filename}`
16+
end
17+
18+
def pull_latest_image
19+
puts "Downloading latest codeclimate docker image..."
20+
`docker pull codeclimate/codeclimate`
1021
end
1122
end
1223
end

lib/codeclimate_diff/runner.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ def self.calculate_changed_filenames(pattern)
1313
extra_grep_filter = pattern ? " | grep '#{pattern}'" : ""
1414
branch_name = CodeclimateDiff.configuration["main_branch_name"] || "main"
1515
files_changed_str = `git diff --name-only #{branch_name} | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
16-
puts "Files changed on branch: #{files_changed_str}"
17-
1816
files_changed_str.split("\n")
1917
end
2018

@@ -46,13 +44,17 @@ def self.calculate_preexisting_issues_in_changed_files(changed_filenames)
4644
end
4745

4846
def self.generate_baseline
47+
CodeclimateWrapper.new.pull_latest_image
48+
4949
puts "Generating the baseline. Should take about 5 minutes..."
5050
result = CodeclimateWrapper.new.run_codeclimate
5151
File.write("codeclimate_diff_baseline.json", result)
5252
puts "Done!"
5353
end
5454

5555
def self.run_diff_on_branch(pattern, show_preexisting: true)
56+
CodeclimateWrapper.new.pull_latest_image
57+
5658
changed_filenames = calculate_changed_filenames(pattern)
5759

5860
changed_file_issues = calculate_issues_in_changed_files(changed_filenames)

lib/codeclimate_diff/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CodeclimateDiff
4-
VERSION = "0.1.4"
4+
VERSION = "0.1.5"
55
end

0 commit comments

Comments
 (0)