Compare commits

...
7 Commits
15 changed files with 230 additions and 96 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.58
1.0.65
+2
View File
@@ -56,6 +56,8 @@ namespace JiraTimeBot.DI
_builder.RegisterType<JiraDescriptionSource>().AsSelf().As<IJiraDescriptionSource>();
_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();
+10 -2
View File
@@ -9,7 +9,15 @@ using JiraTimeBot.TaskTime.Objects;
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 IJiraDescriptionSource _descriptionSource;
@@ -68,7 +76,7 @@ namespace JiraTimeBot.JiraIntegration
return GetIssuesByJQL(jql, settings, date, cancellationToken);
}
private void RemoveWorklogsAddedByUser(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, CancellationToken cancellationToken = default(CancellationToken))
private void RemoveWorklogsAddedByUser(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, CancellationToken cancellationToken = default(CancellationToken))
{
var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date);
foreach (var issue in alreadyLoggedToday)
@@ -46,28 +46,30 @@ namespace JiraTimeBot.JiraIntegration
{
foreach (var comment in userComments.OrderBy(f=>f.CreatedDate))
{
workTasks.Add(new TaskTimeItem
{
StartTime = issue.Updated.GetValueOrDefault(date.Value),
Description = issue.Summary,
Branch = issue.Key.Value,
FilesAffected = 1,
Commits = 1,
Type = CommitType.Task
});
var item = new TaskTimeItem(issue.Key.Value,
issue.Summary,
issue.Project,
issue.Updated.GetValueOrDefault(date.Value),
TimeSpan.Zero,
1,
1,
"",
CommitType.Task);
workTasks.Add(item);
}
}
else
{
workTasks.Add(new TaskTimeItem
{
StartTime = issue.Updated.GetValueOrDefault(date.Value),
Description = issue.Summary,
Branch = issue.Key.Value,
FilesAffected = 1,
Commits = 1,
Type = CommitType.Task
});
var item = new TaskTimeItem(issue.Key.Value,
issue.Summary,
issue.Project,
issue.Updated.GetValueOrDefault(date.Value),
TimeSpan.Zero,
1,
1,
"",
CommitType.Task);
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;
}
}
}
+2
View File
@@ -81,6 +81,7 @@
<Compile Include="DI\ContainerBuilder.cs" />
<Compile Include="JiraIntegration\Comments\IJiraDescriptionSource.cs" />
<Compile Include="JiraIntegration\Comments\JiraDescriptionSource.cs" />
<Compile Include="JiraIntegration\JiraHistory.cs" />
<Compile Include="Job.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Configuration\Settings.cs" />
@@ -92,6 +93,7 @@
<Compile Include="Mercurial\IMercurialLog.cs" />
<Compile Include="Mercurial\Modifiers\TechnicalInfoSkipper.cs" />
<Compile Include="TasksProcessors\IAllTasksProcessors.cs" />
<Compile Include="TaskTime\Objects\CommitType.cs" />
<Compile Include="TaskTime\TaskTimeSpread.cs" />
<Compile Include="UI\frmMain.cs">
<SubType>Form</SubType>
+12 -2
View File
@@ -78,8 +78,18 @@ namespace JiraTimeBot
_log.Info("Использую Jira как источник информации.");
mercurial = _mercurialProviders.JiraCommitEmulator;
}
List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken);
List<TaskTimeItem> taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
List<TaskTimeItem> taskTimes = null;
if (!(tasksProcessor is MeetingProcessor))
{
List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken);
taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
}
else
{
var provider = _mercurialProviders.JiraHistory;
taskTimes = provider.GetDayWorklogs(realDate, settings, cancellationToken);
}
if (cancellationToken.IsCancellationRequested)
{
@@ -6,5 +6,6 @@ namespace JiraTimeBot.Mercurial
{
MercurialLog MercurialLog { get; }
JiraCommitEmulator JiraCommitEmulator { get; }
IJiraHistory JiraHistory { get; }
}
}
+13 -11
View File
@@ -48,6 +48,8 @@ namespace JiraTimeBot.Mercurial
continue;
}
var directoryInfo = new DirectoryInfo(repoDirectory);
var repo = new Repository(repoDirectory);
var logCommand = new LogCommand
{
@@ -72,16 +74,15 @@ namespace JiraTimeBot.Mercurial
}
commitMessage = _technicalInfoSkipper.StripTechnicalInfo(commitMessage);
var task = new TaskTimeItem
{
StartTime = changeset.Timestamp,
Description = commitMessage,
Branch = changeset.Branch,
FilesAffected = changeset.PathActions.Count,
Commits = 1,
TimeSpent = TimeSpan.Zero,
Type = GetCommitType(changeset.Branch)
};
var task = new TaskTimeItem(changeset.Branch,
commitMessage,
directoryInfo.Name,
changeset.Timestamp,
TimeSpan.Zero,
1,
changeset.PathActions.Count,
"",
GetCommitType(changeset.Branch));
if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase))
{
@@ -94,7 +95,8 @@ namespace JiraTimeBot.Mercurial
var release = task.Branch.Replace("release", "");
task.Branch = branch;
task.Description = $"Подготовка и публикация версии {release}.";
task.Description = $"Подготовка и публикация версии {task.Project} {release}.";
task.ReleaseVersion = release;
}
workTasks.Add(task);
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}");
+31 -31
View File
@@ -1,31 +1,31 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("JiraTimeBot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JiraTimeBot")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.58")]
[assembly: AssemblyFileVersion("1.0.58")]
[assembly: AssemblyInformationalVersion("1.0.58")]
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("JiraTimeBot")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JiraTimeBot")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.65")]
[assembly: AssemblyFileVersion("1.0.65")]
[assembly: AssemblyInformationalVersion("1.0.65")]
@@ -0,0 +1,10 @@
using System;
namespace JiraTimeBot.TaskTime.Objects
{
[Flags]
public enum CommitType {
Task = 1,
Release = 2
}
}
@@ -11,10 +11,29 @@ namespace JiraTimeBot.TaskTime.Objects
public int Commits { get; set; }
public int FilesAffected { get; set; }
public CommitType Type { get; set; }
}
public string Project { get; set; }
public string ReleaseVersion { get; set; }
public enum CommitType {
Task = 0,
Release = 1
public TaskTimeItem(string branch, string description, string project, DateTime startTime, TimeSpan timeSpent, int commits,
int filesAffected = 1, string releaseVersion = "", CommitType type = CommitType.Task)
{
Branch = branch;
Description = description;
Project = project;
Commits = commits;
TimeSpent = timeSpent;
StartTime = startTime;
FilesAffected = filesAffected;
ReleaseVersion = releaseVersion;
Type = type;
}
public void MergeWith(TaskTimeItem toMerge)
{
Commits += toMerge.Commits;
TimeSpent += toMerge.TimeSpent;
Description += "\r\n" + toMerge.Description;
Type |= toMerge.Type;
}
}
}
@@ -57,7 +57,17 @@ namespace JiraTimeBot.TaskTime
}
var workTasks = _spreadHelper.SpreadTime(taskCommits, remainMinutes, settings.RoundToMinutes);
workTimeItems.AddRange(workTasks);
foreach (var workTask in workTasks)
{
TaskTimeItem existingItem = workTimeItems.FirstOrDefault(f => f.Branch == workTask.Branch);
if (existingItem != null)
{
existingItem.MergeWith(workTask);
continue;
}
workTimeItems.Add(workTask);
}
workTimeItems = workTimeItems.OrderByDescending(f => f.TimeSpent).ToList();
remainMinutes = minutesPerWorkDay - (int) workTimeItems.Sum(f => f.TimeSpent.TotalMinutes);
@@ -82,13 +92,15 @@ namespace JiraTimeBot.TaskTime
//Если указана задача контроля времени - то спишем туда 30 минут и вычеркнем их из общего рабочего времени.
if (!string.IsNullOrEmpty(timeControlTask))
{
return new TaskTimeItem
{
TimeSpent = TimeSpan.FromMinutes(minutes),
Branch = timeControlTask,
Commits = 1,
Description = "Ведение учета времени"
};
return new TaskTimeItem(timeControlTask,
"Ведение учета времени",
"Service",
DateTime.Now,
TimeSpan.FromMinutes(minutes),
1,
1,
"",
CommitType.Task);
}
return null;
+18 -17
View File
@@ -19,34 +19,35 @@ namespace JiraTimeBot.TaskTime
public List<TaskTimeItem> SpreadTime(List<TaskTimeItem> source, int minutes, int roundToMinutes, bool roundUp = false, bool appendTime = true)
{
List<TaskTimeItem> newList = new List<TaskTimeItem>();
int remainMinutes = minutes;
//Нам нужно раскидать 480 минут в день.
foreach (var taskGroup in source.GroupBy(f => f.Branch).OrderByDescending(f => f.Count()))
{
int currentTaskCommits = taskGroup.Count();
int currentTaskTime = (int)RoundTo(minutes / source.Count * currentTaskCommits, roundToMinutes, roundUp);
remainMinutes = remainMinutes - currentTaskTime;
var orderedTasks = taskGroup.OrderBy(f => f.StartTime).ToArray();
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 taskTimeItem = new TaskTimeItem
{
Branch = taskGroup.Key,
TimeSpent = appendTime ?
TimeSpan.FromMinutes(taskGroup.Sum(f=>f.TimeSpent.TotalMinutes)) + TimeSpan.FromMinutes(currentTaskTime):
TimeSpan.FromMinutes(currentTaskTime)
,
Commits = taskGroup.Sum(f=>f.Commits),
Description = sb.ToString(),
StartTime = taskGroup.Min(f=>f.StartTime),
FilesAffected = taskGroup.Sum(f=>f.FilesAffected),
Type = taskGroup.First().Type
};
var timeSpent = appendTime
? TimeSpan.FromMinutes(taskGroup.Sum(f => f.TimeSpent.TotalMinutes)) +
TimeSpan.FromMinutes(currentTaskTime)
: TimeSpan.FromMinutes(currentTaskTime);
var taskTimeItem = new TaskTimeItem(
taskGroup.Key,
sb.ToString(),
taskGroup.First().Project,
taskGroup.Min(f => f.StartTime),
timeSpent,
taskGroup.Sum(f => f.Commits),
taskGroup.Sum(f => f.FilesAffected),
taskGroup.First().ReleaseVersion,
taskGroup.First().Type);
newList.Add(taskTimeItem);
}
@@ -23,13 +23,13 @@ namespace JiraTimeBot.TasksProcessors
{
_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);
_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)
{
var sum = release.Sum(f => (int) f.TimeSpent.TotalMinutes);