Skip to content
Snippets Groups Projects
Commit d72b2581 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Doesn't import GitHub PR where branches were no longer available

parent f19bf0ea
No related branches found
No related tags found
No related merge requests found
Loading
@@ -52,50 +52,56 @@ module Gitlab
Loading
@@ -52,50 +52,56 @@ module Gitlab
client.pull_requests(project.import_source, state: :all, client.pull_requests(project.import_source, state: :all,
sort: :created, sort: :created,
direction: :asc).each do |pull_request| direction: :asc).each do |pull_request|
body = @formatter.author_line(pull_request.user.login) source_branch = find_branch(pull_request.head.ref)
body += pull_request.body || "" target_branch = find_branch(pull_request.base.ref)
source_branch = pull_request.head.ref if source_branch && target_branch
target_branch = pull_request.base.ref # Pull Request
merge_request = MergeRequest.create!(
merge_request = MergeRequest.create!( title: pull_request.title,
title: pull_request.title, description: format_body(pull_request.user.login, pull_request.body),
description: body, source_project: project,
source_project: project, source_branch: source_branch.name,
source_branch: source_branch, target_project: project,
target_project: project, target_branch: target_branch.name,
target_branch: target_branch, state: merge_request_state(pull_request),
state: merge_request_state(pull_request), author_id: gl_author_id(project, pull_request.user.id),
author_id: gl_author_id(project, pull_request.user.id), assignee_id: gl_user_id(pull_request.assignee.try(:id)),
assignee_id: gl_user_id(pull_request.assignee.try(:id)), created_at: pull_request.created_at,
created_at: pull_request.created_at, updated_at: pull_request.updated_at
updated_at: pull_request.updated_at
)
client.issue_comments(project.import_source, pull_request.number).each do |c|
merge_request.notes.create!(
project: project,
note: format_body(c.user.login, c.body),
author_id: gl_author_id(project, c.user.id),
created_at: c.created_at,
updated_at: c.updated_at
) )
end
   
client.pull_request_comments(project.import_source, pull_request.number).each do |c| # Comments on Pull Request
merge_request.notes.create!( client.issue_comments(project.import_source, pull_request.number).each do |c|
project: project, merge_request.notes.create!(
note: format_body(c.user.login, c.body), project: project,
commit_id: c.commit_id, note: format_body(c.user.login, c.body),
line_code: generate_line_code(c.path, c.position), author_id: gl_author_id(project, c.user.id),
author_id: gl_author_id(project, c.user.id), created_at: c.created_at,
created_at: c.created_at, updated_at: c.updated_at
updated_at: c.updated_at )
) end
# Comments on Pull Request diff
client.pull_request_comments(project.import_source, pull_request.number).each do |c|
merge_request.notes.create!(
project: project,
note: format_body(c.user.login, c.body),
commit_id: c.commit_id,
line_code: generate_line_code(c.path, c.position),
author_id: gl_author_id(project, c.user.id),
created_at: c.created_at,
updated_at: c.updated_at
)
end
end end
end end
end end
   
def find_branch(name)
project.repository.find_branch(name)
end
def format_body(author, body) def format_body(author, body)
@formatter.author_line(author) + (body || "") @formatter.author_line(author) + (body || "")
end end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment