You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-22
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
10
10
## Installation
11
11
12
12
1. Install the codeclimate cli:
13
-
```
13
+
```bash
14
14
brew tap codeclimate/formulae
15
15
brew install codeclimate
16
16
```
17
17
18
18
2. Add a `.codeclimate.yml` config file eg:
19
-
```
19
+
```yml
20
20
---
21
21
version: "2"
22
22
plugins:
@@ -46,10 +46,54 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
46
46
- "**/__tests__/"
47
47
- "**/__mocks__/"
48
48
- "/.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
50
94
```
51
95
52
-
3. Install the gem
96
+
5. Install the gem
53
97
54
98
Add this line to your application's Gemfile:
55
99
@@ -61,17 +105,14 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
61
105
62
106
```bash
63
107
$ bundle install
64
-
65
-
# OR just install it locally
66
-
$ gem install codeclimate_diff
67
108
```
68
109
69
110
Then generate the executable:
70
111
71
112
$ bundle binstubs codeclimate_diff
72
113
73
114
74
-
4. Run the baseline and commit the result to the repo
115
+
6. Run the baseline and commit the result to the repo
75
116
76
117
```
77
118
./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
83
124
84
125
2. Do some work
85
126
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):
87
128
88
-
```
129
+
```bash
89
130
# runs on all code files changed in your branch
90
131
./bin/codeclimate_diff
91
132
@@ -99,22 +140,43 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
99
140
# only shows the new and fixed issues
100
141
./bin/codeclimate_diff --new-only
101
142
```
102
-
4. Now you have time to fix the issues yay!
103
143
104
-
## Configuration
144
+
4. Now you have time to fix the issues, horray!
145
+
105
146
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
+
```
107
176
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
109
178
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!
0 commit comments