Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-10-20 12:40:42 +0300
commitee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch)
treef8479f94a28f66654c6a4f6fb99bad6b4e86a40e /lib/gitlab/legacy_github_import
parent62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff)
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'lib/gitlab/legacy_github_import')
-rw-r--r--lib/gitlab/legacy_github_import/base_formatter.rb2
-rw-r--r--lib/gitlab/legacy_github_import/branch_formatter.rb14
-rw-r--r--lib/gitlab/legacy_github_import/comment_formatter.rb14
-rw-r--r--lib/gitlab/legacy_github_import/importer.rb24
-rw-r--r--lib/gitlab/legacy_github_import/issuable_formatter.rb18
-rw-r--r--lib/gitlab/legacy_github_import/issue_formatter.rb10
-rw-r--r--lib/gitlab/legacy_github_import/label_formatter.rb4
-rw-r--r--lib/gitlab/legacy_github_import/milestone_formatter.rb16
-rw-r--r--lib/gitlab/legacy_github_import/pull_request_formatter.rb14
-rw-r--r--lib/gitlab/legacy_github_import/release_formatter.rb16
-rw-r--r--lib/gitlab/legacy_github_import/user_formatter.rb12
11 files changed, 84 insertions, 60 deletions
diff --git a/lib/gitlab/legacy_github_import/base_formatter.rb b/lib/gitlab/legacy_github_import/base_formatter.rb
index 0b19cf742ed..7bb33cd474b 100644
--- a/lib/gitlab/legacy_github_import/base_formatter.rb
+++ b/lib/gitlab/legacy_github_import/base_formatter.rb
@@ -23,7 +23,7 @@ module Gitlab
# rubocop: enable CodeReuse/ActiveRecord
def url
- raw_data.url || ''
+ raw_data[:url] || ''
end
end
end
diff --git a/lib/gitlab/legacy_github_import/branch_formatter.rb b/lib/gitlab/legacy_github_import/branch_formatter.rb
index 1177751457f..372c6b2e8a0 100644
--- a/lib/gitlab/legacy_github_import/branch_formatter.rb
+++ b/lib/gitlab/legacy_github_import/branch_formatter.rb
@@ -3,7 +3,17 @@
module Gitlab
module LegacyGithubImport
class BranchFormatter < BaseFormatter
- delegate :repo, :sha, :ref, to: :raw_data
+ def repo
+ raw_data[:repo]
+ end
+
+ def sha
+ raw_data[:sha]
+ end
+
+ def ref
+ raw_data[:ref]
+ end
def exists?
branch_exists? && commit_exists?
@@ -14,7 +24,7 @@ module Gitlab
end
def user
- raw_data.user&.login || 'unknown'
+ raw_data.dig(:user, :login) || 'unknown'
end
def short_sha
diff --git a/lib/gitlab/legacy_github_import/comment_formatter.rb b/lib/gitlab/legacy_github_import/comment_formatter.rb
index d83cc4f6b3c..ffd9da604ca 100644
--- a/lib/gitlab/legacy_github_import/comment_formatter.rb
+++ b/lib/gitlab/legacy_github_import/comment_formatter.rb
@@ -9,19 +9,19 @@ module Gitlab
{
project: project,
note: note,
- commit_id: raw_data.commit_id,
+ commit_id: raw_data[:commit_id],
line_code: line_code,
author_id: author_id,
type: type,
- created_at: raw_data.created_at,
- updated_at: raw_data.updated_at
+ created_at: raw_data[:created_at],
+ updated_at: raw_data[:updated_at]
}
end
private
def author
- @author ||= UserFormatter.new(client, raw_data.user)
+ @author ||= UserFormatter.new(client, raw_data[:user])
end
def author_id
@@ -29,7 +29,7 @@ module Gitlab
end
def body
- raw_data.body || ""
+ raw_data[:body] || ""
end
def line_code
@@ -48,11 +48,11 @@ module Gitlab
end
def diff_hunk
- raw_data.diff_hunk
+ raw_data[:diff_hunk]
end
def file_path
- raw_data.path
+ raw_data[:path]
end
def note
diff --git a/lib/gitlab/legacy_github_import/importer.rb b/lib/gitlab/legacy_github_import/importer.rb
index 4ddafbac4c6..331eab7b62a 100644
--- a/lib/gitlab/legacy_github_import/importer.rb
+++ b/lib/gitlab/legacy_github_import/importer.rb
@@ -96,7 +96,7 @@ module Gitlab
def import_labels
fetch_resources(:labels, repo, per_page: 100) do |labels|
labels.each do |raw|
- gh_label = LabelFormatter.new(project, raw)
+ gh_label = LabelFormatter.new(project, raw.to_h)
gh_label.create!
rescue StandardError => e
errors << { type: :label, url: Gitlab::UrlSanitizer.sanitize(gh_label.url), errors: e.message }
@@ -109,7 +109,7 @@ module Gitlab
def import_milestones
fetch_resources(:milestones, repo, state: :all, per_page: 100) do |milestones|
milestones.each do |raw|
- gh_milestone = MilestoneFormatter.new(project, raw)
+ gh_milestone = MilestoneFormatter.new(project, raw.to_h)
gh_milestone.create!
rescue StandardError => e
errors << { type: :milestone, url: Gitlab::UrlSanitizer.sanitize(gh_milestone.url), errors: e.message }
@@ -121,6 +121,7 @@ module Gitlab
def import_issues
fetch_resources(:issues, repo, state: :all, sort: :created, direction: :asc, per_page: 100) do |issues|
issues.each do |raw|
+ raw = raw.to_h
gh_issue = IssueFormatter.new(project, raw, client)
begin
@@ -143,6 +144,7 @@ module Gitlab
def import_pull_requests
fetch_resources(:pull_requests, repo, state: :all, sort: :created, direction: :asc, per_page: 100) do |pull_requests|
pull_requests.each do |raw|
+ raw = raw.to_h
gh_pull_request = PullRequestFormatter.new(project, raw, client)
next unless gh_pull_request.valid?
@@ -190,10 +192,12 @@ module Gitlab
end
def apply_labels(issuable, raw)
- return unless raw.labels.count > 0
+ raw = raw.to_h
- label_ids = raw.labels
- .map { |attrs| @labels[attrs.name] }
+ return unless raw[:labels].count > 0
+
+ label_ids = raw[:labels]
+ .map { |attrs| @labels[attrs[:name]] }
.compact
issuable.update_attribute(:label_ids, label_ids)
@@ -226,10 +230,12 @@ module Gitlab
def create_comments(comments)
ActiveRecord::Base.no_touching do
comments.each do |raw|
+ raw = raw.to_h
+
comment = CommentFormatter.new(project, raw, client)
# GH does not return info about comment's parent, so we guess it by checking its URL!
- *_, parent, iid = URI(raw.html_url).path.split('/')
+ *_, parent, iid = URI(raw[:html_url]).path.split('/')
issuable = if parent == 'issues'
Issue.find_by(project_id: project.id, iid: iid)
@@ -241,7 +247,7 @@ module Gitlab
issuable.notes.create!(comment.attributes)
rescue StandardError => e
- errors << { type: :comment, url: Gitlab::UrlSanitizer.sanitize(raw.url), errors: e.message }
+ errors << { type: :comment, url: Gitlab::UrlSanitizer.sanitize(raw[:url]), errors: e.message }
end
end
end
@@ -251,7 +257,7 @@ module Gitlab
last_note_attrs = nil
cut_off_index = comments.find_index do |raw|
- comment = CommentFormatter.new(project, raw)
+ comment = CommentFormatter.new(project, raw.to_h)
comment_attrs = comment.attributes
last_note_attrs ||= last_note.slice(*comment_attrs.keys)
@@ -282,7 +288,7 @@ module Gitlab
def import_releases
fetch_resources(:releases, repo, per_page: 100) do |releases|
releases.each do |raw|
- gh_release = ReleaseFormatter.new(project, raw)
+ gh_release = ReleaseFormatter.new(project, raw.to_h)
gh_release.create! if gh_release.valid?
rescue StandardError => e
errors << { type: :release, url: Gitlab::UrlSanitizer.sanitize(gh_release.url), errors: e.message }
diff --git a/lib/gitlab/legacy_github_import/issuable_formatter.rb b/lib/gitlab/legacy_github_import/issuable_formatter.rb
index 1a0aefbbd62..e4e333735be 100644
--- a/lib/gitlab/legacy_github_import/issuable_formatter.rb
+++ b/lib/gitlab/legacy_github_import/issuable_formatter.rb
@@ -9,7 +9,9 @@ module Gitlab
raise NotImplementedError
end
- delegate :number, to: :raw_data
+ def number
+ raw_data[:number]
+ end
def find_condition
{ iid: number }
@@ -18,15 +20,15 @@ module Gitlab
private
def state
- raw_data.state == 'closed' ? 'closed' : 'opened'
+ raw_data[:state] == 'closed' ? 'closed' : 'opened'
end
def assigned?
- raw_data.assignee.present?
+ raw_data[:assignee].present?
end
def author
- @author ||= UserFormatter.new(client, raw_data.user)
+ @author ||= UserFormatter.new(client, raw_data[:user])
end
def author_id
@@ -35,7 +37,7 @@ module Gitlab
def assignee
if assigned?
- @assignee ||= UserFormatter.new(client, raw_data.assignee)
+ @assignee ||= UserFormatter.new(client, raw_data[:assignee])
end
end
@@ -46,7 +48,7 @@ module Gitlab
end
def body
- raw_data.body || ""
+ raw_data[:body] || ""
end
def description
@@ -59,8 +61,8 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def milestone
- if raw_data.milestone.present?
- milestone = MilestoneFormatter.new(project, raw_data.milestone)
+ if raw_data[:milestone].present?
+ milestone = MilestoneFormatter.new(project, raw_data[:milestone])
project.milestones.find_by(milestone.find_condition)
end
end
diff --git a/lib/gitlab/legacy_github_import/issue_formatter.rb b/lib/gitlab/legacy_github_import/issue_formatter.rb
index 2f46e2e30d1..e5c568207e3 100644
--- a/lib/gitlab/legacy_github_import/issue_formatter.rb
+++ b/lib/gitlab/legacy_github_import/issue_formatter.rb
@@ -8,18 +8,18 @@ module Gitlab
iid: number,
project: project,
milestone: milestone,
- title: raw_data.title,
+ title: raw_data[:title],
description: description,
state: state,
author_id: author_id,
assignee_ids: Array(assignee_id),
- created_at: raw_data.created_at,
- updated_at: raw_data.updated_at
+ created_at: raw_data[:created_at],
+ updated_at: raw_data[:updated_at]
}
end
def has_comments?
- raw_data.comments > 0
+ raw_data[:comments] > 0
end
def project_association
@@ -27,7 +27,7 @@ module Gitlab
end
def pull_request?
- raw_data.pull_request.present?
+ raw_data[:pull_request].present?
end
end
end
diff --git a/lib/gitlab/legacy_github_import/label_formatter.rb b/lib/gitlab/legacy_github_import/label_formatter.rb
index 415b1b8878f..e3b767f41fa 100644
--- a/lib/gitlab/legacy_github_import/label_formatter.rb
+++ b/lib/gitlab/legacy_github_import/label_formatter.rb
@@ -28,11 +28,11 @@ module Gitlab
private
def color
- "##{raw_data.color}"
+ "##{raw_data[:color]}"
end
def title
- raw_data.name
+ raw_data[:name]
end
end
end
diff --git a/lib/gitlab/legacy_github_import/milestone_formatter.rb b/lib/gitlab/legacy_github_import/milestone_formatter.rb
index 2fe1b4258d3..60d5bcbf44a 100644
--- a/lib/gitlab/legacy_github_import/milestone_formatter.rb
+++ b/lib/gitlab/legacy_github_import/milestone_formatter.rb
@@ -7,12 +7,12 @@ module Gitlab
{
iid: number,
project: project,
- title: raw_data.title,
- description: raw_data.description,
- due_date: raw_data.due_on,
+ title: raw_data[:title],
+ description: raw_data[:description],
+ due_date: raw_data[:due_on],
state: state,
- created_at: raw_data.created_at,
- updated_at: raw_data.updated_at
+ created_at: raw_data[:created_at],
+ updated_at: raw_data[:updated_at]
}
end
@@ -26,16 +26,16 @@ module Gitlab
def number
if project.gitea_import?
- raw_data.id
+ raw_data[:id]
else
- raw_data.number
+ raw_data[:number]
end
end
private
def state
- raw_data.state == 'closed' ? 'closed' : 'active'
+ raw_data[:state] == 'closed' ? 'closed' : 'active'
end
end
end
diff --git a/lib/gitlab/legacy_github_import/pull_request_formatter.rb b/lib/gitlab/legacy_github_import/pull_request_formatter.rb
index 5b847f13d4a..72adba30093 100644
--- a/lib/gitlab/legacy_github_import/pull_request_formatter.rb
+++ b/lib/gitlab/legacy_github_import/pull_request_formatter.rb
@@ -9,7 +9,7 @@ module Gitlab
def attributes
{
iid: number,
- title: raw_data.title,
+ title: raw_data[:title],
description: description,
source_project: source_branch_project,
source_branch: source_branch_name,
@@ -21,8 +21,8 @@ module Gitlab
milestone: milestone,
author_id: author_id,
assignee_id: assignee_id,
- created_at: raw_data.created_at,
- updated_at: raw_data.updated_at,
+ created_at: raw_data[:created_at],
+ updated_at: raw_data[:updated_at],
imported: true
}
end
@@ -36,7 +36,7 @@ module Gitlab
end
def source_branch
- @source_branch ||= BranchFormatter.new(project, raw_data.head)
+ @source_branch ||= BranchFormatter.new(project, raw_data[:head])
end
def source_branch_name
@@ -57,7 +57,7 @@ module Gitlab
end
def target_branch
- @target_branch ||= BranchFormatter.new(project, raw_data.base)
+ @target_branch ||= BranchFormatter.new(project, raw_data[:base])
end
def target_branch_name
@@ -71,7 +71,7 @@ module Gitlab
def cross_project?
return true if source_branch_repo.nil?
- source_branch_repo.id != target_branch_repo.id
+ source_branch_repo[:id] != target_branch_repo[:id]
end
def opened?
@@ -81,7 +81,7 @@ module Gitlab
private
def state
- if raw_data.state == 'closed' && raw_data.merged_at.present?
+ if raw_data[:state] == 'closed' && raw_data[:merged_at].present?
'merged'
else
super
diff --git a/lib/gitlab/legacy_github_import/release_formatter.rb b/lib/gitlab/legacy_github_import/release_formatter.rb
index 0fb7e376f5b..2a54a15429b 100644
--- a/lib/gitlab/legacy_github_import/release_formatter.rb
+++ b/lib/gitlab/legacy_github_import/release_formatter.rb
@@ -6,13 +6,13 @@ module Gitlab
def attributes
{
project: project,
- tag: raw_data.tag_name,
- name: raw_data.name,
- description: raw_data.body,
- created_at: raw_data.created_at,
+ tag: raw_data[:tag_name],
+ name: raw_data[:name],
+ description: raw_data[:body],
+ created_at: raw_data[:created_at],
# Draft releases will have a null published_at
- released_at: raw_data.published_at || Time.current,
- updated_at: raw_data.created_at
+ released_at: raw_data[:published_at] || Time.current,
+ updated_at: raw_data[:created_at]
}
end
@@ -21,11 +21,11 @@ module Gitlab
end
def find_condition
- { tag: raw_data.tag_name }
+ { tag: raw_data[:tag_name] }
end
def valid?
- !raw_data.draft && raw_data.tag_name.present?
+ !raw_data[:draft] && raw_data[:tag_name].present?
end
end
end
diff --git a/lib/gitlab/legacy_github_import/user_formatter.rb b/lib/gitlab/legacy_github_import/user_formatter.rb
index 7ae1b195ec6..d45a166d2b7 100644
--- a/lib/gitlab/legacy_github_import/user_formatter.rb
+++ b/lib/gitlab/legacy_github_import/user_formatter.rb
@@ -5,13 +5,19 @@ module Gitlab
class UserFormatter
attr_reader :client, :raw
- delegate :id, :login, to: :raw, allow_nil: true
-
def initialize(client, raw)
@client = client
@raw = raw
end
+ def id
+ raw[:id]
+ end
+
+ def login
+ raw[:login]
+ end
+
def gitlab_id
return @gitlab_id if defined?(@gitlab_id)
@@ -21,7 +27,7 @@ module Gitlab
private
def email
- @email ||= client.user(raw.login).try(:email)
+ @email ||= client.user(raw[:login]).to_h[:email]
end
def find_by_email