Skip to content

Skip cli wrapper dependency #3

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

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
codeclimate_diff (0.1.4)
codeclimate_diff (0.1.5)
colorize
json
optparse
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ NOTE: similar code will only work correctly if you run a diff on all the files i

## Installation

1. Install the codeclimate cli:
```bash
brew tap codeclimate/formulae
brew install codeclimate
```
1. Make sure docker is installed and running

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

4. Add a `.codecimate_diff.yml` configuration file
```
main_branch_name: main # defaults to main
main_branch_name: master # defaults to main
```

5. Install the gem
Expand Down
13 changes: 12 additions & 1 deletion lib/codeclimate_diff/codeclimate_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
module CodeclimateDiff
class CodeclimateWrapper
def run_codeclimate(filename = "")
`codeclimate analyze -f json #{filename}`
`docker run \
--interactive --tty --rm \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze -f json #{filename}`
end

def pull_latest_image
puts "Downloading latest codeclimate docker image..."
`docker pull codeclimate/codeclimate`
end
end
end
6 changes: 4 additions & 2 deletions lib/codeclimate_diff/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def self.calculate_changed_filenames(pattern)
extra_grep_filter = pattern ? " | grep '#{pattern}'" : ""
branch_name = CodeclimateDiff.configuration["main_branch_name"] || "main"
files_changed_str = `git diff --name-only #{branch_name} | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{extra_grep_filter}`
puts "Files changed on branch: #{files_changed_str}"

files_changed_str.split("\n")
end

Expand Down Expand Up @@ -46,13 +44,17 @@ def self.calculate_preexisting_issues_in_changed_files(changed_filenames)
end

def self.generate_baseline
CodeclimateWrapper.new.pull_latest_image

puts "Generating the baseline. Should take about 5 minutes..."
result = CodeclimateWrapper.new.run_codeclimate
File.write("codeclimate_diff_baseline.json", result)
puts "Done!"
end

def self.run_diff_on_branch(pattern, show_preexisting: true)
CodeclimateWrapper.new.pull_latest_image

changed_filenames = calculate_changed_filenames(pattern)

changed_file_issues = calculate_issues_in_changed_files(changed_filenames)
Expand Down
2 changes: 1 addition & 1 deletion lib/codeclimate_diff/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CodeclimateDiff
VERSION = "0.1.4"
VERSION = "0.1.5"
end