diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2017-03-07 10:36:42 +0100 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2017-03-10 21:08:21 +0100 |
commit | 9b53cb6c88f406c947df24debcba0f87c66cbfcf (patch) | |
tree | 8874710fb35b8830d500bd68e408d7b05faf34ad | |
parent | c4ba6ea684052ff555e8683c23be5b25bf5abd11 (diff) | |
download | gitlab-ce-9b53cb6c88f406c947df24debcba0f87c66cbfcf.tar.gz |
Fix GitHub Import for open PRs from a fork
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/github_import/pull_request_formatter.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/github_import/pull_request_formatter_spec.rb | 24 |
3 files changed, 37 insertions, 1 deletions
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index dc73cad93a5..055a07781a5 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -148,7 +148,7 @@ module Gitlab rescue => e errors << { type: :pull_request, url: Gitlab::UrlSanitizer.sanitize(gh_pull_request.url), errors: e.message } ensure - clean_up_restored_branches(gh_pull_request) + clean_up_restored_branches(gh_pull_request) unless gh_pull_request.opened? end end end diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb index 28812fd0cb9..0a31e3888bd 100644 --- a/lib/gitlab/github_import/pull_request_formatter.rb +++ b/lib/gitlab/github_import/pull_request_formatter.rb @@ -60,6 +60,18 @@ module Gitlab source_branch.repo.id != target_branch.repo.id end + def opened? + state == 'opened' + end + + def closed? + state == 'closed' + end + + def merged? + state == 'merged' + end + private def state diff --git a/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb b/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb index 951cbea7857..af7ed3658a9 100644 --- a/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb +++ b/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb @@ -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' 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 |