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
+44-19
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:
@@ -52,7 +52,7 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
52
52
3. Add a `.reek.yml` config file eg:
53
53
54
54
See https://github.com/troessner/reek#working-with-rails
55
-
```
55
+
```yml
56
56
detectors:
57
57
IrresponsibleModule:
58
58
enabled: false
@@ -90,18 +90,10 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
90
90
91
91
4. Add a `.codecimate_diff.yml` configuration file
92
92
```
93
-
main_branch_name: main
94
-
95
-
# settings to pull down the baseline from the pipeline in Gitlab before checking your branch
96
-
gitlab:
97
-
download_baseline_from_pipeline: true # If false or excluded, you will need to generate the baseline manually
98
-
project_id: '85'
99
-
host: https://gitlab.digitalnz.org/
100
-
baseline_filename: 'gl-code-quality-report.json'
93
+
main_branch_name: main # defaults to main
101
94
```
102
95
103
-
104
-
4. Install the gem
96
+
5. Install the gem
105
97
106
98
Add this line to your application's Gemfile:
107
99
@@ -113,17 +105,14 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
113
105
114
106
```bash
115
107
$ bundle install
116
-
117
-
# OR just install it locally
118
-
$ gem install codeclimate_diff
119
108
```
120
109
121
110
Then generate the executable:
122
111
123
112
$ bundle binstubs codeclimate_diff
124
113
125
114
126
-
4. Run the baseline and commit the result to the repo
115
+
6. Run the baseline and commit the result to the repo
127
116
128
117
```
129
118
./bin/codeclimate_diff --baseline
@@ -137,7 +126,7 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
137
126
138
127
3. Check if you've added any issues (about 10 secs per code file changed on your branch):
139
128
140
-
```
129
+
```bash
141
130
# runs on all code files changed in your branch
142
131
./bin/codeclimate_diff
143
132
@@ -151,7 +140,43 @@ NOTE: similar code will only work correctly if you run a diff on all the files i
151
140
# only shows the new and fixed issues
152
141
./bin/codeclimate_diff --new-only
153
142
```
154
-
4. Now you have time to fix the issues yay!
143
+
144
+
4. Now you have time to fix the issues, horray!
145
+
146
+
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
+
```
176
+
177
+
3. Create a personal access token with `read_api` access and save it in the `CODECLIMATE_DIFF_GITLAB_PERSONAL_ACCESS_TOKEN` env variable
178
+
179
+
Now when you run it on the changed files in your branch, it will refresh the baseline first!
0 commit comments