Skip to content

Commit 17cd541

Browse files
feat: we now use the docker image directly so people don't have to install a CLI package
1 parent 550679f commit 17cd541

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.md

Lines changed: 2 additions & 6 deletions
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

Lines changed: 12 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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)

0 commit comments

Comments
 (0)