Compare commits

..
5 Commits
15 changed files with 174 additions and 62 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.60 1.0.65
+2
View File
@@ -57,6 +57,8 @@ namespace JiraTimeBot.DI
_builder.RegisterType<JiraDescriptionSource>().AsSelf().As<IJiraDescriptionSource>(); _builder.RegisterType<JiraDescriptionSource>().AsSelf().As<IJiraDescriptionSource>();
_builder.RegisterType<JiraApi>().AsSelf().AsImplementedInterfaces(); _builder.RegisterType<JiraApi>().AsSelf().AsImplementedInterfaces();
_builder.RegisterType<JiraHistory>().AsSelf().As<IJiraHistory>();
_builder.Register(c => new Job(c.Resolve<IAllMercurialProviders>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf(); _builder.Register(c => new Job(c.Resolve<IAllMercurialProviders>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf();
_builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces(); _builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces();
+9 -1
View File
@@ -9,7 +9,15 @@ using JiraTimeBot.TaskTime.Objects;
namespace JiraTimeBot.JiraIntegration namespace JiraTimeBot.JiraIntegration
{ {
public class JiraApi public interface IJiraApi
{
List<Issue> GetIssuesByJQL(string jql, Settings settings, DateTime? date = null, CancellationToken cancellationToken = default);
string GetTaskName(string branch, Settings settings);
List<Issue> GetWorkloggedIssuesByDate(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default);
void SetTodayWorklog(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false, CancellationToken cancellationToken = default);
}
public class JiraApi : IJiraApi
{ {
private readonly ILog _log; private readonly ILog _log;
private readonly IJiraDescriptionSource _descriptionSource; private readonly IJiraDescriptionSource _descriptionSource;
@@ -48,10 +48,12 @@ namespace JiraTimeBot.JiraIntegration
{ {
var item = new TaskTimeItem(issue.Key.Value, var item = new TaskTimeItem(issue.Key.Value,
issue.Summary, issue.Summary,
1, issue.Project,
TimeSpan.Zero,
issue.Updated.GetValueOrDefault(date.Value), issue.Updated.GetValueOrDefault(date.Value),
TimeSpan.Zero,
1, 1,
1,
"",
CommitType.Task); CommitType.Task);
workTasks.Add(item); workTasks.Add(item);
} }
@@ -60,10 +62,12 @@ namespace JiraTimeBot.JiraIntegration
{ {
var item = new TaskTimeItem(issue.Key.Value, var item = new TaskTimeItem(issue.Key.Value,
issue.Summary, issue.Summary,
1, issue.Project,
TimeSpan.Zero,
issue.Updated.GetValueOrDefault(date.Value), issue.Updated.GetValueOrDefault(date.Value),
TimeSpan.Zero,
1, 1,
1,
"",
CommitType.Task); CommitType.Task);
workTasks.Add(item); workTasks.Add(item);
} }
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JiraTimeBot.Configuration;
using JiraTimeBot.TaskTime.Objects;
namespace JiraTimeBot.JiraIntegration
{
public interface IJiraHistory
{
List<TaskTimeItem> GetDayWorklogs(DateTime date,
Settings settings,
CancellationToken cancellationToken = default(CancellationToken));
}
public class JiraHistory: IJiraHistory
{
private readonly IJiraApi _jiraApi;
public JiraHistory(IJiraApi jiraApi)
{
_jiraApi = jiraApi;
}
public List<TaskTimeItem> GetDayWorklogs(DateTime date,
Settings settings,
CancellationToken cancellationToken = default(CancellationToken))
{
var tasks = _jiraApi.GetIssuesByJQL("status changed by '%USER%' during (\"%DATE%\",\"%DATE%\")", settings, date, cancellationToken);
List<TaskTimeItem> resultItems = new List<TaskTimeItem>();
foreach (var issue in tasks)
{
var workLogs = issue.GetWorklogsAsync(cancellationToken).Result;
var user = settings.JiraUserName;
//user = "Zoya.Aleksandridi";
var userWorklogs = workLogs.Where(w =>
w.CreateDate.GetValueOrDefault().Date == date && w.Author.Equals(user,
StringComparison.InvariantCultureIgnoreCase)).ToList();
if (!userWorklogs.Any())
{
continue;
}
var firstWorklog = userWorklogs.First();
var description = string.Join("\r\n", userWorklogs.Select(f => f.Comment).Distinct());
var totalTime = TimeSpan.FromSeconds(userWorklogs.Sum(f => f.TimeSpentInSeconds));
var startDate = firstWorklog?.CreateDate ?? date;
var commits = userWorklogs.Sum(f => f.Comment.Count(c => c == '\n'));
var taskType = CommitType.Task;
if (description.Contains("Подготовка и публикация"))
{
taskType = CommitType.Release;
}
resultItems.Add(new TaskTimeItem(issue.Key.Value, description, issue.Project, startDate, totalTime, commits, 1, "", taskType));
}
return resultItems;
}
}
}
+1
View File
@@ -81,6 +81,7 @@
<Compile Include="DI\ContainerBuilder.cs" /> <Compile Include="DI\ContainerBuilder.cs" />
<Compile Include="JiraIntegration\Comments\IJiraDescriptionSource.cs" /> <Compile Include="JiraIntegration\Comments\IJiraDescriptionSource.cs" />
<Compile Include="JiraIntegration\Comments\JiraDescriptionSource.cs" /> <Compile Include="JiraIntegration\Comments\JiraDescriptionSource.cs" />
<Compile Include="JiraIntegration\JiraHistory.cs" />
<Compile Include="Job.cs" /> <Compile Include="Job.cs" />
<Compile Include="Logger.cs" /> <Compile Include="Logger.cs" />
<Compile Include="Configuration\Settings.cs" /> <Compile Include="Configuration\Settings.cs" />
+11 -1
View File
@@ -78,8 +78,18 @@ namespace JiraTimeBot
_log.Info("Использую Jira как источник информации."); _log.Info("Использую Jira как источник информации.");
mercurial = _mercurialProviders.JiraCommitEmulator; mercurial = _mercurialProviders.JiraCommitEmulator;
} }
List<TaskTimeItem> taskTimes = null;
if (!(tasksProcessor is MeetingProcessor))
{
List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken); List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken);
List<TaskTimeItem> taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken); taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
}
else
{
var provider = _mercurialProviders.JiraHistory;
taskTimes = provider.GetDayWorklogs(realDate, settings, cancellationToken);
}
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
@@ -6,5 +6,6 @@ namespace JiraTimeBot.Mercurial
{ {
MercurialLog MercurialLog { get; } MercurialLog MercurialLog { get; }
JiraCommitEmulator JiraCommitEmulator { get; } JiraCommitEmulator JiraCommitEmulator { get; }
IJiraHistory JiraHistory { get; }
} }
} }
+8 -3
View File
@@ -48,6 +48,8 @@ namespace JiraTimeBot.Mercurial
continue; continue;
} }
var directoryInfo = new DirectoryInfo(repoDirectory);
var repo = new Repository(repoDirectory); var repo = new Repository(repoDirectory);
var logCommand = new LogCommand var logCommand = new LogCommand
{ {
@@ -74,10 +76,12 @@ namespace JiraTimeBot.Mercurial
var task = new TaskTimeItem(changeset.Branch, var task = new TaskTimeItem(changeset.Branch,
commitMessage, commitMessage,
1, directoryInfo.Name,
TimeSpan.Zero,
changeset.Timestamp, changeset.Timestamp,
TimeSpan.Zero,
1,
changeset.PathActions.Count, changeset.PathActions.Count,
"",
GetCommitType(changeset.Branch)); GetCommitType(changeset.Branch));
if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase)) if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase))
@@ -91,7 +95,8 @@ namespace JiraTimeBot.Mercurial
var release = task.Branch.Replace("release", ""); var release = task.Branch.Replace("release", "");
task.Branch = branch; task.Branch = branch;
task.Description = $"Подготовка и публикация версии {release}."; task.Description = $"Подготовка и публикация версии {task.Project} {release}.";
task.ReleaseVersion = release;
} }
workTasks.Add(task); workTasks.Add(task);
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}"); _log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}");
+3 -3
View File
@@ -26,6 +26,6 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.60")] [assembly: AssemblyVersion("1.0.65")]
[assembly: AssemblyFileVersion("1.0.60")] [assembly: AssemblyFileVersion("1.0.65")]
[assembly: AssemblyInformationalVersion("1.0.60")] [assembly: AssemblyInformationalVersion("1.0.65")]
@@ -1,7 +1,10 @@
namespace JiraTimeBot.TaskTime.Objects using System;
namespace JiraTimeBot.TaskTime.Objects
{ {
[Flags]
public enum CommitType { public enum CommitType {
Task = 0, Task = 1,
Release = 1 Release = 2
} }
} }
@@ -11,17 +11,29 @@ namespace JiraTimeBot.TaskTime.Objects
public int Commits { get; set; } public int Commits { get; set; }
public int FilesAffected { get; set; } public int FilesAffected { get; set; }
public CommitType Type { get; set; } public CommitType Type { get; set; }
public string Project { get; set; }
public string ReleaseVersion { get; set; }
public TaskTimeItem(string branch, string description, int commits, TimeSpan timeSpent, DateTime startTime, public TaskTimeItem(string branch, string description, string project, DateTime startTime, TimeSpan timeSpent, int commits,
int filesAffected, CommitType type) int filesAffected = 1, string releaseVersion = "", CommitType type = CommitType.Task)
{ {
Branch = branch; Branch = branch;
Description = description; Description = description;
Project = project;
Commits = commits; Commits = commits;
TimeSpent = timeSpent; TimeSpent = timeSpent;
StartTime = startTime; StartTime = startTime;
FilesAffected = filesAffected; FilesAffected = filesAffected;
ReleaseVersion = releaseVersion;
Type = type; Type = type;
} }
public void MergeWith(TaskTimeItem toMerge)
{
Commits += toMerge.Commits;
TimeSpent += toMerge.TimeSpent;
Description += "\r\n" + toMerge.Description;
Type |= toMerge.Type;
}
} }
} }
@@ -59,11 +59,10 @@ namespace JiraTimeBot.TaskTime
var workTasks = _spreadHelper.SpreadTime(taskCommits, remainMinutes, settings.RoundToMinutes); var workTasks = _spreadHelper.SpreadTime(taskCommits, remainMinutes, settings.RoundToMinutes);
foreach (var workTask in workTasks) foreach (var workTask in workTasks)
{ {
var existingItem = workTimeItems.FirstOrDefault(f => f.Branch == workTask.Branch); TaskTimeItem existingItem = workTimeItems.FirstOrDefault(f => f.Branch == workTask.Branch);
if (existingItem != null) if (existingItem != null)
{ {
existingItem.TimeSpent += workTask.TimeSpent; existingItem.MergeWith(workTask);
existingItem.Description += "\r\n" + workTask.Description;
continue; continue;
} }
@@ -95,10 +94,12 @@ namespace JiraTimeBot.TaskTime
{ {
return new TaskTimeItem(timeControlTask, return new TaskTimeItem(timeControlTask,
"Ведение учета времени", "Ведение учета времени",
1, "Service",
TimeSpan.FromMinutes(minutes),
DateTime.Now, DateTime.Now,
TimeSpan.FromMinutes(minutes),
1, 1,
1,
"",
CommitType.Task); CommitType.Task);
} }
+6 -6
View File
@@ -19,20 +19,18 @@ namespace JiraTimeBot.TaskTime
public List<TaskTimeItem> SpreadTime(List<TaskTimeItem> source, int minutes, int roundToMinutes, bool roundUp = false, bool appendTime = true) public List<TaskTimeItem> SpreadTime(List<TaskTimeItem> source, int minutes, int roundToMinutes, bool roundUp = false, bool appendTime = true)
{ {
List<TaskTimeItem> newList = new List<TaskTimeItem>(); List<TaskTimeItem> newList = new List<TaskTimeItem>();
int remainMinutes = minutes;
//Нам нужно раскидать 480 минут в день. //Нам нужно раскидать 480 минут в день.
foreach (var taskGroup in source.GroupBy(f => f.Branch).OrderByDescending(f => f.Count())) foreach (var taskGroup in source.GroupBy(f => f.Branch).OrderByDescending(f => f.Count()))
{ {
int currentTaskCommits = taskGroup.Count(); int currentTaskCommits = taskGroup.Count();
int currentTaskTime = (int)RoundTo(minutes / source.Count * currentTaskCommits, roundToMinutes, roundUp); int currentTaskTime = (int)RoundTo(minutes / source.Count * currentTaskCommits, roundToMinutes, roundUp);
remainMinutes = remainMinutes - currentTaskTime;
var orderedTasks = taskGroup.OrderBy(f => f.StartTime).ToArray(); var orderedTasks = taskGroup.OrderBy(f => f.StartTime).ToArray();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (var task in orderedTasks) foreach (var taskDescription in orderedTasks.Select(f=>f.Description).Distinct())
{ {
sb.AppendLine($"- {task.Description}"); sb.AppendLine($"- {taskDescription}");
} }
var timeSpent = appendTime var timeSpent = appendTime
@@ -43,10 +41,12 @@ namespace JiraTimeBot.TaskTime
var taskTimeItem = new TaskTimeItem( var taskTimeItem = new TaskTimeItem(
taskGroup.Key, taskGroup.Key,
sb.ToString(), sb.ToString(),
taskGroup.Sum(f => f.Commits), taskGroup.First().Project,
timeSpent,
taskGroup.Min(f => f.StartTime), taskGroup.Min(f => f.StartTime),
timeSpent,
taskGroup.Sum(f => f.Commits),
taskGroup.Sum(f => f.FilesAffected), taskGroup.Sum(f => f.FilesAffected),
taskGroup.First().ReleaseVersion,
taskGroup.First().Type); taskGroup.First().Type);
newList.Add(taskTimeItem); newList.Add(taskTimeItem);
@@ -23,13 +23,13 @@ namespace JiraTimeBot.TasksProcessors
{ {
_log.Trace($"На реальную дату {realDate:dd.MM.yyyy} распределение по задачам:"); _log.Trace($"На реальную дату {realDate:dd.MM.yyyy} распределение по задачам:");
foreach (var taskTime in taskTimes.Where(f=>f.Type == CommitType.Task).OrderByDescending(f => f.TimeSpent)) foreach (var taskTime in taskTimes.Where(f=>f.Type.HasFlag(CommitType.Task)).OrderByDescending(f => f.TimeSpent))
{ {
var taskName = _jiraApi.GetTaskName(taskTime.Branch, settings); var taskName = _jiraApi.GetTaskName(taskTime.Branch, settings);
_log.Trace($" - [{taskTime.Branch}, коммитов {taskTime.Commits}]: {taskName} - {taskTime.TimeSpent}"); _log.Trace($" - [{taskTime.Branch}, коммитов {taskTime.Commits}]: {taskName} - {taskTime.TimeSpent}");
} }
var releases = taskTimes.Where(f => f.Type == CommitType.Release).GroupBy(f=>f.Description); var releases = taskTimes.Where(f => f.Type.HasFlag(CommitType.Release)).GroupBy(f=>f.Description);
foreach (var release in releases) foreach (var release in releases)
{ {
var sum = release.Sum(f => (int) f.TimeSpent.TotalMinutes); var sum = release.Sum(f => (int) f.TimeSpent.TotalMinutes);