Commit d052b592 authored by charlie ablett's avatar charlie ablett

Merge branch '208911-jira-issues-serializer' into 'master'

Convert jira issues to gitlab issues

See merge request gitlab-org/gitlab!27201
parents 7fc45180 86577384
......@@ -14,5 +14,10 @@ module Gitlab
author ||= "Anonymous"
"*Created by: #{author}*\n\n"
end
def assignee_line(assignee)
assignee ||= "Anonymous"
"*Assigned to: #{assignee}*\n\n"
end
end
end
......@@ -3,12 +3,50 @@
module Gitlab
module JiraImport
class IssueSerializer
attr_reader :jira_issue, :project, :params, :formatter
def initialize(project, jira_issue, params = {})
@jira_issue = jira_issue
@project = project
@params = params
@formatter = Gitlab::ImportFormatter.new
end
def execute
# this is going to be implemented in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27201
{}
{
iid: params[:iid],
project_id: project.id,
description: description,
title: title,
state_id: map_status(jira_issue.status.statusCategory),
updated_at: jira_issue.updated,
created_at: jira_issue.created,
author_id: project.creator_id # TODO: map actual author: https://gitlab.com/gitlab-org/gitlab/-/issues/210580
}
end
private
def title
"[#{jira_issue.key}] #{jira_issue.summary}"
end
def description
body = []
body << formatter.author_line(jira_issue.reporter.displayName)
body << formatter.assignee_line(jira_issue.assignee.displayName) if jira_issue.assignee
body << jira_issue.description
body.join
end
def map_status(jira_status_category)
case jira_status_category["key"].downcase
when 'done'
Issuable::STATE_ID_MAP[:closed]
else
Issuable::STATE_ID_MAP[:opened]
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ImportFormatter do
let(:formatter) { Gitlab::ImportFormatter.new }
describe '#comment' do
it 'creates the correct string' do
expect(formatter.comment('Name', '2020-02-02', 'some text')).to eq(
"\n\n*By Name on 2020-02-02*\n\nsome text"
)
end
end
describe '#author_line' do
it 'returns the correct string with provided author name' do
expect(formatter.author_line('Name')).to eq("*Created by: Name*\n\n")
end
it 'returns the correct string with Anonymous name if author not provided' do
expect(formatter.author_line(nil)).to eq("*Created by: Anonymous*\n\n")
end
end
describe '#assignee_line' do
it 'returns the correct string with provided author name' do
expect(formatter.assignee_line('Name')).to eq("*Assigned to: Name*\n\n")
end
it 'returns the correct string with Anonymous name if author not provided' do
expect(formatter.assignee_line(nil)).to eq("*Assigned to: Anonymous*\n\n")
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::JiraImport::IssueSerializer do
describe '#execute' do
let_it_be(:project) { create(:project) }
let(:iid) { 5 }
let(:key) { 'PROJECT-5' }
let(:summary) { 'some title' }
let(:description) { 'basic description' }
let(:created_at) { '2020-01-01 20:00:00' }
let(:updated_at) { '2020-01-10 20:00:00' }
let(:assignee) { double(displayName: 'Solver') }
let(:jira_status) { 'new' }
let(:jira_issue) do
double(
id: '1234',
key: key,
summary: summary,
description: description,
created: created_at,
updated: updated_at,
assignee: assignee,
reporter: double(displayName: 'Reporter'),
status: double(statusCategory: { 'key' => jira_status })
)
end
let(:params) { { iid: iid } }
let(:expected_description) do
<<~MD
*Created by: Reporter*
*Assigned to: Solver*
basic description
MD
end
subject { described_class.new(project, jira_issue, params).execute }
context 'attributes setting' do
it 'sets the basic attributes' do
expect(subject).to eq(
iid: iid,
project_id: project.id,
description: expected_description.strip,
title: "[#{key}] #{summary}",
state_id: 1,
updated_at: updated_at,
created_at: created_at,
author_id: project.creator_id
)
end
end
context 'with done status' do
let(:jira_status) { 'done' }
it 'maps the status to closed' do
expect(subject[:state_id]).to eq(2)
end
end
context 'without the assignee' do
let(:assignee) { nil }
it 'does not include assignee in the description' do
expected_description = <<~MD
*Created by: Reporter*
basic description
MD
expect(subject[:description]).to eq(expected_description.strip)
end
end
context 'without the iid' do
let(:params) { {} }
it 'does not set the iid' do
expect(subject[:iid]).to be_nil
end
end
end
end
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