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
end
def commit_exists?
project.repository.commit(sha).present?
project.repository.branch_names_contains(sha).include?(ref)
end
def short_id
......
......@@ -6,27 +6,27 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
let(:repo) { double }
let(:raw) do
{
ref: 'feature',
ref: 'branch-merged',
repo: repo,
sha: commit.id
}
end
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))
expect(branch.exists?).to eq true
end
it 'returns false when branch does not exist' do
branch = described_class.new(project, double(raw.merge(ref: 'removed-branch')))
it 'returns false when branch exists and commit is not part of the branch' do
branch = described_class.new(project, double(raw.merge(ref: 'feature')))
expect(branch.exists?).to eq false
end
it 'returns false when commit does not exist' do
branch = described_class.new(project, double(raw.merge(sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b')))
it 'returns false when branch does not exist' do
branch = described_class.new(project, double(raw.merge(ref: 'removed-branch')))
expect(branch.exists?).to eq false
end
......
......@@ -130,7 +130,7 @@ describe Gitlab::GithubImport::Importer, lib: true do
let!(:user) { create(:user, email: octocat.email) }
let(:repository) { double(id: 1, fork: false) }
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_branch) { double(ref: 'master', repo: repository, sha: target_sha) }
let(:pull_request) 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(:repository) { double(id: 1, fork: false) }
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_branch) { double(ref: 'master', repo: target_repo, sha: target_sha) }
let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b') }
......@@ -49,7 +49,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project,
source_branch: 'feature',
source_branch: 'branch-merged',
source_branch_sha: source_sha,
target_project: project,
target_branch: 'master',
......@@ -75,7 +75,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project,
source_branch: 'feature',
source_branch: 'branch-merged',
source_branch_sha: source_sha,
target_project: project,
target_branch: 'master',
......@@ -102,7 +102,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
title: 'New feature',
description: "*Created by: octocat*\n\nPlease pull these awesome changes",
source_project: project,
source_branch: 'feature',
source_branch: 'branch-merged',
source_branch_sha: source_sha,
target_project: project,
target_branch: 'master',
......@@ -194,7 +194,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
let(:raw_data) { double(base_data) }
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
......@@ -208,7 +208,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
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) }
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