File tree Expand file tree Collapse file tree 5 files changed +12
-40
lines changed Expand file tree Collapse file tree 5 files changed +12
-40
lines changed Original file line number Diff line number Diff line change 7
7
8
8
gem "colorize"
9
9
gem "json"
10
+ gem "pry"
10
11
gem "rake" , "~> 13.0"
11
12
gem "rest-client"
12
13
gem "rspec" , "~> 3.0"
13
14
gem "rubocop" , "~> 1.21"
14
- gem "pry"
Original file line number Diff line number Diff line change @@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
26
26
spec . require_paths = [ "lib" ]
27
27
28
28
# Uncomment to register a new dependency of your gem
29
+ spec . add_dependency ( "colorize" )
29
30
spec . add_dependency ( "json" )
30
31
spec . add_dependency ( "optparse" )
31
32
spec . add_dependency ( "rest-client" )
32
- spec . add_dependency ( "colorize" )
33
33
34
34
# For more information and examples about making a new gem, check out our
35
35
# guide at: https://bundler.io/guides/creating_gem.html
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require_relative "codeclimate_diff/version"
4
+ require "yaml"
4
5
5
6
module CodeclimateDiff
6
- class Configuration
7
- attr_accessor :gitlab ,
8
- :github
9
-
10
- def initialize
11
- @gitlab = {
12
- main_branch_name : "main" ,
13
- download_baseline_from_pipeline : false ,
14
- project_id : nil ,
15
- host : nil ,
16
- personal_access_token : nil
17
- }
18
-
19
- @github = {
20
- # TODO: Add GitHub requirements
21
- }
22
- end
23
- end
24
-
25
7
class << self
26
8
def configuration
27
- @configuration ||= Configuration . new
28
- end
29
-
30
- def configure
31
- yield ( configuration )
9
+ YAML . load_file ( "./.codeclimate_diff.yml" )
32
10
end
33
11
end
34
12
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "rest-client"
4
- require "yaml"
5
4
6
5
module CodeclimateDiff
7
6
class Downloader
8
-
9
7
def self . refresh_baseline_if_configured
10
-
11
- config = YAML . load_file ( "./.codeclimate_diff.yml" )
12
-
13
- puts config
14
-
15
- should_download = config [ 'gitlab' ] [ 'download_baseline_for_pipeline' ]
8
+ should_download = CodeclimateDiff . configuration [ "gitlab" ] [ "download_baseline_for_pipeline" ]
16
9
return unless should_download
17
10
18
- puts "downloading baseline file from gitlab"
19
- branch_name = config [ ' gitlab' ] [ ' main_branch_name' ]
20
- project_id = config [ ' gitlab' ] [ ' project_id' ]
21
- host = config [ ' gitlab' ] [ ' host' ]
22
- personal_access_token = config [ ' gitlab' ] [ ' personal_access_token' ]
11
+ puts "Downloading baseline file from gitlab"
12
+ branch_name = CodeclimateDiff . configuration [ " gitlab" ] [ " main_branch_name" ]
13
+ project_id = CodeclimateDiff . configuration [ " gitlab" ] [ " project_id" ]
14
+ host = CodeclimateDiff . configuration [ " gitlab" ] [ " host" ]
15
+ personal_access_token = CodeclimateDiff . configuration [ " gitlab" ] [ " personal_access_token" ]
23
16
24
17
# 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"
25
18
url = "#{ host } /api/v4/projects/#{ project_id } /jobs/artifacts/#{ branch_name } /raw/codeclimate_diff_baseline.json?job=code_quality"
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ module CodeclimateDiff
11
11
class Runner
12
12
def self . calculate_changed_filenames ( pattern )
13
13
extra_grep_filter = pattern ? " | grep '#{ pattern } '" : ""
14
- files_changed = `git diff --name-only main | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{ extra_grep_filter } `
14
+ branch_name = CodeclimateDiff . configuration [ "gitlab" ] [ "main_branch_name" ]
15
+ files_changed = `git diff --name-only #{ branch_name } | grep --invert-match spec/ | grep --extended-regexp '.js$|.rb$'#{ extra_grep_filter } `
15
16
files_changed . split ( "\n " )
16
17
end
17
18
You can’t perform that action at this time.
0 commit comments