Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8de5aba1c | ||
|
|
1e40f0a07c | ||
|
|
64723248a5 | ||
|
|
c97ab59b96 |
+1
-1
@@ -1 +1 @@
|
||||
1.0.63
|
||||
1.0.67
|
||||
|
||||
@@ -57,6 +57,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();
|
||||
|
||||
_builder.RegisterType<AutoStartUp>().AsSelf().AsImplementedInterfaces();
|
||||
|
||||
@@ -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)
|
||||
@@ -77,7 +85,7 @@ namespace JiraTimeBot.JiraIntegration
|
||||
{
|
||||
var workLogs = issue.GetWorklogsAsync(cancellationToken).Result;
|
||||
var userWorklogs = workLogs.Where(w =>
|
||||
w.CreateDate.GetValueOrDefault().Date == date && w.Author.Equals(settings.JiraUserName,
|
||||
w.StartDate.GetValueOrDefault().Date == date && w.Author.Equals(settings.JiraUserName,
|
||||
StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||
foreach (var userWorklog in userWorklogs)
|
||||
{
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace JiraTimeBot.JiraIntegration
|
||||
TimeSpan.Zero,
|
||||
1,
|
||||
1,
|
||||
"",
|
||||
CommitType.Task);
|
||||
workTasks.Add(item);
|
||||
}
|
||||
@@ -66,6 +67,7 @@ namespace JiraTimeBot.JiraIntegration
|
||||
TimeSpan.Zero,
|
||||
1,
|
||||
1,
|
||||
"",
|
||||
CommitType.Task);
|
||||
workTasks.Add(item);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
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("worklogDate = \"%DATE%\" and worklogAuthor='%USER%'", 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.StartDate.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'));
|
||||
if (commits == 0)
|
||||
{
|
||||
commits = 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -81,6 +82,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" />
|
||||
|
||||
+12
-2
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace JiraTimeBot.Mercurial
|
||||
TimeSpan.Zero,
|
||||
1,
|
||||
changeset.PathActions.Count,
|
||||
"",
|
||||
GetCommitType(changeset.Branch));
|
||||
|
||||
if (task.Type == CommitType.Release && task.Description.StartsWith("Merge with", StringComparison.CurrentCultureIgnoreCase))
|
||||
@@ -95,6 +96,7 @@ namespace JiraTimeBot.Mercurial
|
||||
|
||||
task.Branch = branch;
|
||||
task.Description = $"Подготовка и публикация версии {task.Project} {release}.";
|
||||
task.ReleaseVersion = release;
|
||||
}
|
||||
workTasks.Add(task);
|
||||
_log?.Trace($" - Найден changeset: {changeset.Timestamp} - {changeset.Branch} - {changeset.AuthorEmailAddress} - {commitMessage}");
|
||||
|
||||
@@ -26,6 +26,6 @@ using System.Runtime.InteropServices;
|
||||
//
|
||||
// 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.63")]
|
||||
[assembly: AssemblyFileVersion("1.0.63")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.63")]
|
||||
[assembly: AssemblyVersion("1.0.67")]
|
||||
[assembly: AssemblyFileVersion("1.0.67")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.67")]
|
||||
|
||||
@@ -12,9 +12,10 @@ namespace JiraTimeBot.TaskTime.Objects
|
||||
public int FilesAffected { get; set; }
|
||||
public CommitType Type { get; set; }
|
||||
public string Project { get; set; }
|
||||
public string ReleaseVersion { get; set; }
|
||||
|
||||
public TaskTimeItem(string branch, string description, string project, DateTime startTime, TimeSpan timeSpent, int commits,
|
||||
int filesAffected = 1, CommitType type = CommitType.Task)
|
||||
int filesAffected = 1, string releaseVersion = "", CommitType type = CommitType.Task)
|
||||
{
|
||||
Branch = branch;
|
||||
Description = description;
|
||||
@@ -23,6 +24,7 @@ namespace JiraTimeBot.TaskTime.Objects
|
||||
TimeSpent = timeSpent;
|
||||
StartTime = startTime;
|
||||
FilesAffected = filesAffected;
|
||||
ReleaseVersion = releaseVersion;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace JiraTimeBot.TaskTime
|
||||
_spreadHelper = spreadHelper;
|
||||
}
|
||||
|
||||
public List<TaskTimeItem> CalculateTaskTime(List<TaskTimeItem> commits, Settings settings, CancellationToken cancellationToken = default)
|
||||
public List<TaskTimeItem> CalculateTaskTime(List<TaskTimeItem> commits, Settings settings, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
int minutesPerWorkDay = settings.MinuterPerWorkDay + GetRandomMinutes(settings);
|
||||
int workHours = (settings.MinuterPerWorkDay / 60);
|
||||
@@ -99,6 +99,7 @@ namespace JiraTimeBot.TaskTime
|
||||
TimeSpan.FromMinutes(minutes),
|
||||
1,
|
||||
1,
|
||||
"",
|
||||
CommitType.Task);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,20 +19,18 @@ 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 -= 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 timeSpent = appendTime
|
||||
@@ -48,6 +46,7 @@ namespace JiraTimeBot.TaskTime
|
||||
timeSpent,
|
||||
taskGroup.Sum(f => f.Commits),
|
||||
taskGroup.Sum(f => f.FilesAffected),
|
||||
taskGroup.First().ReleaseVersion,
|
||||
taskGroup.First().Type);
|
||||
|
||||
newList.Add(taskTimeItem);
|
||||
|
||||
@@ -19,9 +19,10 @@ namespace JiraTimeBot.TasksProcessors
|
||||
_jiraApi = jiraApi;
|
||||
}
|
||||
|
||||
public void Process(DateTime setForDate, DateTime realDate, List<TaskTimeItem> taskTimes, Settings settings, bool dummyMode, CancellationToken cancellationToken = default)
|
||||
public void Process(DateTime setForDate, DateTime realDate, List<TaskTimeItem> taskTimes, Settings settings, bool dummyMode, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
_log.Trace($"На реальную дату {realDate:dd.MM.yyyy} распределение по задачам:");
|
||||
var totalTime = TimeSpan.FromSeconds(taskTimes.Sum(f => f.TimeSpent.TotalSeconds));
|
||||
_log.Trace($"На реальную дату {realDate:dd.MM.yyyy} распределение по задачам ({totalTime:hh':'mm':'ss}):");
|
||||
|
||||
foreach (var taskTime in taskTimes.Where(f=>f.Type.HasFlag(CommitType.Task)).OrderByDescending(f => f.TimeSpent))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user