Skip to content

Commit

Permalink
Merge pull request #247 from drewish/support-detached
Browse files Browse the repository at this point in the history
When HEAD is detached find GitHub PR by SHA
  • Loading branch information
mmozuras authored Jul 15, 2017
2 parents aa344ed + ee18f54 commit e97cb2b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Metrics/BlockLength:
ExcludedMethods: Struct.new
Exclude:
- spec/**/*.rb

Rubocop/Metrics/AbcSize:
Max: 25
4 changes: 4 additions & 0 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def head_commit_sha
head.oid
end

def head_detached?
@repo.head_detached?
end

private

def empty_patches(sha)
Expand Down
4 changes: 4 additions & 0 deletions lib/pronto/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def pull
pull_requests.find { |pr| pr[:number].to_i == env_pull_id }
elsif @repo.branch
pull_requests.find { |pr| pr[:head][:ref] == @repo.branch }
elsif @repo.head_detached?
pull_requests.find do |pr|
pr[:head][:sha] == @repo.head_commit_sha
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/pronto/github_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Pronto
let(:github) { described_class.new(repo) }

let(:repo) do
double(remote_urls: ['git@github.com:prontolabs/pronto.git'], branch: nil)
double(remote_urls: ['git@github.com:prontolabs/pronto.git'], branch: nil, head_detached?: false)
end
let(:sha) { '61e4bef' }
let(:comment) { double(body: 'note', path: 'path', line: 1, position: 1) }
Expand Down

0 comments on commit e97cb2b

Please sign in to comment.