Skip to content

Commit b4438cb

Browse files
feat: reads branch name for all the code
1 parent 7b83dfb commit b4438cb

File tree

5 files changed

+12
-40
lines changed

5 files changed

+12
-40
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ gemspec
77

88
gem "colorize"
99
gem "json"
10+
gem "pry"
1011
gem "rake", "~> 13.0"
1112
gem "rest-client"
1213
gem "rspec", "~> 3.0"
1314
gem "rubocop", "~> 1.21"
14-
gem "pry"

codeclimate_diff.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Gem::Specification.new do |spec|
2626
spec.require_paths = ["lib"]
2727

2828
# Uncomment to register a new dependency of your gem
29+
spec.add_dependency("colorize")
2930
spec.add_dependency("json")
3031
spec.add_dependency("optparse")
3132
spec.add_dependency("rest-client")
32-
spec.add_dependency("colorize")
3333

3434
# For more information and examples about making a new gem, check out our
3535
# guide at: https://bundler.io/guides/creating_gem.html

lib/codeclimate_diff.rb

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
# frozen_string_literal: true
22

33
require_relative "codeclimate_diff/version"
4+
require "yaml"
45

56
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-
257
class << self
268
def configuration
27-
@configuration ||= Configuration.new
28-
end
29-
30-
def configure
31-
yield(configuration)
9+
YAML.load_file("./.codeclimate_diff.yml")
3210
end
3311
end
3412
end

lib/codeclimate_diff/downloader.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
# frozen_string_literal: true
22

33
require "rest-client"
4-
require "yaml"
54

65
module CodeclimateDiff
76
class Downloader
8-
97
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"]
169
return unless should_download
1710

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"]
2316

2417
# 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"
2518
url = "#{host}/api/v4/projects/#{project_id}/jobs/artifacts/#{branch_name}/raw/codeclimate_diff_baseline.json?job=code_quality"

lib/codeclimate_diff/runner.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module CodeclimateDiff
1111
class Runner
1212
def self.calculate_changed_filenames(pattern)
1313
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}`
1516
files_changed.split("\n")
1617
end
1718

0 commit comments

Comments
 (0)