Class: Gitlab::LegacyGithubImport::PullRequestFormatter

Inherits:
IssuableFormatter show all
Defined in:
lib/gitlab/legacy_github_import/pull_request_formatter.rb

Constant Summary

Constants included from Import::UsernameMentionRewriter

Import::UsernameMentionRewriter::MENTION_REGEX

Instance Attribute Summary

Attributes inherited from BaseFormatter

#client, #formatter, #project, #raw_data, #source_user_mapper

Instance Method Summary collapse

Methods inherited from IssuableFormatter

#create!, #find_condition, #number

Methods included from Import::UsernameMentionRewriter

#update_username_mentions, #wrap_mentions_in_backticks

Methods inherited from BaseFormatter

#create!, #create_record, #imported_from, #initialize, #push_placeholder_reference, #push_placeholder_references, #url

Constructor Details

This class inherits a constructor from Gitlab::LegacyGithubImport::BaseFormatter

Instance Method Details

#attributesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 9

def attributes
  {
    iid: number,
    title: raw_data[:title],
    description: description,
    source_project: source_branch_project,
    source_branch: source_branch_name,
    source_branch_sha: source_branch_sha,
    target_project: target_branch_project,
    target_branch: target_branch_name,
    target_branch_sha: target_branch_sha,
    state: state,
    milestone: milestone,
    author_id: author_id,
    assignee_id: assignee_id,
    created_at: raw_data[:created_at],
    updated_at: raw_data[:updated_at],
    imported_from: imported_from
  }
end

#contributing_assignee_formattersObject



91
92
93
94
95
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 91

def contributing_assignee_formatters
  {
    user_id: assignee
  }
end

#contributing_user_formattersObject



85
86
87
88
89
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 85

def contributing_user_formatters
  {
    author_id: author
  }
end

#cross_project?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 71

def cross_project?
  return true if source_branch_repo.nil?

  source_branch_repo[:id] != target_branch_repo[:id]
end

#opened?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 77

def opened?
  state == 'opened'
end

#project_assignee_associationObject



81
82
83
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 81

def project_assignee_association
  :merge_request_assignees
end

#project_associationObject



30
31
32
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 30

def project_association
  :merge_requests
end

#source_branchObject



38
39
40
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 38

def source_branch
  @source_branch ||= BranchFormatter.new(project, raw_data[:head])
end

#source_branch_exists?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 55

def source_branch_exists?
  !cross_project? && source_branch.exists?
end

#source_branch_nameObject



42
43
44
45
46
47
48
49
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 42

def source_branch_name
  @source_branch_name ||=
    if cross_project? || !source_branch_exists?
      source_branch_name_prefixed
    else
      source_branch_ref
    end
end

#source_branch_name_prefixedObject



51
52
53
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 51

def source_branch_name_prefixed
  "gh-#{target_branch_short_sha}/#{number}/#{source_branch_user}/#{source_branch_ref}"
end

#target_branchObject



59
60
61
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 59

def target_branch
  @target_branch ||= BranchFormatter.new(project, raw_data[:base])
end

#target_branch_nameObject



63
64
65
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 63

def target_branch_name
  @target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
end

#target_branch_name_prefixedObject



67
68
69
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 67

def target_branch_name_prefixed
  "gl-#{target_branch_short_sha}/#{number}/#{target_branch_user}/#{target_branch_ref}"
end

#target_branch_shaObject



97
98
99
100
101
102
103
104
105
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 97

def target_branch_sha
  # For merged PRs, Gitea returns base[:sha] as the merge commit SHA,
  # not the target branch SHA before the merge. We need to use merge_base instead.
  if raw_data[:merged] && raw_data[:merge_base].present?
    raw_data[:merge_base]
  else
    target_branch.sha
  end
end

#valid?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/gitlab/legacy_github_import/pull_request_formatter.rb', line 34

def valid?
  source_branch.valid? && target_branch.valid?
end