mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-10 05:06:46 +10:00
Merge branch 'gh-import-labels' into 'master'
Import labels from GitHub Closes #15292 See merge request !3776
This commit is contained in:
@@ -85,6 +85,7 @@ v 8.7.0 (unreleased)
|
||||
- Show number sign on external issue reference text (Florent Baldino)
|
||||
- Updated print style for issues
|
||||
- Use GitHub Issue/PR number as iid to keep references
|
||||
- Import GitHub labels
|
||||
|
||||
v 8.6.6
|
||||
- Expire the exists cache before deletion to ensure project dir actually exists (Stan Hu). !3413
|
||||
|
||||
@@ -315,7 +315,7 @@ end
|
||||
|
||||
gem "newrelic_rpm", '~> 3.14'
|
||||
|
||||
gem 'octokit', '~> 3.8.0'
|
||||
gem 'octokit', '~> 4.3.0'
|
||||
|
||||
gem "mail_room", "~> 0.6.1"
|
||||
|
||||
|
||||
+5
-5
@@ -485,8 +485,8 @@ GEM
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
octokit (3.8.0)
|
||||
sawyer (~> 0.6.0, >= 0.5.3)
|
||||
octokit (4.3.0)
|
||||
sawyer (~> 0.7.0, >= 0.5.3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (>= 1.0, < 3)
|
||||
@@ -712,8 +712,8 @@ GEM
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sprockets-rails (>= 2.0, < 4.0)
|
||||
tilt (>= 1.1, < 3)
|
||||
sawyer (0.6.0)
|
||||
addressable (~> 2.3.5)
|
||||
sawyer (0.7.0)
|
||||
addressable (>= 2.3.5, < 2.5)
|
||||
faraday (~> 0.8, < 0.10)
|
||||
scss_lint (0.47.1)
|
||||
rake (>= 0.9, < 11)
|
||||
@@ -968,7 +968,7 @@ DEPENDENCIES
|
||||
newrelic_rpm (~> 3.14)
|
||||
nokogiri (~> 1.6.7, >= 1.6.7.2)
|
||||
oauth2 (~> 1.0.0)
|
||||
octokit (~> 3.8.0)
|
||||
octokit (~> 4.3.0)
|
||||
omniauth (~> 1.3.1)
|
||||
omniauth-auth0 (~> 1.4.1)
|
||||
omniauth-azure-oauth2 (~> 0.0.6)
|
||||
|
||||
@@ -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,
|
||||
@@ -33,6 +43,7 @@ module Gitlab
|
||||
|
||||
if gh_issue.valid?
|
||||
issue = Issue.create!(gh_issue.attributes)
|
||||
apply_labels(gh_issue.number, issue)
|
||||
|
||||
if gh_issue.has_comments?
|
||||
import_comments(gh_issue.number, issue)
|
||||
@@ -55,6 +66,7 @@ module Gitlab
|
||||
merge_request = MergeRequest.new(pull_request.attributes)
|
||||
|
||||
if merge_request.save
|
||||
apply_labels(pull_request.number, merge_request)
|
||||
import_comments(pull_request.number, merge_request)
|
||||
import_comments_on_diff(pull_request.number, merge_request)
|
||||
end
|
||||
@@ -66,6 +78,18 @@ module Gitlab
|
||||
raise Projects::ImportService::Error, e.message
|
||||
end
|
||||
|
||||
def apply_labels(number, issuable)
|
||||
issue = client.issue(project.import_source, number)
|
||||
|
||||
if issue.labels.count > 0
|
||||
label_ids = issue.labels.map do |raw|
|
||||
Label.find_by(LabelFormatter.new(project, raw).attributes).try(:id)
|
||||
end
|
||||
|
||||
issuable.update_attribute(:label_ids, label_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def import_comments(issue_number, noteable)
|
||||
comments = client.issue_comments(project.import_source, issue_number)
|
||||
create_comments(comments, noteable)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user