Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When HEAD is detached find GitHub PR by SHA #247

Merged
merged 2 commits into from
Jul 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Find PRs when checked out by commit
  • Loading branch information
drewish committed Jun 16, 2017
commit 0076a6be26819b898b128f662dd69d44d3e48a85
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: ['[email protected]:prontolabs/pronto.git'], branch: nil)
double(remote_urls: ['[email protected]: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