Commit 9b53cb6c authored by Gabriel Mazetto's avatar Gabriel Mazetto

Fix GitHub Import for open PRs from a fork

parent c4ba6ea6
...@@ -148,7 +148,7 @@ module Gitlab ...@@ -148,7 +148,7 @@ module Gitlab
rescue => e rescue => e
errors << { type: :pull_request, url: Gitlab::UrlSanitizer.sanitize(gh_pull_request.url), errors: e.message } errors << { type: :pull_request, url: Gitlab::UrlSanitizer.sanitize(gh_pull_request.url), errors: e.message }
ensure ensure
clean_up_restored_branches(gh_pull_request) clean_up_restored_branches(gh_pull_request) unless gh_pull_request.opened?
end end
end end
end end
......
...@@ -60,6 +60,18 @@ module Gitlab ...@@ -60,6 +60,18 @@ module Gitlab
source_branch.repo.id != target_branch.repo.id source_branch.repo.id != target_branch.repo.id
end end
def opened?
state == 'opened'
end
def closed?
state == 'closed'
end
def merged?
state == 'merged'
end
private private
def state def state
......
...@@ -306,4 +306,28 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -306,4 +306,28 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
expect(pull_request.url).to eq 'https://api.github.com/repos/octocat/Hello-World/pulls/1347' expect(pull_request.url).to eq 'https://api.github.com/repos/octocat/Hello-World/pulls/1347'
end end
end end
describe '#opened?' do
let(:raw_data) { double(base_data.merge(state: 'open')) }
it 'returns true when state is "open"' do
expect(pull_request.opened?).to be_truthy
end
end
describe '#closed?' do
let(:raw_data) { double(base_data.merge(state: 'closed')) }
it 'returns true when state is "closed"' do
expect(pull_request.closed?).to be_truthy
end
end
describe '#merged?' do
let(:raw_data) { double(base_data.merge(state: 'closed', merged_at: Date.today)) }
it 'returns true when state is "closed" and merged_at is set' do
expect(pull_request.merged?).to be_truthy
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment