debian-mirror-gitlab/lib/gitlab/legacy_github_import/pull_request_formatter.rb

93 lines
2.4 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
2018-03-17 18:26:18 +05:30
module LegacyGithubImport
2017-08-17 22:00:37 +05:30
class PullRequestFormatter < IssuableFormatter
delegate :user, :project, :ref, :repo, :sha, to: :source_branch, prefix: true
delegate :user, :exists?, :project, :ref, :repo, :sha, :short_sha, to: :target_branch, prefix: true
2016-06-02 11:05:42 +05:30
def attributes
{
2016-06-02 11:05:42 +05:30
iid: number,
title: raw_data.title,
description: description,
2016-06-02 11:05:42 +05:30
source_project: source_branch_project,
source_branch: source_branch_name,
2016-08-24 12:49:21 +05:30
source_branch_sha: source_branch_sha,
2016-06-02 11:05:42 +05:30
target_project: target_branch_project,
target_branch: target_branch_name,
2016-08-24 12:49:21 +05:30
target_branch_sha: target_branch_sha,
state: state,
2016-06-02 11:05:42 +05:30
milestone: milestone,
author_id: author_id,
assignee_id: assignee_id,
created_at: raw_data.created_at,
2017-08-17 22:00:37 +05:30
updated_at: raw_data.updated_at,
imported: true
}
end
2016-11-03 12:29:30 +05:30
def project_association
:merge_requests
end
def valid?
2016-09-13 17:45:13 +05:30
source_branch.valid? && target_branch.valid?
2016-06-02 11:05:42 +05:30
end
def source_branch
@source_branch ||= BranchFormatter.new(project, raw_data.head)
end
2016-09-13 17:45:13 +05:30
def source_branch_name
2017-08-17 22:00:37 +05:30
@source_branch_name ||=
if cross_project? || !source_branch_exists?
source_branch_name_prefixed
else
source_branch_ref
end
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
def source_branch_name_prefixed
"gh-#{target_branch_short_sha}/#{number}/#{source_branch_user}/#{source_branch_ref}"
end
2017-08-17 22:00:37 +05:30
def source_branch_exists?
!cross_project? && source_branch.exists?
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
def target_branch
@target_branch ||= BranchFormatter.new(project, raw_data.base)
end
2017-08-17 22:00:37 +05:30
def target_branch_name
@target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
end
2017-08-17 22:00:37 +05:30
def target_branch_name_prefixed
"gl-#{target_branch_short_sha}/#{number}/#{target_branch_user}/#{target_branch_ref}"
end
2017-08-17 22:00:37 +05:30
def cross_project?
return true if source_branch_repo.nil?
2017-08-17 22:00:37 +05:30
source_branch_repo.id != target_branch_repo.id
end
2017-08-17 22:00:37 +05:30
def opened?
state == 'opened'
2016-01-29 22:53:50 +05:30
end
2017-08-17 22:00:37 +05:30
private
def state
2017-08-17 22:00:37 +05:30
if raw_data.state == 'closed' && raw_data.merged_at.present?
'merged'
else
super
end
end
end
end
end