Skip to content

Commit 550679f

Browse files
Merge pull request #2 from boost/first-usable-version
First usable version
2 parents c7e26a7 + f94a6e2 commit 550679f

File tree

5 files changed

+90
-28
lines changed

5 files changed

+90
-28
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.3)
4+
codeclimate_diff (0.1.4)
55
colorize
66
json
77
optparse

README.md

+84-22
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
1010
## Installation
1111

1212
1. Install the codeclimate cli:
13-
```
13+
```bash
1414
brew tap codeclimate/formulae
1515
brew install codeclimate
1616
```
1717

1818
2. Add a `.codeclimate.yml` config file eg:
19-
```
19+
```yml
2020
---
2121
version: "2"
2222
plugins:
@@ -46,10 +46,54 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
4646
- "**/__tests__/"
4747
- "**/__mocks__/"
4848
- "/.gitlab/"
49-
- coverage/
49+
- coverage/ . # simple cov
50+
```
51+
52+
3. Add a `.reek.yml` config file eg:
53+
54+
See https://github.com/troessner/reek#working-with-rails
55+
```yml
56+
detectors:
57+
IrresponsibleModule:
58+
enabled: false
59+
60+
LongParameterList:
61+
max_params: 4 # defaults to 3. You want this number realistic but stretchy so we can move it down
62+
63+
TooManyStatements:
64+
max_statements: 10 # defaults to 5. You want this number realistic but stretchy so we can move it down
65+
66+
directories:
67+
"app/controllers":
68+
IrresponsibleModule:
69+
enabled: false
70+
NestedIterators:
71+
max_allowed_nesting: 2
72+
UnusedPrivateMethod:
73+
enabled: false
74+
InstanceVariableAssumption:
75+
enabled: false
76+
"app/helpers":
77+
IrresponsibleModule:
78+
enabled: false
79+
UtilityFunction:
80+
enabled: false
81+
FeatureEnvy:
82+
enabled: false
83+
"app/mailers":
84+
InstanceVariableAssumption:
85+
enabled: false
86+
"app/models":
87+
InstanceVariableAssumption:
88+
enabled: false
89+
```
90+
91+
4. Add a `.codecimate_diff.yml` configuration file
92+
```
93+
main_branch_name: main # defaults to main
5094
```
5195

52-
3. Install the gem
96+
5. Install the gem
5397

5498
Add this line to your application's Gemfile:
5599
@@ -61,17 +105,14 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
61105
62106
```bash
63107
$ bundle install
64-
65-
# OR just install it locally
66-
$ gem install codeclimate_diff
67108
```
68109
69110
Then generate the executable:
70111
71112
$ bundle binstubs codeclimate_diff
72113
73114
74-
4. Run the baseline and commit the result to the repo
115+
6. Run the baseline and commit the result to the repo
75116
76117
```
77118
./bin/codeclimate_diff --baseline
@@ -83,9 +124,9 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
83124
84125
2. Do some work
85126
86-
3. Check if you've added any issues (about 10 secs per code file changed on your branch)
127+
3. Check if you've added any issues (about 10 secs per code file changed on your branch):
87128

88-
```
129+
```bash
89130
# runs on all code files changed in your branch
90131
./bin/codeclimate_diff
91132
@@ -99,22 +140,43 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
99140
# only shows the new and fixed issues
100141
./bin/codeclimate_diff --new-only
101142
```
102-
4. Now you have time to fix the issues yay!
103143

104-
## Configuration
144+
4. Now you have time to fix the issues, horray!
145+
105146

106-
Example:
147+
## Setting it up to download the latest baseline from your CI Pipeline (Gitlab only)
148+
149+
Gitlab has a codeclimate template you can add to your pipeline that runs on main builds and then runs on your branch and outputs a difference (see https://docs.gitlab.com/ee/ci/testing/code_quality.html).
150+
151+
With a few tweaks to your CI configuration, we can pull down the main build baseline from the job so we don't have to do it locally.
152+
153+
1. In your Gitlab CI Configuration where you include the `Code-Quality.gitlab-ci.yml` template:
154+
155+
```yml
156+
include:
157+
- template: Code-Quality.gitlab-ci.yml
158+
159+
# add this bit:
160+
code_quality:
161+
artifacts:
162+
paths: [gl-code-quality-report.json] . # without this, the artifact can't be downloaded
163+
```
164+
165+
2. Add your project settings to the `.codecimate_diff.yml` configuration file:
166+
```yml
167+
main_branch_name: main
168+
169+
# settings to pull down the baseline from the pipeline in Gitlab before checking your branch
170+
gitlab:
171+
download_baseline_from_pipeline: true # If false or excluded, you will need to generate the baseline manually
172+
project_id: '<project id>'
173+
host: https://gitlab.digitalnz.org/
174+
baseline_filename: 'gl-code-quality-report.json'
175+
```
107176

108-
.codeclimate_diff.yml
177+
3. Create a personal access token with `read_api` access and save it in the `CODECLIMATE_DIFF_GITLAB_PERSONAL_ACCESS_TOKEN` env variable
109178

110-
```rb
111-
gitlab:
112-
main_branch_name: main
113-
download_baseline_for_pipeline: true
114-
project_id: '..'
115-
host: https://gitlab.digitalnz.org/
116-
personal_access_token: <LOAD FROM ENV VARIABLE>
117-
```
179+
Now when you run it on the changed files in your branch, it will refresh the baseline first!
118180

119181
## Development
120182

lib/codeclimate_diff/downloader.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
module CodeclimateDiff
66
class Downloader
77
def self.refresh_baseline_if_configured
8-
should_download = CodeclimateDiff.configuration["gitlab"]["download_baseline_for_pipeline"]
9-
return unless should_download
8+
return unless CodeclimateDiff.configuration["gitlab"]
9+
return unless CodeclimateDiff.configuration["gitlab"]["download_baseline_from_pipeline"]
1010

1111
puts "Downloading baseline file from gitlab"
12-
branch_name = CodeclimateDiff.configuration["main_branch_name"]
12+
branch_name = CodeclimateDiff.configuration["main_branch_name"] || "main"
1313
project_id = CodeclimateDiff.configuration["gitlab"]["project_id"]
1414
host = CodeclimateDiff.configuration["gitlab"]["host"]
1515
baseline_filename = CodeclimateDiff.configuration["gitlab"]["baseline_filename"]

lib/codeclimate_diff/runner.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module CodeclimateDiff
1111
class Runner
1212
def self.calculate_changed_filenames(pattern)
1313
extra_grep_filter = pattern ? " | grep '#{pattern}'" : ""
14-
branch_name = CodeclimateDiff.configuration["main_branch_name"]
14+
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}`
1616
puts "Files changed on branch: #{files_changed_str}"
1717

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.3"
4+
VERSION = "0.1.4"
55
end

0 commit comments

Comments
 (0)