From e906e4edc30711f529d4fcfdeb91ec9cfbb4518a Mon Sep 17 00:00:00 2001 From: Danil Kislov Date: Fri, 15 Mar 2019 18:02:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D1=80=D0=B5=D1=84=D0=B0?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configuration/PasswordEncryptionClass.cs | 4 +-- JiraTimeBotForm/DI/ContainerBuilder.cs | 8 +++--- .../JiraIntegration/IJiraDescriptionSource.cs | 11 ++++++++ JiraTimeBotForm/JiraIntegration/JiraApi.cs | 20 +++++--------- .../JiraIntegration/JiraDescriptionSource.cs | 27 +++++++++++++++++++ JiraTimeBotForm/JiraTimeBotForm.csproj | 2 ++ .../TaskTime/TaskTimeDiscoverer.cs | 5 ++++ JiraTimeBotForm/UI/frmMain.cs | 3 --- 8 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 JiraTimeBotForm/JiraIntegration/IJiraDescriptionSource.cs create mode 100644 JiraTimeBotForm/JiraIntegration/JiraDescriptionSource.cs diff --git a/JiraTimeBotForm/Configuration/PasswordEncryptionClass.cs b/JiraTimeBotForm/Configuration/PasswordEncryptionClass.cs index 7f1cf30..7ca048b 100644 --- a/JiraTimeBotForm/Configuration/PasswordEncryptionClass.cs +++ b/JiraTimeBotForm/Configuration/PasswordEncryptionClass.cs @@ -6,11 +6,11 @@ namespace JiraTimeBotForm.Configuration { public class PasswordEncryptionClass { - private byte[] GetEntropy(string EntropyString) + private byte[] GetEntropy(string entropyString) { MD5 md5 = MD5.Create(); - return md5.ComputeHash(Encoding.UTF8.GetBytes(EntropyString)); + return md5.ComputeHash(Encoding.UTF8.GetBytes(entropyString)); } public string Encrypt(string username, string password, string address) diff --git a/JiraTimeBotForm/DI/ContainerBuilder.cs b/JiraTimeBotForm/DI/ContainerBuilder.cs index 77dba65..5e56389 100644 --- a/JiraTimeBotForm/DI/ContainerBuilder.cs +++ b/JiraTimeBotForm/DI/ContainerBuilder.cs @@ -32,11 +32,13 @@ namespace JiraTimeBotForm.DI _builder.RegisterType().AsSelf().As(); _builder.RegisterAggregateService(); - _builder.Register(c => new JiraApi(c.Resolve())).AsSelf().AsImplementedInterfaces(); + _builder.RegisterType().AsSelf().As(); + _builder.RegisterType().AsSelf().AsImplementedInterfaces(); _builder.Register(c => new Job(c.Resolve(), c.Resolve(), c.Resolve())).AsSelf(); - - return _builder.Build(); + + var container = _builder.Build(); + return container; } } } diff --git a/JiraTimeBotForm/JiraIntegration/IJiraDescriptionSource.cs b/JiraTimeBotForm/JiraIntegration/IJiraDescriptionSource.cs new file mode 100644 index 0000000..4c42f8a --- /dev/null +++ b/JiraTimeBotForm/JiraIntegration/IJiraDescriptionSource.cs @@ -0,0 +1,11 @@ +using System.Text; +using System.Threading.Tasks; +using JiraTimeBotForm.TaskTime; + +namespace JiraTimeBotForm.JiraIntegration +{ + public interface IJiraDescriptionSource + { + string GetDescription(TaskTimeItem item, bool addCommentsToWorklog); + } +} diff --git a/JiraTimeBotForm/JiraIntegration/JiraApi.cs b/JiraTimeBotForm/JiraIntegration/JiraApi.cs index 4a76445..0dd8de7 100644 --- a/JiraTimeBotForm/JiraIntegration/JiraApi.cs +++ b/JiraTimeBotForm/JiraIntegration/JiraApi.cs @@ -10,16 +10,12 @@ namespace JiraTimeBotForm.JiraIntegration public class JiraApi { private readonly ILog _log; + private readonly IJiraDescriptionSource _descriptionSource; - private readonly List _dummyComments = new List - { - "Написание кода", "написание кода", "программирование", "реализация задачи", "кодинг", "код + тесты", - "кодинг", "написание кода и тестов" - }; - - public JiraApi(ILog log = null) + public JiraApi(ILog log, IJiraDescriptionSource descriptionSource) { _log = log; + _descriptionSource = descriptionSource; } public string GetTaskName(string branch, Settings settings) @@ -46,7 +42,7 @@ namespace JiraTimeBotForm.JiraIntegration } date = date.Value.Date; - foreach (var taskTimeItem in taskTimeItems) + foreach (TaskTimeItem taskTimeItem in taskTimeItems) { Issue issue = null; try @@ -91,12 +87,8 @@ namespace JiraTimeBotForm.JiraIntegration if (!hasTodayWorklog) { var timeSpentJira = $"{taskTimeItem.Time.TotalMinutes}m"; - - var comment = _dummyComments.OrderBy(f=>Guid.NewGuid()).FirstOrDefault(); - if (addCommentsToWorklog) - { - comment = taskTimeItem.Description; - } + + var comment = _descriptionSource.GetDescription(taskTimeItem, addCommentsToWorklog); Worklog workLogToAdd = new Worklog(timeSpentJira, date.Value, comment); if (!dummy) diff --git a/JiraTimeBotForm/JiraIntegration/JiraDescriptionSource.cs b/JiraTimeBotForm/JiraIntegration/JiraDescriptionSource.cs new file mode 100644 index 0000000..a370e07 --- /dev/null +++ b/JiraTimeBotForm/JiraIntegration/JiraDescriptionSource.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using JiraTimeBotForm.TaskTime; + +namespace JiraTimeBotForm.JiraIntegration +{ + public class JiraDescriptionSource : IJiraDescriptionSource + { + private readonly List _dummyComments = new List + { + "Написание кода", "написание кода", "программирование", "реализация задачи", "кодинг", "код + тесты", + "кодинг", "написание кода и тестов" + }; + + public string GetDescription(TaskTimeItem taskTimeItem, bool addCommentsToWorklog) + { + var comment = _dummyComments.OrderBy(f=>Guid.NewGuid()).FirstOrDefault(); + if (addCommentsToWorklog) + { + comment = taskTimeItem.Description; + } + + return comment; + } + } +} \ No newline at end of file diff --git a/JiraTimeBotForm/JiraTimeBotForm.csproj b/JiraTimeBotForm/JiraTimeBotForm.csproj index c5d1598..974bb82 100644 --- a/JiraTimeBotForm/JiraTimeBotForm.csproj +++ b/JiraTimeBotForm/JiraTimeBotForm.csproj @@ -82,6 +82,8 @@ + + diff --git a/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs b/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs index 83ea0d1..5a56236 100644 --- a/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs +++ b/JiraTimeBotForm/TaskTime/TaskTimeDiscoverer.cs @@ -56,11 +56,16 @@ namespace JiraTimeBotForm.TaskTime workTimeItems.Add(taskTimeItem); } + if (!workTimeItems.Any()) + { + return new List(); + } if (remainMinutes != 0) { _log.Trace($"Погрешность распределения времени: {remainMinutes}. Добавляю к первой задаче."); } + //если переборщили или не достаточно добавили до 8 часов - скореектируем остаток в первой задаче (она самая трудозатратная). workTimeItems.First().Time += TimeSpan.FromMinutes(remainMinutes); diff --git a/JiraTimeBotForm/UI/frmMain.cs b/JiraTimeBotForm/UI/frmMain.cs index 0574fd0..4708dce 100644 --- a/JiraTimeBotForm/UI/frmMain.cs +++ b/JiraTimeBotForm/UI/frmMain.cs @@ -7,11 +7,8 @@ using System.Windows.Forms; using Autofac; using JiraTimeBotForm.Configuration; using JiraTimeBotForm.DI; -using JiraTimeBotForm.Mercurial; using JiraTimeBotForm.TasksProcessors; -using JiraTimeBotForm.TaskTime; using JiraTimeBotForm.UI; -using Newtonsoft.Json; // This is the code for your desktop app. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.