Class: Gitlab::LegacyGithubImport::PullRequestFormatter

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

Instance Attribute Summary

Attributes inherited from BaseFormatter

#client, #formatter, #project, #raw_data

Instance Method Summary collapse

Methods inherited from IssuableFormatter

#find_condition, #number

Methods inherited from BaseFormatter

#create!, #initialize, #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: true
  }
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_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

#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