Compare commits

...
3 Commits
7 changed files with 88 additions and 50 deletions
+1 -1
View File
@@ -1 +1 @@
1.0.48 1.0.50
+3 -2
View File
@@ -10,7 +10,7 @@ namespace JiraTimeBot.Configuration
public class Settings public class Settings
{ {
public int MinuterPerWorkDay { get; set; } public int MinuterPerWorkDay { get; set; }
public int RountToMinutes { get; set; } public int RoundToMinutes { get; set; }
public string JiraUrl = "https://myteam.aeroclub.ru"; public string JiraUrl = "https://myteam.aeroclub.ru";
@@ -23,6 +23,7 @@ namespace JiraTimeBot.Configuration
public WorkType WorkType { get; set; } public WorkType WorkType { get; set; }
public string JiraQuery { get; set; } public string JiraQuery { get; set; }
public string TimeControlTask { get; set; } public string TimeControlTask { get; set; }
public int RandomWorkMinutes { get; set; }
public static Settings LoadAndCheck(Action settingsSource, Action<string> errorMessageReporter) public static Settings LoadAndCheck(Action settingsSource, Action<string> errorMessageReporter)
{ {
@@ -60,7 +61,7 @@ namespace JiraTimeBot.Configuration
var errors = new List<string>(); var errors = new List<string>();
message = null; message = null;
if (settings.RountToMinutes == default(int)) if (settings.RoundToMinutes == default(int))
{ {
errors.Add("Укажите округление времени, например, 10 (минут)"); errors.Add("Укажите округление времени, например, 10 (минут)");
} }
+2 -3
View File
@@ -51,8 +51,7 @@ namespace JiraTimeBot.JiraIntegration
try try
{ {
List<Issue> affectedIssues = List<Issue> affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 100, 0, cancellationToken).Result.ToList();
jira.Issues.GetIssuesFromJqlAsync(jql, 100, 0, cancellationToken).Result.ToList();
return affectedIssues; return affectedIssues;
} }
catch (Exception ex) catch (Exception ex)
@@ -177,7 +176,7 @@ namespace JiraTimeBot.JiraIntegration
} }
catch (Exception ex) catch (Exception ex)
{ {
_log.Error($"Не могу добавить Worklog по задаче {taskTimeItem.Branch}: {ex.Message}."); _log.Error($"Не могу добавить Worklog по задаче {taskTimeItem.Branch}: {ex.Message} ({ex.InnerException?.Message}).");
continue; continue;
} }
} }
+31 -31
View File
@@ -1,31 +1,31 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("JiraTimeBot")] [assembly: AssemblyTitle("JiraTimeBot")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JiraTimeBot")] [assembly: AssemblyProduct("JiraTimeBot")]
[assembly: AssemblyCopyright("Copyright © 2019")] [assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")] [assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// 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.48")] [assembly: AssemblyVersion("1.0.50")]
[assembly: AssemblyFileVersion("1.0.48")] [assembly: AssemblyFileVersion("1.0.50")]
[assembly: AssemblyInformationalVersion("1.0.48")] [assembly: AssemblyInformationalVersion("1.0.50")]
@@ -20,7 +20,7 @@ namespace JiraTimeBot.TaskTime
public List<TaskTimeItem> CalculateTaskTime(List<MercurialCommitItem> commits, Settings settings, CancellationToken cancellationToken = default(CancellationToken)) public List<TaskTimeItem> CalculateTaskTime(List<MercurialCommitItem> commits, Settings settings, CancellationToken cancellationToken = default(CancellationToken))
{ {
int minutesPerWorkDay = settings.MinuterPerWorkDay; int minutesPerWorkDay = settings.MinuterPerWorkDay + GetRandomMinutes(settings);
int workHours = (settings.MinuterPerWorkDay / 60); int workHours = (settings.MinuterPerWorkDay / 60);
int totalCommitsCount = commits.Count; int totalCommitsCount = commits.Count;
@@ -30,11 +30,11 @@ namespace JiraTimeBot.TaskTime
} }
//если кол-во коммитов более чем кол-во интервалов - то уменьшим интервал вдвое. //если кол-во коммитов более чем кол-во интервалов - то уменьшим интервал вдвое.
while (totalCommitsCount > (workHours * (60.0 / settings.RountToMinutes))) while (totalCommitsCount > (workHours * (60.0 / settings.RoundToMinutes)))
{ {
settings.RountToMinutes = (int)RoundTo((decimal)(settings.RountToMinutes / 2.0), 5); settings.RoundToMinutes = (int)RoundTo((decimal)(settings.RoundToMinutes / 2.0), 5);
_log.Info($"Слишком много задач - уменьшаю интервал до {settings.RountToMinutes}."); _log.Info($"Слишком много задач - уменьшаю интервал до {settings.RoundToMinutes}.");
if (settings.RountToMinutes == 5) if (settings.RoundToMinutes == 5)
{ {
break; break;
} }
@@ -65,7 +65,7 @@ namespace JiraTimeBot.TaskTime
} }
int currentTaskCommits = taskGroup.Count(); int currentTaskCommits = taskGroup.Count();
int currentTaskTime = (int)RoundTo(minutesPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RountToMinutes); int currentTaskTime = (int)RoundTo(minutesPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RoundToMinutes);
remainMinutes = remainMinutes - currentTaskTime; remainMinutes = remainMinutes - currentTaskTime;
var orderedTasks = taskGroup.OrderBy(f => f.Time).ToArray(); var orderedTasks = taskGroup.OrderBy(f => f.Time).ToArray();
@@ -110,6 +110,14 @@ namespace JiraTimeBot.TaskTime
return workTimeItems; return workTimeItems;
} }
private int GetRandomMinutes(Settings settings)
{
var rand = new Random();
int randomIntervals = settings.RandomWorkMinutes / settings.RoundToMinutes;
int randomMinutes = rand.Next(0, randomIntervals + 1) * settings.RoundToMinutes;
return randomMinutes;
}
private void PrintTotal(List<TaskTimeItem> workTimeItems) private void PrintTotal(List<TaskTimeItem> workTimeItems)
{ {
var totalTime = TimeSpan.Zero; var totalTime = TimeSpan.Zero;
+28 -4
View File
@@ -51,6 +51,8 @@
this.chkAutostart = new System.Windows.Forms.CheckBox(); this.chkAutostart = new System.Windows.Forms.CheckBox();
this.lblWorkDay = new System.Windows.Forms.Label(); this.lblWorkDay = new System.Windows.Forms.Label();
this.txtWorkDayDuration = new System.Windows.Forms.TextBox(); this.txtWorkDayDuration = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.txtRandomMinutes = new System.Windows.Forms.TextBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// label5 // label5
@@ -78,6 +80,7 @@
this.label4.Size = new System.Drawing.Size(76, 13); this.label4.Size = new System.Drawing.Size(76, 13);
this.label4.TabIndex = 26; this.label4.TabIndex = 26;
this.label4.Text = "Путь до репо:"; this.label4.Text = "Путь до репо:";
this.label4.TextAlign = System.Drawing.ContentAlignment.TopRight;
// //
// txtRepoPath // txtRepoPath
// //
@@ -94,6 +97,7 @@
this.label2.Size = new System.Drawing.Size(82, 13); this.label2.Size = new System.Drawing.Size(82, 13);
this.label2.TabIndex = 24; this.label2.TabIndex = 24;
this.label2.Text = "Mercurial name:"; this.label2.Text = "Mercurial name:";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
// //
// txtMercurialEmail // txtMercurialEmail
// //
@@ -155,7 +159,7 @@
// chkAddComments // chkAddComments
// //
this.chkAddComments.AutoSize = true; this.chkAddComments.AutoSize = true;
this.chkAddComments.Location = new System.Drawing.Point(65, 308); this.chkAddComments.Location = new System.Drawing.Point(65, 336);
this.chkAddComments.Name = "chkAddComments"; this.chkAddComments.Name = "chkAddComments";
this.chkAddComments.Size = new System.Drawing.Size(133, 17); this.chkAddComments.Size = new System.Drawing.Size(133, 17);
this.chkAddComments.TabIndex = 31; this.chkAddComments.TabIndex = 31;
@@ -164,7 +168,7 @@
// //
// btnSave // btnSave
// //
this.btnSave.Location = new System.Drawing.Point(86, 331); this.btnSave.Location = new System.Drawing.Point(86, 359);
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;
@@ -229,7 +233,7 @@
// chkAutostart // chkAutostart
// //
this.chkAutostart.AutoSize = true; this.chkAutostart.AutoSize = true;
this.chkAutostart.Location = new System.Drawing.Point(65, 285); this.chkAutostart.Location = new System.Drawing.Point(65, 313);
this.chkAutostart.Name = "chkAutostart"; this.chkAutostart.Name = "chkAutostart";
this.chkAutostart.Size = new System.Drawing.Size(96, 17); this.chkAutostart.Size = new System.Drawing.Size(96, 17);
this.chkAutostart.TabIndex = 40; this.chkAutostart.TabIndex = 40;
@@ -252,11 +256,29 @@
this.txtWorkDayDuration.Size = new System.Drawing.Size(99, 20); this.txtWorkDayDuration.Size = new System.Drawing.Size(99, 20);
this.txtWorkDayDuration.TabIndex = 41; this.txtWorkDayDuration.TabIndex = 41;
// //
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(30, 284);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(101, 13);
this.label9.TabIndex = 44;
this.label9.Text = "Рандомных минут:";
//
// txtRandomMinutes
//
this.txtRandomMinutes.Location = new System.Drawing.Point(133, 280);
this.txtRandomMinutes.Name = "txtRandomMinutes";
this.txtRandomMinutes.Size = new System.Drawing.Size(99, 20);
this.txtRandomMinutes.TabIndex = 43;
//
// 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, 362); this.ClientSize = new System.Drawing.Size(243, 391);
this.Controls.Add(this.label9);
this.Controls.Add(this.txtRandomMinutes);
this.Controls.Add(this.lblWorkDay); this.Controls.Add(this.lblWorkDay);
this.Controls.Add(this.txtWorkDayDuration); this.Controls.Add(this.txtWorkDayDuration);
this.Controls.Add(this.chkAutostart); this.Controls.Add(this.chkAutostart);
@@ -316,5 +338,7 @@
private System.Windows.Forms.CheckBox chkAutostart; private System.Windows.Forms.CheckBox chkAutostart;
private System.Windows.Forms.Label lblWorkDay; private System.Windows.Forms.Label lblWorkDay;
private System.Windows.Forms.TextBox txtWorkDayDuration; private System.Windows.Forms.TextBox txtWorkDayDuration;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtRandomMinutes;
} }
} }
+9 -3
View File
@@ -34,11 +34,12 @@ namespace JiraTimeBot.UI
txtRepoPath.Text = settings.RepositoryPath; txtRepoPath.Text = settings.RepositoryPath;
actTime.Text = settings.ActivationTime.ToString("hh\\:mm\\:ss"); actTime.Text = settings.ActivationTime.ToString("hh\\:mm\\:ss");
chkAddComments.Checked = settings.AddCommentsToWorklog; chkAddComments.Checked = settings.AddCommentsToWorklog;
txtRoundTo.Text = settings.RountToMinutes.ToString(); txtRoundTo.Text = settings.RoundToMinutes.ToString();
cboWorkType.SelectedIndex = (int) settings.WorkType; cboWorkType.SelectedIndex = (int) settings.WorkType;
txtTimeControlTask.Text = settings.TimeControlTask; txtTimeControlTask.Text = settings.TimeControlTask;
txtJQL.Text = settings.JiraQuery; txtJQL.Text = settings.JiraQuery;
txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString(); txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString();
txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString();
cboWorkType_SelectedIndexChanged(null, null); cboWorkType_SelectedIndexChanged(null, null);
} }
@@ -53,6 +54,10 @@ namespace JiraTimeBot.UI
{ {
minuterPerWorkDay = 8 * 60; minuterPerWorkDay = 8 * 60;
} }
if (!int.TryParse(txtRandomMinutes.Text, out var randomWorkMinutes))
{
randomWorkMinutes = 0;
}
var settings = new Settings var settings = new Settings
{ {
@@ -62,11 +67,12 @@ namespace JiraTimeBot.UI
ActivationTime = TimeSpan.Parse(actTime.Text), ActivationTime = TimeSpan.Parse(actTime.Text),
RepositoryPath = txtRepoPath.Text, RepositoryPath = txtRepoPath.Text,
AddCommentsToWorklog = chkAddComments.Checked, AddCommentsToWorklog = chkAddComments.Checked,
RountToMinutes = roundTo, RoundToMinutes = roundTo,
WorkType = (WorkType) cboWorkType.SelectedIndex, WorkType = (WorkType) cboWorkType.SelectedIndex,
JiraQuery = txtJQL.Text, JiraQuery = txtJQL.Text,
TimeControlTask = txtTimeControlTask.Text, TimeControlTask = txtTimeControlTask.Text,
MinuterPerWorkDay = minuterPerWorkDay MinuterPerWorkDay = minuterPerWorkDay,
RandomWorkMinutes = randomWorkMinutes
}; };
//LockUnlock(false); //LockUnlock(false);