Commit d1d1e7c6 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'bb-wiki-import' into 'master'

Add Wiki import to BB importer

## What does this MR do?

Adds wiki importing



- [ ] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
  - [ ] Added for this feature/bug
  - [ ] All builds are passing
- [ ] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/25819

See merge request !8180
parents 959981af 5b0ebbe5
...@@ -5,7 +5,7 @@ Bitbucket.org account. ...@@ -5,7 +5,7 @@ Bitbucket.org account.
## Overview ## Overview
You can set up Bitbucket.org as an OAuth provider so that you can use your You can set up Bitbucket.org as an OAuth2 provider so that you can use your
credentials to authenticate into GitLab or import your projects from credentials to authenticate into GitLab or import your projects from
Bitbucket.org. Bitbucket.org.
...@@ -50,6 +50,7 @@ you to use. ...@@ -50,6 +50,7 @@ you to use.
Repositories: Read Repositories: Read
Pull Requests: Read Pull Requests: Read
Issues: Read Issues: Read
Wiki: Read and Write
``` ```
![Bitbucket OAuth settings page](img/bitbucket_oauth_settings_page.png) ![Bitbucket OAuth settings page](img/bitbucket_oauth_settings_page.png)
......
...@@ -17,6 +17,7 @@ to enable this if not already. ...@@ -17,6 +17,7 @@ to enable this if not already.
- the pull requests (GitLab 8.4+) - the pull requests (GitLab 8.4+)
- the pull request comments (GitLab 8.15+) - the pull request comments (GitLab 8.15+)
- the milestones (GitLab 8.15+) - the milestones (GitLab 8.15+)
- the wiki (GitLab 8.15+)
- References to pull requests and issues are preserved (GitLab 8.7+) - References to pull requests and issues are preserved (GitLab 8.7+)
- Repository public access is retained. If a repository is private in Bitbucket - Repository public access is retained. If a repository is private in Bitbucket
it will be created as private in GitLab as well. it will be created as private in GitLab as well.
......
...@@ -51,6 +51,10 @@ module Bitbucket ...@@ -51,6 +51,10 @@ module Bitbucket
raw['scm'] == 'git' raw['scm'] == 'git'
end end
def has_wiki?
raw['has_wiki']
end
def visibility_level def visibility_level
if raw['is_private'] if raw['is_private']
Gitlab::VisibilityLevel::PRIVATE Gitlab::VisibilityLevel::PRIVATE
......
module Gitlab module Gitlab
module BitbucketImport module BitbucketImport
class Importer class Importer
include Gitlab::ShellAdapter
LABELS = [{ title: 'bug', color: '#FF0000' }, LABELS = [{ title: 'bug', color: '#FF0000' },
{ title: 'enhancement', color: '#428BCA' }, { title: 'enhancement', color: '#428BCA' },
{ title: 'proposal', color: '#69D100' }, { title: 'proposal', color: '#69D100' },
...@@ -18,6 +20,7 @@ module Gitlab ...@@ -18,6 +20,7 @@ module Gitlab
end end
def execute def execute
import_wiki
import_issues import_issues
import_pull_requests import_pull_requests
handle_errors handle_errors
...@@ -55,6 +58,16 @@ module Gitlab ...@@ -55,6 +58,16 @@ module Gitlab
@repo ||= client.repo(project.import_source) @repo ||= client.repo(project.import_source)
end end
def import_wiki
return if project.wiki.repository_exists?
path_with_namespace = "#{project.path_with_namespace}.wiki"
import_url = project.import_url.sub(/\.git\z/, ".git/wiki")
gitlab_shell.import_repository(project.repository_storage_path, path_with_namespace, import_url)
rescue StandardError => e
errors << { type: :wiki, errors: e.message }
end
def import_issues def import_issues
return unless repo.issues_enabled? return unless repo.issues_enabled?
......
...@@ -22,9 +22,16 @@ module Gitlab ...@@ -22,9 +22,16 @@ module Gitlab
import_type: 'bitbucket', import_type: 'bitbucket',
import_source: repo.full_name, import_source: repo.full_name,
import_url: repo.clone_url(session_data[:token]), import_url: repo.clone_url(session_data[:token]),
import_data: { credentials: session_data } import_data: { credentials: session_data },
skip_wiki: skip_wiki
).execute ).execute
end end
private
def skip_wiki
repo.has_wiki?
end
end end
end end
end end
require 'spec_helper'
describe Bitbucket::Representation::Repo do
describe '#has_wiki?' do
it { expect(described_class.new({ 'has_wiki' => false }).has_wiki?).to be_falsey }
it { expect(described_class.new({ 'has_wiki' => true }).has_wiki?).to be_truthy }
end
describe '#name' do
it { expect(described_class.new({ 'name' => 'test' }).name).to eq('test') }
end
describe '#valid?' do
it { expect(described_class.new({ 'scm' => 'hg' }).valid?).to be_falsey }
it { expect(described_class.new({ 'scm' => 'git' }).valid?).to be_truthy }
end
describe '#full_name' do
it { expect(described_class.new({ 'full_name' => 'test_full' }).full_name).to eq('test_full') }
end
describe '#description' do
it { expect(described_class.new({ 'description' => 'desc' }).description).to eq('desc') }
end
describe '#issues_enabled?' do
it { expect(described_class.new({ 'has_issues' => false }).issues_enabled?).to be_falsey }
it { expect(described_class.new({ 'has_issues' => true }).issues_enabled?).to be_truthy }
end
describe '#owner_and_slug' do
it { expect(described_class.new({ 'full_name' => 'ben/test' }).owner_and_slug).to eq(['ben', 'test']) }
end
describe '#owner' do
it { expect(described_class.new({ 'full_name' => 'ben/test' }).owner).to eq('ben') }
end
describe '#slug' do
it { expect(described_class.new({ 'full_name' => 'ben/test' }).slug).to eq('test') }
end
describe '#clone_url' do
it 'builds url' do
data = { 'links' => { 'clone' => [ { 'name' => 'https', 'href' => 'https://bibucket.org/test/test.git' }] } }
expect(described_class.new(data).clone_url('abc')).to eq('https://x-token-auth:abc@bibucket.org/test/test.git')
end
end
end
...@@ -69,6 +69,9 @@ describe Gitlab::BitbucketImport::Importer, lib: true do ...@@ -69,6 +69,9 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
context 'issues statuses' do context 'issues statuses' do
before do before do
# HACK: Bitbucket::Representation.const_get('Issue') seems to return ::Issue without this
Bitbucket::Representation::Issue.new({})
stub_request( stub_request(
:get, :get,
"https://api.bitbucket.org/2.0/repositories/#{project_identifier}" "https://api.bitbucket.org/2.0/repositories/#{project_identifier}"
...@@ -108,13 +111,16 @@ describe Gitlab::BitbucketImport::Importer, lib: true do ...@@ -108,13 +111,16 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
body: {}.to_json) body: {}.to_json)
end end
it 'map statuses to open or closed' do it 'maps statuses to open or closed' do
# HACK: Bitbucket::Representation.const_get('Issue') seems to return ::Issue without this
Bitbucket::Representation::Issue.new({})
importer.execute importer.execute
expect(project.issues.where(state: "closed").size).to eq(5) expect(project.issues.where(state: "closed").size).to eq(5)
expect(project.issues.where(state: "opened").size).to eq(2) expect(project.issues.where(state: "opened").size).to eq(2)
end end
it 'calls import_wiki' do
expect(importer).to receive(:import_wiki)
importer.execute
end
end end
end end
...@@ -11,7 +11,8 @@ describe Gitlab::BitbucketImport::ProjectCreator, lib: true do ...@@ -11,7 +11,8 @@ describe Gitlab::BitbucketImport::ProjectCreator, lib: true do
owner: "asd", owner: "asd",
full_name: 'Vim repo', full_name: 'Vim repo',
visibility_level: Gitlab::VisibilityLevel::PRIVATE, visibility_level: Gitlab::VisibilityLevel::PRIVATE,
clone_url: 'ssh://git@bitbucket.org/asd/vim.git') clone_url: 'ssh://git@bitbucket.org/asd/vim.git',
has_wiki?: false)
end end
let(:namespace){ create(:group, owner: user) } let(:namespace){ create(:group, owner: user) }
......
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