File tree Expand file tree Collapse file tree 6 files changed +49
-0
lines changed Expand file tree Collapse file tree 6 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 8
8
gem "colorize"
9
9
gem "json"
10
10
gem "rake" , "~> 13.0"
11
+ gem "rest-client"
11
12
gem "rspec" , "~> 3.0"
12
13
gem "rubocop" , "~> 1.21"
Original file line number Diff line number Diff line change 4
4
codeclimate_diff (0.1.1 )
5
5
json
6
6
optparse
7
+ rest-client
7
8
8
9
GEM
9
10
remote: https://rubygems.org/
10
11
specs:
11
12
ast (2.4.2 )
12
13
colorize (0.8.1 )
13
14
diff-lcs (1.5.0 )
15
+ domain_name (0.5.20190701 )
16
+ unf (>= 0.0.5 , < 1.0.0 )
17
+ http-accept (1.7.0 )
18
+ http-cookie (1.0.5 )
19
+ domain_name (~> 0.5 )
14
20
json (2.6.2 )
21
+ mime-types (3.4.1 )
22
+ mime-types-data (~> 3.2015 )
23
+ mime-types-data (3.2022.0105 )
24
+ netrc (0.11.0 )
15
25
optparse (0.2.0 )
16
26
parallel (1.22.1 )
17
27
parser (3.1.2.1 )
18
28
ast (~> 2.4.1 )
19
29
rainbow (3.1.1 )
20
30
rake (13.0.6 )
21
31
regexp_parser (2.6.0 )
32
+ rest-client (2.1.0 )
33
+ http-accept (>= 1.7.0 , < 2.0 )
34
+ http-cookie (>= 1.0.2 , < 2.0 )
35
+ mime-types (>= 1.16 , < 4.0 )
36
+ netrc (~> 0.8 )
22
37
rexml (3.2.5 )
23
38
rspec (3.11.0 )
24
39
rspec-core (~> 3.11.0 )
46
61
rubocop-ast (1.22.0 )
47
62
parser (>= 3.1.1.0 )
48
63
ruby-progressbar (1.11.0 )
64
+ unf (0.1.4 )
65
+ unf_ext
66
+ unf_ext (0.0.8.2 )
49
67
unicode-display_width (2.3.0 )
50
68
51
69
PLATFORMS
@@ -57,6 +75,7 @@ DEPENDENCIES
57
75
colorize
58
76
json
59
77
rake (~> 13.0 )
78
+ rest-client
60
79
rspec (~> 3.0 )
61
80
rubocop (~> 1.21 )
62
81
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
# Uncomment to register a new dependency of your gem
29
29
spec . add_dependency ( "json" )
30
30
spec . add_dependency ( "optparse" )
31
+ spec . add_dependency ( "rest-client" )
31
32
32
33
# For more information and examples about making a new gem, check out our
33
34
# guide at: https://bundler.io/guides/creating_gem.html
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Configuration
8
8
def initialize
9
9
@gitlab = {
10
10
main_branch_name : "main" ,
11
+ download_baseline_from_pipeline : false ,
11
12
project_id : nil ,
12
13
host : nil ,
13
14
personal_access_token : nil
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "rest-client"
4
+
5
+ module CodeclimateDiff
6
+ class Downloader
7
+ def self . refresh_baseline_if_configured
8
+ should_download = CodeclimateDiff . configuration . gitlab [ :download_baseline_from_pipeline ]
9
+ return unless should_download
10
+
11
+ branch_name = CodeclimateDiff . configuration . gitlab [ :main_branch_name ]
12
+ project_id = CodeclimateDiff . configuration . gitlab [ :project_id ]
13
+ host = CodeclimateDiff . configuration . gitlab [ :host ]
14
+ personal_access_token = CodeclimateDiff . configuration . gitlab [ :personal_access_token ]
15
+
16
+ # curl --output codeclimate_diff_baseline.json --header "PRIVATE-TOKEN: MYTOKEN" "https://gitlab.digitalnz.org/api/v4/projects/85/jobs/artifacts/main/raw/codeclimate_diff_baseline.json?job=code_quality"
17
+ url = "#{ host } /api/v4/projects/#{ project_id } /jobs/artifacts/#{ branch_name } /raw/codeclimate_diff_baseline.json?job=code_quality"
18
+ response = RestClient . get ( url , { "PRIVATE-TOKEN" : personal_access_token } )
19
+ File . write ( "codeclimate_diff_baseline.json" , response . body )
20
+ rescue StandardError => e
21
+ puts e
22
+ end
23
+ end
24
+ end
Original file line number Diff line number Diff line change 5
5
require_relative "./codeclimate_wrapper"
6
6
require_relative "./result_printer"
7
7
require_relative "./issue_sorter"
8
+ require_relative "./downloader"
8
9
9
10
module CodeclimateDiff
10
11
class Runner
@@ -33,6 +34,8 @@ def self.calculate_issues_in_changed_files(changed_filenames)
33
34
end
34
35
35
36
def self . calculate_preexisting_issues_in_changed_files ( changed_filenames )
37
+ Downloader . refresh_baseline_if_configured
38
+
36
39
puts "Extracting relevant preexisting issues..."
37
40
all_issues = JSON . parse ( File . read ( "./codeclimate_diff_baseline.json" ) )
38
41
You can’t perform that action at this time.
0 commit comments