Class: MultiRepo::Service::CodeClimate

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_repo/service/code_climate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, dry_run: false, **_) ⇒ CodeClimate

Returns a new instance of CodeClimate.



37
38
39
40
# File 'lib/multi_repo/service/code_climate.rb', line 37

def initialize(repo, dry_run: false, **_)
  @repo    = repo
  @dry_run = dry_run
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



35
36
37
# File 'lib/multi_repo/service/code_climate.rb', line 35

def dry_run
  @dry_run
end

#repoObject (readonly)

Returns the value of attribute repo.



35
36
37
# File 'lib/multi_repo/service/code_climate.rb', line 35

def repo
  @repo
end

Class Method Details

.api_tokenObject



3
4
5
# File 'lib/multi_repo/service/code_climate.rb', line 3

def self.api_token
  @api_token ||= ENV["CODECLIMATE_API_TOKEN"]
end

.api_token=(token) ⇒ Object



7
8
9
# File 'lib/multi_repo/service/code_climate.rb', line 7

def self.api_token=(token)
  @api_token = token
end

.badge_details(repo) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/multi_repo/service/code_climate.rb', line 15

def self.badge_details(repo)
  {
    "description" => badge_name,
    "image"       => "https://codeclimate.com/github/#{repo.name}.svg",
    "url"         => "https://codeclimate.com/github/#{repo.name}"
  }
end

.badge_nameObject



11
12
13
# File 'lib/multi_repo/service/code_climate.rb', line 11

def self.badge_name
  "Code Climate"
end

.coverage_badge_details(repo) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/multi_repo/service/code_climate.rb', line 27

def self.coverage_badge_details(repo)
  {
    "description" => coverage_badge_name,
    "image"       => "https://codeclimate.com/github/#{repo.name}/badges/coverage.svg",
    "url"         => "https://codeclimate.com/github/#{repo.name}/coverage"
  }
end

.coverage_badge_nameObject



23
24
25
# File 'lib/multi_repo/service/code_climate.rb', line 23

def self.coverage_badge_name
  "Test Coverage"
end

Instance Method Details

#badge_detailsObject



51
52
53
# File 'lib/multi_repo/service/code_climate.rb', line 51

def badge_details
  self.class.badge_details(repo)
end

#coverage_badge_detailsObject



55
56
57
# File 'lib/multi_repo/service/code_climate.rb', line 55

def coverage_badge_details
  self.class.coverage_badge_details(repo)
end

#create_repo_secretObject



64
65
66
# File 'lib/multi_repo/service/code_climate.rb', line 64

def create_repo_secret
  Github.new(dry_run: dry_run).create_or_update_repository_secret(repo.name, "CC_TEST_REPORTER_ID", test_reporter_id)
end

#enableObject



47
48
49
# File 'lib/multi_repo/service/code_climate.rb', line 47

def enable
  ensure_enabled
end

#save!Object



42
43
44
45
# File 'lib/multi_repo/service/code_climate.rb', line 42

def save!
  write_codeclimate_yaml
  write_rubocop_yamls
end

#test_reporter_idObject



59
60
61
62
# File 'lib/multi_repo/service/code_climate.rb', line 59

def test_reporter_id
  ensure_enabled
  @response.dig("data", 0, "attributes", "test_reporter_id")
end