41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using System;
|
|
using System.Reflection.Metadata;
|
|
using TriliumMind.Data.Entities;
|
|
using TriliumMind.Models;
|
|
|
|
namespace TriliumMind.Services.Mappers;
|
|
|
|
public static class JiraIssueMapper
|
|
{
|
|
private static readonly char[] _specialCharacters = ['(', '/'];
|
|
|
|
public static JiraIssue ToEntity(this Issue issue)
|
|
{
|
|
return new JiraIssue
|
|
{
|
|
Key = issue.key,
|
|
Summary = issue.fields.summary ?? string.Empty,
|
|
Parent = issue.fields.parent?.key ?? issue.fields.customfield_10808,
|
|
Type = issue.fields.issuetype?.name ?? string.Empty,
|
|
Status = issue.fields.status?.name ?? string.Empty,
|
|
Assignee = CleanDisplayName(issue.fields.assignee?.displayName),
|
|
Manager = CleanDisplayName(issue.fields.reporter?.displayName),
|
|
Due = issue.fields.duedate?.ToUniversalTime() ?? DateTimeOffset.MinValue.ToUniversalTime(),
|
|
Updated = issue.fields.UpdatedAt.ToUniversalTime(),
|
|
Published = DateTimeOffset.MinValue.ToUniversalTime(),
|
|
ObjectId = null,
|
|
NeedNotify = 0
|
|
};
|
|
}
|
|
private static string CleanDisplayName(string? displayName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(displayName))
|
|
return string.Empty;
|
|
|
|
var specialCharIndex = displayName.IndexOfAny(_specialCharacters);
|
|
if (specialCharIndex >= 0)
|
|
displayName = displayName[..specialCharIndex];
|
|
|
|
return displayName.Trim();
|
|
}
|
|
} |