Commit b51e4cb3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix/29093' into 'master'

Fix 'Object not found - no match for id (sha)' when importing GitHub PRs

Closes #29093

See merge request !9751
parents 685e261f 5195999e
---
title: Fix 'Object not found - no match for id (sha)' when importing GitHub Pull Requests
merge_request:
author:
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
end end
def commit_exists? def commit_exists?
project.repository.commit(sha).present? project.repository.branch_names_contains(sha).include?(ref)
end end
def short_id def short_id
......
...@@ -6,27 +6,27 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do ...@@ -6,27 +6,27 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
let(:repo) { double } let(:repo) { double }
let(:raw) do let(:raw) do
{ {
ref: 'feature', ref: 'branch-merged',
repo: repo, repo: repo,
sha: commit.id sha: commit.id
} }
end end
describe '#exists?' do describe '#exists?' do
it 'returns true when both branch, and commit exists' do it 'returns true when branch exists and commit is part of the branch' do
branch = described_class.new(project, double(raw)) branch = described_class.new(project, double(raw))
expect(branch.exists?).to eq true expect(branch.exists?).to eq true
end end
it 'returns false when branch does not exist' do it 'returns false when branch exists and commit is not part of the branch' do
branch = described_class.new(project, double(raw.merge(ref: 'removed-branch'))) branch = described_class.new(project, double(raw.merge(ref: 'feature')))
expect(branch.exists?).to eq false expect(branch.exists?).to eq false
end end
it 'returns false when commit does not exist' do it 'returns false when branch does not exist' do
branch = described_class.new(project, double(raw.merge(sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'))) branch = described_class.new(project, double(raw.merge(ref: 'removed-branch')))
expect(branch.exists?).to eq false expect(branch.exists?).to eq false
end end
......
...@@ -130,7 +130,7 @@ describe Gitlab::GithubImport::Importer, lib: true do ...@@ -130,7 +130,7 @@ describe Gitlab::GithubImport::Importer, lib: true do
let!(:user) { create(:user, email: octocat.email) } let!(:user) { create(:user, email: octocat.email) }
let(:repository) { double(id: 1, fork: false) } let(:repository) { double(id: 1, fork: false) }
let(:source_sha) { create(:commit, project: project).id } let(:source_sha) { create(:commit, project: project).id }
let(:source_branch) { double(ref: 'feature', repo: repository, sha: source_sha) } let(:source_branch) { double(ref: 'branch-merged', repo: repository, sha: source_sha) }
let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id } let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id }
let(:target_branch) { double(ref: 'master', repo: repository, sha: target_sha) } let(:target_branch) { double(ref: 'master', repo: repository, sha: target_sha) }
let(:pull_request) do let(:pull_request) do
......
...@@ -7,7 +7,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -7,7 +7,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id } let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id }
let(:repository) { double(id: 1, fork: false) } let(:repository) { double(id: 1, fork: false) }
let(:source_repo) { repository } let(:source_repo) { repository }
let(:source_branch) { double(ref: 'feature', repo: source_repo, sha: source_sha) } let(:source_branch) { double(ref: 'branch-merged', repo: source_repo, sha: source_sha) }
let(:target_repo) { repository } let(:target_repo) { repository }
let(:target_branch) { double(ref: 'master', repo: target_repo, sha: target_sha) } let(:target_branch) { double(ref: 'master', repo: target_repo, sha: target_sha) }
let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b') } let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b') }
...@@ -49,7 +49,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -49,7 +49,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature', title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes", description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project, source_project: project,
source_branch: 'feature', source_branch: 'branch-merged',
source_branch_sha: source_sha, source_branch_sha: source_sha,
target_project: project, target_project: project,
target_branch: 'master', target_branch: 'master',
...@@ -75,7 +75,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -75,7 +75,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature', title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes", description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project, source_project: project,
source_branch: 'feature', source_branch: 'branch-merged',
source_branch_sha: source_sha, source_branch_sha: source_sha,
target_project: project, target_project: project,
target_branch: 'master', target_branch: 'master',
...@@ -102,7 +102,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -102,7 +102,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature', title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes", description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project, source_project: project,
source_branch: 'feature', source_branch: 'branch-merged',
source_branch_sha: source_sha, source_branch_sha: source_sha,
target_project: project, target_project: project,
target_branch: 'master', target_branch: 'master',
...@@ -194,7 +194,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -194,7 +194,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
let(:raw_data) { double(base_data) } let(:raw_data) { double(base_data) }
it 'returns branch ref' do it 'returns branch ref' do
expect(pull_request.source_branch_name).to eq 'feature' expect(pull_request.source_branch_name).to eq 'branch-merged'
end end
end end
...@@ -208,7 +208,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do ...@@ -208,7 +208,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end end
shared_examples 'Gitlab::GithubImport::PullRequestFormatter#target_branch_name' do shared_examples 'Gitlab::GithubImport::PullRequestFormatter#target_branch_name' do
context 'when source branch exists' do context 'when target branch exists' do
let(:raw_data) { double(base_data) } let(:raw_data) { double(base_data) }
it 'returns branch ref' do it 'returns branch ref' do
......
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