Commit 402cc95c authored by Stan Hu's avatar Stan Hu

Fix Bitbucket importer spec to pass with 2.0 API

parent 0b72994b
......@@ -22,10 +22,10 @@ module Bitbucket
attrs.map { |attr| { attr.to_sym => raw[attr] } }.reduce(&:merge)
end
def parse_values(raw, representation_class)
def parse_values(raw, bitbucket_rep_class)
return [] unless raw['values'] && raw['values'].is_a?(Array)
raw['values'].map { |hash| representation_class.new(hash) }
raw['values'].map { |hash| bitbucket_rep_class.new(hash) }
end
def representation_class(type)
......
......@@ -62,13 +62,6 @@ module Gitlab
)
end
end
project.issues.create!(
description: body,
title: issue["title"],
state: %w(resolved invalid duplicate wontfix closed).include?(issue["status"]) ? 'closed' : 'opened',
author_id: gitlab_user_id(project, reporter)
)
end
rescue ActiveRecord::RecordInvalid
nil
......
......@@ -23,10 +23,14 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
statuses.map.with_index do |status, index|
issues << {
local_id: index,
status: status,
id: index,
state: status,
title: "Issue #{index}",
content: "Some content to issue #{index}"
content: {
raw: "Some content to issue #{index}",
markup: "markdown",
html: "Some content to issue #{index}"
}
}
end
......@@ -37,8 +41,8 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
let(:data) do
{
'bb_session' => {
'bitbucket_access_token' => "123456",
'bitbucket_access_token_secret' => "secret"
'bitbucket_token' => "123456",
'bitbucket_refresh_token' => "secret"
}
}
end
......@@ -53,7 +57,7 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
let(:issues_statuses_sample_data) do
{
count: sample_issues_statuses.count,
issues: sample_issues_statuses
values: sample_issues_statuses
}
end
......@@ -61,26 +65,40 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
before do
stub_request(
:get,
"https://bitbucket.org/api/1.0/repositories/#{project_identifier}"
).to_return(status: 200, body: { has_issues: true }.to_json)
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}"
).to_return(status: 200,
headers: {"Content-Type" => "application/json"},
body: { has_issues: true, full_name: project_identifier }.to_json)
stub_request(
:get,
"https://bitbucket.org/api/1.0/repositories/#{project_identifier}/issues?limit=50&sort=utc_created_on&start=0"
).to_return(status: 200, body: issues_statuses_sample_data.to_json)
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/issues?pagelen=50&sort=created_on"
).to_return(status: 200,
headers: {"Content-Type" => "application/json"},
body: issues_statuses_sample_data.to_json)
sample_issues_statuses.each_with_index do |issue, index|
stub_request(
:get,
"https://bitbucket.org/api/1.0/repositories/#{project_identifier}/issues/#{issue[:local_id]}/comments"
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/issues/#{issue[:id]}/comments?pagelen=50&sort=created_on"
).to_return(
status: 200,
body: [{ author_info: { username: "username" }, utc_created_on: index }].to_json
headers: {"Content-Type" => "application/json"},
body: { author_info: { username: "username" }, utc_created_on: index }.to_json
)
end
stub_request(
:get,
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/pullrequests?pagelen=50&sort=created_on&state=ALL"
).to_return(status: 200,
headers: {"Content-Type" => "application/json"},
body: {}.to_json)
end
it 'map statuses to open or closed' do
# HACK: Bitbucket::Representation.const_get('Issue') seems to return Issue without this
Bitbucket::Representation::Issue
importer.execute
expect(project.issues.where(state: "closed").size).to eq(5)
......
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