Import labels from GitHub
This commit is contained in:
parent
5f39729c19
commit
05a4f444c3
3 changed files with 53 additions and 1 deletions
|
@ -16,7 +16,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def execute
|
||||
import_issues && import_pull_requests && import_wiki
|
||||
import_labels && import_issues && import_pull_requests && import_wiki
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -25,6 +25,16 @@ module Gitlab
|
|||
@import_data_credentials ||= project.import_data.credentials if project.import_data
|
||||
end
|
||||
|
||||
def import_labels
|
||||
client.labels(project.import_source).each do |raw_data|
|
||||
Label.create!(LabelFormatter.new(project, raw_data).attributes)
|
||||
end
|
||||
|
||||
true
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
raise Projects::ImportService::Error, e.message
|
||||
end
|
||||
|
||||
def import_issues
|
||||
client.list_issues(project.import_source, state: :all,
|
||||
sort: :created,
|
||||
|
|
23
lib/gitlab/github_import/label_formatter.rb
Normal file
23
lib/gitlab/github_import/label_formatter.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Gitlab
|
||||
module GithubImport
|
||||
class LabelFormatter < BaseFormatter
|
||||
def attributes
|
||||
{
|
||||
project: project,
|
||||
title: title,
|
||||
color: color
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def color
|
||||
"##{raw_data.color}"
|
||||
end
|
||||
|
||||
def title
|
||||
raw_data.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
spec/lib/gitlab/github_import/label_formatter_spec.rb
Normal file
19
spec/lib/gitlab/github_import/label_formatter_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::GithubImport::LabelFormatter, lib: true do
|
||||
|
||||
describe '#attributes' do
|
||||
it 'returns formatted attributes' do
|
||||
project = create(:project)
|
||||
raw = double(name: 'improvements', color: 'e6e6e6')
|
||||
|
||||
formatter = described_class.new(project, raw)
|
||||
|
||||
expect(formatter.attributes).to eq({
|
||||
project: project,
|
||||
title: 'improvements',
|
||||
color: '#e6e6e6'
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue