Class: CIAgainst::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_against/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo, github_access_token:) ⇒ Runner

repo: owner/repo



4
5
6
7
# File 'lib/ci_against/runner.rb', line 4

def initialize(repo, github_access_token:)
  @repo = repo
  @octokit = Octokit::Client.new(access_token: github_access_token)
end

Instance Method Details

#run(dry_run:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ci_against/runner.rb', line 9

def run(dry_run:)
  begin
    content = Base64.decode64(octokit.contents(@repo, path: '.travis.yml').content)
  rescue Octokit::NotFound
    log ".travis.yml does not exist in #{@repo}"
    return
  end
  if exist_file?('.ruby-version')
    log ".ruby-version exists in #{@repo}. So skipped." 
    return
  end
  converter = Converter.new(content)
  new_content = converter.convert
  if new_content == content
    log "No difference. Skipped"
    return
  end

  if dry_run
    display_diff(content, new_content, log: converter.log)
  else
    create_pull_request(new_content, log: converter.log)
  end
end