Set GitHub milestones to Issue/Merge Request that were imported

parent 06ec5111
......@@ -5,6 +5,7 @@ module Gitlab
{
iid: number,
project: project,
milestone: milestone,
title: raw_data.title,
description: description,
state: state,
......@@ -55,6 +56,12 @@ module Gitlab
@formatter.author_line(author) + body
end
def milestone
if raw_data.milestone.present?
project.milestones.find_by(iid: raw_data.milestone.number)
end
end
def state
raw_data.state == 'closed' ? 'closed' : 'opened'
end
......
......@@ -11,6 +11,7 @@ module Gitlab
target_project: target_project,
target_branch: target_branch.name,
state: state,
milestone: milestone,
author_id: author_id,
assignee_id: assignee_id,
created_at: raw_data.created_at,
......@@ -58,6 +59,12 @@ module Gitlab
formatter.author_line(author) + body
end
def milestone
if raw_data.milestone.present?
project.milestones.find_by(iid: raw_data.milestone.number)
end
end
def source_project
project
end
......
......@@ -32,6 +32,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
expected = {
iid: 1347,
project: project,
milestone: nil,
title: 'Found a bug',
description: "*Created by: octocat*\n\nI'm having a problem with this.",
state: 'opened',
......@@ -53,6 +54,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
expected = {
iid: 1347,
project: project,
milestone: nil,
title: 'Found a bug',
description: "*Created by: octocat*\n\nI'm having a problem with this.",
state: 'closed',
......@@ -80,6 +82,21 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
context 'when it has a milestone' do
let(:milestone) { OpenStruct.new(number: 45) }
let(:raw_data) { OpenStruct.new(base_data.merge(milestone: milestone)) }
it 'returns nil when milestone does not exist' do
expect(issue.attributes.fetch(:milestone)).to be_nil
end
it 'returns milestone when it exists' do
milestone = create(:milestone, project: project, iid: 45)
expect(issue.attributes.fetch(:milestone)).to eq milestone
end
end
context 'when author is a GitLab user' do
let(:raw_data) { OpenStruct.new(base_data.merge(user: octocat)) }
......
......@@ -43,6 +43,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project: project,
target_branch: 'master',
state: 'opened',
milestone: nil,
author_id: project.creator_id,
assignee_id: nil,
created_at: created_at,
......@@ -67,6 +68,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project: project,
target_branch: 'master',
state: 'closed',
milestone: nil,
author_id: project.creator_id,
assignee_id: nil,
created_at: created_at,
......@@ -91,6 +93,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project: project,
target_branch: 'master',
state: 'merged',
milestone: nil,
author_id: project.creator_id,
assignee_id: nil,
created_at: created_at,
......@@ -128,6 +131,21 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
expect(pull_request.attributes.fetch(:author_id)).to eq gl_user.id
end
end
context 'when it has a milestone' do
let(:milestone) { OpenStruct.new(number: 45) }
let(:raw_data) { OpenStruct.new(base_data.merge(milestone: milestone)) }
it 'returns nil when milestone does not exists' do
expect(pull_request.attributes.fetch(:milestone)).to be_nil
end
it 'returns milestone when is exists' do
milestone = create(:milestone, project: project, iid: 45)
expect(pull_request.attributes.fetch(:milestone)).to eq milestone
end
end
end
describe '#number' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment