Compare commits

..
5 Commits
10 changed files with 84 additions and 52 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.66 1.0.71
+3 -3
View File
@@ -13,7 +13,7 @@ namespace JiraTimeBot.Configuration
public int RoundToMinutes { get; set; } public int RoundToMinutes { get; set; }
public string JiraUrl = "https://myteam.aeroclub.ru"; public string JiraUrl = "https://myteam.aeroclub.ru";
public bool PullBeforeProcess { get; set; }
public string RepositoryPath { get; set; } public string RepositoryPath { get; set; }
public string MercurialAuthorEmail { get; set; } public string MercurialAuthorEmail { get; set; }
public string JiraUserName { get; set; } public string JiraUserName { get; set; }
@@ -61,7 +61,7 @@ namespace JiraTimeBot.Configuration
var errors = new List<string>(); var errors = new List<string>();
message = null; message = null;
if (settings.RoundToMinutes == default(int)) if (settings.RoundToMinutes == default)
{ {
errors.Add("Укажите округление времени, например, 10 (минут)"); errors.Add("Укажите округление времени, например, 10 (минут)");
} }
@@ -137,7 +137,7 @@ namespace JiraTimeBot.Configuration
File.WriteAllText(settingsPath, settingsString); File.WriteAllText(settingsPath, settingsString);
} }
private static string _settingsFileName = "settings.json"; private static readonly string _settingsFileName = "settings.json";
} }
public enum WorkType public enum WorkType
+5 -5
View File
@@ -42,7 +42,7 @@ namespace JiraTimeBot.JiraIntegration
} }
} }
public List<Issue> GetIssuesByJQL(string jql, Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken)) public List<Issue> GetIssuesByJQL(string jql, Settings settings, DateTime? date = null, CancellationToken cancellationToken = default)
{ {
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword); var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
date = date.GetValueOrDefault(DateTime.Now.Date); date = date.GetValueOrDefault(DateTime.Now.Date);
@@ -69,14 +69,14 @@ namespace JiraTimeBot.JiraIntegration
} }
} }
public List<Issue> GetWorkloggedIssuesByDate(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken)) public List<Issue> GetWorkloggedIssuesByDate(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default)
{ {
date = date.GetValueOrDefault(DateTime.Now.Date); date = date.GetValueOrDefault(DateTime.Now.Date);
var jql = "issueFunction in workLogged(\"on %DATE% by '%USER%'\")"; var jql = "issueFunction in workLogged(\"on %DATE% by '%USER%'\")";
return GetIssuesByJQL(jql, settings, date, cancellationToken); 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)
{ {
var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date); var alreadyLoggedToday = GetWorkloggedIssuesByDate(settings, date);
foreach (var issue in alreadyLoggedToday) foreach (var issue in alreadyLoggedToday)
@@ -85,7 +85,7 @@ namespace JiraTimeBot.JiraIntegration
{ {
var workLogs = issue.GetWorklogsAsync(cancellationToken).Result; var workLogs = issue.GetWorklogsAsync(cancellationToken).Result;
var userWorklogs = workLogs.Where(w => 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(); StringComparison.InvariantCultureIgnoreCase)).ToList();
foreach (var userWorklog in userWorklogs) foreach (var userWorklog in userWorklogs)
{ {
@@ -100,7 +100,7 @@ namespace JiraTimeBot.JiraIntegration
} }
} }
public void SetTodayWorklog(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false, CancellationToken cancellationToken = default(CancellationToken)) public void SetTodayWorklog(List<TaskTimeItem> taskTimeItems, Settings settings, DateTime? date = null, bool dummy = false, bool addCommentsToWorklog = false, CancellationToken cancellationToken = default)
{ {
date = date.GetValueOrDefault(DateTime.Now.Date).Date; date = date.GetValueOrDefault(DateTime.Now.Date).Date;
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword); var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
@@ -13,7 +13,7 @@ namespace JiraTimeBot.JiraIntegration
{ {
List<TaskTimeItem> GetDayWorklogs(DateTime date, List<TaskTimeItem> GetDayWorklogs(DateTime date,
Settings settings, Settings settings,
CancellationToken cancellationToken = default(CancellationToken)); CancellationToken cancellationToken = default);
} }
public class JiraHistory: IJiraHistory public class JiraHistory: IJiraHistory
@@ -27,17 +27,16 @@ namespace JiraTimeBot.JiraIntegration
public List<TaskTimeItem> GetDayWorklogs(DateTime date, public List<TaskTimeItem> GetDayWorklogs(DateTime date,
Settings settings, Settings settings,
CancellationToken cancellationToken = default(CancellationToken)) CancellationToken cancellationToken = default)
{ {
var tasks = _jiraApi.GetIssuesByJQL("status changed by '%USER%' during (\"%DATE%\",\"%DATE%\")", settings, date, cancellationToken); var tasks = _jiraApi.GetIssuesByJQL("worklogDate = \"%DATE%\" and worklogAuthor='%USER%'", settings, date, cancellationToken);
List<TaskTimeItem> resultItems = new List<TaskTimeItem>(); List<TaskTimeItem> resultItems = new List<TaskTimeItem>();
foreach (var issue in tasks) foreach (var issue in tasks)
{ {
var workLogs = issue.GetWorklogsAsync(cancellationToken).Result; var workLogs = issue.GetWorklogsAsync(cancellationToken).Result;
var user = settings.JiraUserName; var user = settings.JiraUserName;
//user = "Zoya.Aleksandridi";
var userWorklogs = workLogs.Where(w => var userWorklogs = workLogs.Where(w =>
w.CreateDate.GetValueOrDefault().Date == date && w.Author.Equals(user, w.StartDate.GetValueOrDefault().Date == date && w.Author.Equals(user,
StringComparison.InvariantCultureIgnoreCase)).ToList(); StringComparison.InvariantCultureIgnoreCase)).ToList();
if (!userWorklogs.Any()) if (!userWorklogs.Any())
{ {
@@ -46,10 +45,14 @@ namespace JiraTimeBot.JiraIntegration
var firstWorklog = userWorklogs.First(); var firstWorklog = userWorklogs.First();
var description = string.Join("\r\n", userWorklogs.Select(f => f.Comment).Distinct()); var description = string.Join(Environment.NewLine, userWorklogs.Select(f => f.Comment).Distinct());
var totalTime = TimeSpan.FromSeconds(userWorklogs.Sum(f => f.TimeSpentInSeconds)); var totalTime = TimeSpan.FromSeconds(userWorklogs.Sum(f => f.TimeSpentInSeconds));
var startDate = firstWorklog?.CreateDate ?? date; var startDate = firstWorklog?.CreateDate ?? date;
var commits = userWorklogs.Sum(f => f.Comment.Count(c => c == '\n')); var commits = userWorklogs.Sum(f => f.Comment.Count(c => c == '\n'));
if (commits == 0)
{
commits = 1;
}
var taskType = CommitType.Task; var taskType = CommitType.Task;
if (description.Contains("Подготовка и публикация")) if (description.Contains("Подготовка и публикация"))
{ {
+1 -1
View File
@@ -79,7 +79,7 @@ namespace JiraTimeBot
mercurial = _mercurialProviders.JiraCommitEmulator; mercurial = _mercurialProviders.JiraCommitEmulator;
} }
List<TaskTimeItem> taskTimes = null; List<TaskTimeItem> taskTimes;
if (!(tasksProcessor is MeetingProcessor)) if (!(tasksProcessor is MeetingProcessor))
{ {
List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken); List<TaskTimeItem> commits = mercurial.GetMercurialLog(settings, realDate, cancellationToken);
+14 -1
View File
@@ -24,7 +24,7 @@ namespace JiraTimeBot.Mercurial
_technicalInfoSkipper = technicalInfoSkipper; _technicalInfoSkipper = technicalInfoSkipper;
} }
public List<TaskTimeItem> GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken)) public List<TaskTimeItem> GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default)
{ {
if (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath)) if (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath))
{ {
@@ -51,6 +51,19 @@ namespace JiraTimeBot.Mercurial
var directoryInfo = new DirectoryInfo(repoDirectory); var directoryInfo = new DirectoryInfo(repoDirectory);
var repo = new Repository(repoDirectory); var repo = new Repository(repoDirectory);
if (settings.PullBeforeProcess)
{
try
{
repo.Pull();
}
catch (Exception ex)
{
_log?.Trace($" - Не получается сделать pull для репозитория: {directoryInfo.Name} - {ex.Message}");
}
}
var logCommand = new LogCommand var logCommand = new LogCommand
{ {
Date = date, Date = date,
+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.66")] [assembly: AssemblyVersion("1.0.71")]
[assembly: AssemblyFileVersion("1.0.66")] [assembly: AssemblyFileVersion("1.0.71")]
[assembly: AssemblyInformationalVersion("1.0.66")] [assembly: AssemblyInformationalVersion("1.0.71")]
@@ -21,7 +21,8 @@ namespace JiraTimeBot.TasksProcessors
public void Process(DateTime setForDate, DateTime realDate, List<TaskTimeItem> taskTimes, Settings settings, bool dummyMode, CancellationToken cancellationToken = default(CancellationToken)) 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)) foreach (var taskTime in taskTimes.Where(f=>f.Type.HasFlag(CommitType.Task)).OrderByDescending(f => f.TimeSpent))
{ {
+15 -2
View File
@@ -53,6 +53,7 @@
this.txtWorkDayDuration = new System.Windows.Forms.TextBox(); this.txtWorkDayDuration = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label(); this.label9 = new System.Windows.Forms.Label();
this.txtRandomMinutes = new System.Windows.Forms.TextBox(); this.txtRandomMinutes = new System.Windows.Forms.TextBox();
this.chkPullBeforeProcess = new System.Windows.Forms.CheckBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// label5 // label5
@@ -168,7 +169,7 @@
// //
// btnSave // btnSave
// //
this.btnSave.Location = new System.Drawing.Point(86, 359); this.btnSave.Location = new System.Drawing.Point(86, 382);
this.btnSave.Name = "btnSave"; this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 32; this.btnSave.TabIndex = 32;
@@ -272,11 +273,22 @@
this.txtRandomMinutes.Size = new System.Drawing.Size(99, 20); this.txtRandomMinutes.Size = new System.Drawing.Size(99, 20);
this.txtRandomMinutes.TabIndex = 43; this.txtRandomMinutes.TabIndex = 43;
// //
// chkPullBeforeProcess
//
this.chkPullBeforeProcess.AutoSize = true;
this.chkPullBeforeProcess.Location = new System.Drawing.Point(65, 359);
this.chkPullBeforeProcess.Name = "chkPullBeforeProcess";
this.chkPullBeforeProcess.Size = new System.Drawing.Size(83, 17);
this.chkPullBeforeProcess.TabIndex = 45;
this.chkPullBeforeProcess.Text = "Делать pull";
this.chkPullBeforeProcess.UseVisualStyleBackColor = true;
//
// frmSettings // frmSettings
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(243, 391); this.ClientSize = new System.Drawing.Size(243, 414);
this.Controls.Add(this.chkPullBeforeProcess);
this.Controls.Add(this.label9); this.Controls.Add(this.label9);
this.Controls.Add(this.txtRandomMinutes); this.Controls.Add(this.txtRandomMinutes);
this.Controls.Add(this.lblWorkDay); this.Controls.Add(this.lblWorkDay);
@@ -340,5 +352,6 @@
private System.Windows.Forms.TextBox txtWorkDayDuration; private System.Windows.Forms.TextBox txtWorkDayDuration;
private System.Windows.Forms.Label label9; private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtRandomMinutes; private System.Windows.Forms.TextBox txtRandomMinutes;
private System.Windows.Forms.CheckBox chkPullBeforeProcess;
} }
} }
+3 -1
View File
@@ -40,6 +40,7 @@ namespace JiraTimeBot.UI
txtJQL.Text = settings.JiraQuery; txtJQL.Text = settings.JiraQuery;
txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString(); txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString();
txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString(); txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString();
chkPullBeforeProcess.Checked = settings.PullBeforeProcess;
cboWorkType_SelectedIndexChanged(null, null); cboWorkType_SelectedIndexChanged(null, null);
} }
@@ -72,7 +73,8 @@ namespace JiraTimeBot.UI
JiraQuery = txtJQL.Text, JiraQuery = txtJQL.Text,
TimeControlTask = txtTimeControlTask.Text, TimeControlTask = txtTimeControlTask.Text,
MinuterPerWorkDay = minuterPerWorkDay, MinuterPerWorkDay = minuterPerWorkDay,
RandomWorkMinutes = randomWorkMinutes RandomWorkMinutes = randomWorkMinutes,
PullBeforeProcess = chkPullBeforeProcess.Checked
}; };
//LockUnlock(false); //LockUnlock(false);