2016-02-22 23:59:13 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Gitlab::BitbucketImport::Importer do
|
2016-06-08 14:49:01 +00:00
|
|
|
include ImportSpecHelper
|
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
before do
|
2016-06-08 14:49:01 +00:00
|
|
|
stub_omniauth_provider('bitbucket')
|
2016-02-22 23:59:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:statuses) do
|
|
|
|
[
|
|
|
|
"open",
|
|
|
|
"resolved",
|
|
|
|
"on hold",
|
|
|
|
"invalid",
|
|
|
|
"duplicate",
|
|
|
|
"wontfix",
|
|
|
|
"closed" # undocumented status
|
|
|
|
]
|
|
|
|
end
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
let(:sample_issues_statuses) do
|
|
|
|
issues = []
|
|
|
|
|
|
|
|
statuses.map.with_index do |status, index|
|
|
|
|
issues << {
|
2016-11-22 04:49:40 +00:00
|
|
|
id: index,
|
|
|
|
state: status,
|
2016-02-22 23:59:13 +00:00
|
|
|
title: "Issue #{index}",
|
2016-12-09 17:40:22 +00:00
|
|
|
kind: 'bug',
|
2016-11-22 04:49:40 +00:00
|
|
|
content: {
|
|
|
|
raw: "Some content to issue #{index}",
|
|
|
|
markup: "markdown",
|
|
|
|
html: "Some content to issue #{index}"
|
|
|
|
}
|
2016-02-22 23:59:13 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
issues
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:project_identifier) { 'namespace/repo' }
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
let(:data) do
|
|
|
|
{
|
2016-03-22 16:53:53 +00:00
|
|
|
'bb_session' => {
|
2016-11-22 04:49:40 +00:00
|
|
|
'bitbucket_token' => "123456",
|
|
|
|
'bitbucket_refresh_token' => "secret"
|
2016-02-22 23:59:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
let(:project) do
|
|
|
|
create(
|
2017-08-02 19:55:11 +00:00
|
|
|
:project,
|
2016-02-22 23:59:13 +00:00
|
|
|
import_source: project_identifier,
|
2017-08-03 12:19:11 +00:00
|
|
|
import_data_attributes: { credentials: data }
|
2016-02-22 23:59:13 +00:00
|
|
|
)
|
|
|
|
end
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2017-07-25 17:09:00 +00:00
|
|
|
let(:importer) { described_class.new(project) }
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
let(:issues_statuses_sample_data) do
|
|
|
|
{
|
|
|
|
count: sample_issues_statuses.count,
|
2016-11-22 04:49:40 +00:00
|
|
|
values: sample_issues_statuses
|
2016-02-22 23:59:13 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'issues statuses' do
|
|
|
|
before do
|
2016-12-19 18:44:57 +00:00
|
|
|
# HACK: Bitbucket::Representation.const_get('Issue') seems to return ::Issue without this
|
|
|
|
Bitbucket::Representation::Issue.new({})
|
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
stub_request(
|
|
|
|
:get,
|
2016-11-22 04:49:40 +00:00
|
|
|
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}"
|
|
|
|
).to_return(status: 200,
|
2016-11-22 04:58:46 +00:00
|
|
|
headers: { "Content-Type" => "application/json" },
|
2016-11-22 04:49:40 +00:00
|
|
|
body: { has_issues: true, full_name: project_identifier }.to_json)
|
2016-02-22 23:59:13 +00:00
|
|
|
|
|
|
|
stub_request(
|
|
|
|
:get,
|
2016-11-22 04:49:40 +00:00
|
|
|
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/issues?pagelen=50&sort=created_on"
|
|
|
|
).to_return(status: 200,
|
2016-11-22 04:58:46 +00:00
|
|
|
headers: { "Content-Type" => "application/json" },
|
2016-11-22 04:49:40 +00:00
|
|
|
body: issues_statuses_sample_data.to_json)
|
2016-02-22 23:59:13 +00:00
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
stub_request(:get, "https://api.bitbucket.org/2.0/repositories/namespace/repo?pagelen=50&sort=created_on")
|
|
|
|
.with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer', 'User-Agent' => 'Faraday v0.9.2' })
|
|
|
|
.to_return(status: 200, body: "", headers: {})
|
2016-12-09 17:40:22 +00:00
|
|
|
|
2016-02-22 23:59:13 +00:00
|
|
|
sample_issues_statuses.each_with_index do |issue, index|
|
|
|
|
stub_request(
|
|
|
|
:get,
|
2016-11-22 04:49:40 +00:00
|
|
|
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/issues/#{issue[:id]}/comments?pagelen=50&sort=created_on"
|
2016-02-22 23:59:13 +00:00
|
|
|
).to_return(
|
|
|
|
status: 200,
|
2016-11-22 04:58:46 +00:00
|
|
|
headers: { "Content-Type" => "application/json" },
|
2016-11-22 04:49:40 +00:00
|
|
|
body: { author_info: { username: "username" }, utc_created_on: index }.to_json
|
2016-02-22 23:59:13 +00:00
|
|
|
)
|
|
|
|
end
|
2016-11-22 04:49:40 +00:00
|
|
|
|
|
|
|
stub_request(
|
2016-11-22 04:58:46 +00:00
|
|
|
:get,
|
|
|
|
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}/pullrequests?pagelen=50&sort=created_on&state=ALL"
|
2016-11-22 04:49:40 +00:00
|
|
|
).to_return(status: 200,
|
2016-11-22 04:58:46 +00:00
|
|
|
headers: { "Content-Type" => "application/json" },
|
2016-11-22 04:49:40 +00:00
|
|
|
body: {}.to_json)
|
2016-02-22 23:59:13 +00:00
|
|
|
end
|
|
|
|
|
2016-12-19 18:44:57 +00:00
|
|
|
it 'maps statuses to open or closed' do
|
2016-02-22 23:59:13 +00:00
|
|
|
importer.execute
|
|
|
|
|
|
|
|
expect(project.issues.where(state: "closed").size).to eq(5)
|
|
|
|
expect(project.issues.where(state: "opened").size).to eq(2)
|
|
|
|
end
|
2016-12-19 18:44:57 +00:00
|
|
|
|
|
|
|
it 'calls import_wiki' do
|
|
|
|
expect(importer).to receive(:import_wiki)
|
|
|
|
importer.execute
|
|
|
|
end
|
2016-02-22 23:59:13 +00:00
|
|
|
end
|
|
|
|
end
|