Skip to content

Commit

Permalink
Extract Pronto::Github to be used by multiple formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed Sep 10, 2014
1 parent b5f80b6 commit fbf8d76
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rugged'
require 'octokit'
require 'forwardable'

require 'pronto/git/repository'
Expand All @@ -10,6 +11,7 @@
require 'pronto/plugin'
require 'pronto/message'
require 'pronto/runner'
require 'pronto/github'

require 'pronto/formatter/text_formatter'
require 'pronto/formatter/json_formatter'
Expand Down
8 changes: 1 addition & 7 deletions lib/pronto/formatter/github_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'octokit'

module Pronto
module Formatter
class GithubFormatter
Expand Down Expand Up @@ -33,12 +31,8 @@ def create_comment(repo, sha, position, path, body)
end
end

def access_token
ENV['GITHUB_ACCESS_TOKEN']
end

def client
@client ||= Octokit::Client.new(access_token: access_token)
@client ||= Github.new
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Pronto
class Github
extend Forwardable

def_delegators :client, :commit_comments, :create_commit_comment

private

def client
@client ||= Octokit::Client.new(access_token: access_token)
end

def access_token
ENV['GITHUB_ACCESS_TOKEN']
end
end
end
1 change: 0 additions & 1 deletion lib/pronto/rake_task/travis_pull_request.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'pronto'
require 'octokit'
require 'rake'
require 'rake/tasklib'

Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/formatter/github_formattter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Formatter
describe '#format' do
subject { github_formatter.format(messages, repository) }
let(:messages) { [message, message] }
let(:repository) { Pronto::Git::Repository.new('.') }
let(:repository) { Git::Repository.new('.') }
let(:message) { Message.new('path/to', line, :warning, 'crucial') }
let(:line) { double(new_lineno: 1, commit_sha: '123', position: nil) }
before { line.stub(:commit_line).and_return(line) }
Expand Down

0 comments on commit fbf8d76

Please sign in to comment.