Добавлено получение данных из Jira + настройка округления
This commit is contained in:
@@ -8,6 +8,8 @@ namespace JiraTimeBotForm.Configuration
|
||||
public class Settings
|
||||
{
|
||||
public int MinuterPerWorkDay = 8 * 60;
|
||||
public int RountToMinutes { get; set; }
|
||||
|
||||
public string JiraUrl = "https://myteam.aeroclub.ru";
|
||||
|
||||
public string RepositoryPath { get; set; }
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace JiraTimeBotForm.DI
|
||||
_builder.RegisterType<TechnicalInfoSkipper>().As<ITechnicalInfoSkipper>().AsSelf();
|
||||
|
||||
_builder.RegisterType<MercurialLog>().As<IMercurialLog>().AsSelf();
|
||||
//_builder.RegisterType<JiraCommitEmulator>().As<IMercurialLog>().AsSelf();
|
||||
_builder.RegisterType<JiraCommitEmulator>().As<IMercurialLog>().AsSelf();
|
||||
_builder.RegisterAggregateService<IAllMercurialProviders>();
|
||||
|
||||
_builder.RegisterType<TaskTimeByCommitsCalculator>().As<ITaskTimeCalculator>().AsSelf();
|
||||
|
||||
@@ -38,10 +39,11 @@ namespace JiraTimeBotForm.DI
|
||||
_builder.RegisterType<MeetingProcessor>().AsSelf().As<ITasksProcessor>();
|
||||
_builder.RegisterAggregateService<IAllTasksProcessors>();
|
||||
|
||||
|
||||
_builder.RegisterType<JiraDescriptionSource>().AsSelf().As<IJiraDescriptionSource>();
|
||||
_builder.RegisterType<JiraApi>().AsSelf().AsImplementedInterfaces();
|
||||
|
||||
_builder.Register(c => new Job(c.Resolve<IMercurialLog>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf();
|
||||
_builder.Register(c => new Job(c.Resolve<IAllMercurialProviders>(), c.Resolve<ITaskTimeCalculator>(), c.Resolve<ILog>())).AsSelf();
|
||||
|
||||
var container = _builder.Build();
|
||||
return container;
|
||||
|
||||
@@ -39,7 +39,10 @@ namespace JiraTimeBotForm.JiraIntegration
|
||||
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
|
||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||
|
||||
var jql = $"status changed by '{settings.JiraUserName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value.AddDays(1):yyyy-MM-dd}\")";
|
||||
var userName = settings.JiraUserName;
|
||||
//userName = "Zoya.Aleksandridi";
|
||||
|
||||
var jql = $"status changed by '{userName}' during (\"{date.Value:yyyy-MM-dd}\",\"{date.Value.AddDays(1):yyyy-MM-dd}\")";
|
||||
var affectedIssues = jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList();
|
||||
return affectedIssues;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="Configuration\Settings.cs" />
|
||||
<Compile Include="JiraIntegration\JiraCommitEmulator.cs" />
|
||||
<Compile Include="Mercurial\IAllMercurialProviders.cs" />
|
||||
<Compile Include="Mercurial\Modifiers\ITechnicalInfoSkipper.cs" />
|
||||
<Compile Include="Mercurial\Modifiers\CommitSkipper.cs" />
|
||||
<Compile Include="Mercurial\Modifiers\ICommitSkipper.cs" />
|
||||
@@ -109,7 +110,7 @@
|
||||
<Compile Include="TasksProcessors\MeetingProcessor.cs" />
|
||||
<Compile Include="TasksProcessors\WorkLogTasksProcessor.cs" />
|
||||
<Compile Include="TaskTime\ITaskTimeCalculator.cs" />
|
||||
<Compile Include="TaskTime\TaskTimeDiscoverer.cs" />
|
||||
<Compile Include="TaskTime\TaskTimeByCommitsCalculator.cs" />
|
||||
<Compile Include="TaskTime\Objects\TaskTimeItem.cs" />
|
||||
<Compile Include="UI\Tray\ITrayMenu.cs" />
|
||||
<Compile Include="UI\Tray\RestoreFromTray.cs" />
|
||||
|
||||
+10
-4
@@ -14,13 +14,13 @@ namespace JiraTimeBotForm
|
||||
{
|
||||
class Job
|
||||
{
|
||||
private readonly IMercurialLog _mercurialLog;
|
||||
private readonly IAllMercurialProviders _mercurialProviders;
|
||||
private readonly ITaskTimeCalculator _taskTimeDiscoverer;
|
||||
private readonly ILog _log;
|
||||
|
||||
public Job(IMercurialLog mercurialLog, ITaskTimeCalculator taskTimeDiscoverer, ILog log)
|
||||
public Job(IAllMercurialProviders mercurialProviders, ITaskTimeCalculator taskTimeDiscoverer, ILog log)
|
||||
{
|
||||
_mercurialLog = mercurialLog;
|
||||
_mercurialProviders = mercurialProviders;
|
||||
_taskTimeDiscoverer = taskTimeDiscoverer;
|
||||
_log = log;
|
||||
}
|
||||
@@ -44,7 +44,13 @@ namespace JiraTimeBotForm
|
||||
{
|
||||
DateTime date = DateTime.Now.Date.AddDays(daysDiff);
|
||||
|
||||
List<MercurialCommitItem> commits = _mercurialLog.GetMercurialLog(settings, date, cancellationToken);
|
||||
IMercurialLog mercurial = _mercurialProviders.MercurialLog;
|
||||
if (string.IsNullOrEmpty(settings.RepositoryPath))
|
||||
{
|
||||
_log.Info("Путь до репозитория пуст, использую Jira как источник информации.");
|
||||
mercurial = _mercurialProviders.JiraCommitEmulator;
|
||||
}
|
||||
List<MercurialCommitItem> commits = mercurial.GetMercurialLog(settings, date, cancellationToken);
|
||||
List<TaskTimeItem> taskTimes = _taskTimeDiscoverer.CalculateTaskTime(commits, settings, cancellationToken);
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JiraTimeBotForm.JiraIntegration;
|
||||
|
||||
namespace JiraTimeBotForm.Mercurial
|
||||
{
|
||||
public interface IAllMercurialProviders
|
||||
{
|
||||
MercurialLog MercurialLog { get; }
|
||||
JiraCommitEmulator JiraCommitEmulator { get; }
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,12 @@ namespace JiraTimeBotForm.Mercurial
|
||||
|
||||
public List<MercurialCommitItem> GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (string.IsNullOrEmpty(settings.RepositoryPath) || !Directory.Exists(settings.RepositoryPath))
|
||||
{
|
||||
_log.Error("Папка с репо не сушествует.");
|
||||
return new List<MercurialCommitItem>();
|
||||
}
|
||||
|
||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||
|
||||
var workTasks = new List<MercurialCommitItem>();
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ namespace JiraTimeBotForm.TaskTime
|
||||
}
|
||||
|
||||
int currentTaskCommits = taskGroup.Count();
|
||||
int currentTaskTime = (int)RoundTo(settings.MinuterPerWorkDay / totalCommitsCount * currentTaskCommits);
|
||||
int currentTaskTime = (int)RoundTo(settings.MinuterPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RountToMinutes);
|
||||
remainMinutes = remainMinutes - currentTaskTime;
|
||||
|
||||
var orderedTasks = taskGroup.OrderBy(f => f.Time).ToArray();
|
||||
Generated
+43
-20
@@ -49,19 +49,21 @@
|
||||
this.btnMeeting = new System.Windows.Forms.Button();
|
||||
this.btnCancel = new System.Windows.Forms.Button();
|
||||
this.chkAddComments = new System.Windows.Forms.CheckBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.txtRoundTo = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// actTime
|
||||
//
|
||||
this.actTime.Format = System.Windows.Forms.DateTimePickerFormat.Time;
|
||||
this.actTime.Location = new System.Drawing.Point(94, 120);
|
||||
this.actTime.Location = new System.Drawing.Point(100, 147);
|
||||
this.actTime.Name = "actTime";
|
||||
this.actTime.Size = new System.Drawing.Size(100, 20);
|
||||
this.actTime.TabIndex = 0;
|
||||
//
|
||||
// txtJiraLogin
|
||||
//
|
||||
this.txtJiraLogin.Location = new System.Drawing.Point(94, 42);
|
||||
this.txtJiraLogin.Location = new System.Drawing.Point(100, 42);
|
||||
this.txtJiraLogin.Name = "txtJiraLogin";
|
||||
this.txtJiraLogin.Size = new System.Drawing.Size(100, 20);
|
||||
this.txtJiraLogin.TabIndex = 1;
|
||||
@@ -69,7 +71,7 @@
|
||||
// lbl1
|
||||
//
|
||||
this.lbl1.AutoSize = true;
|
||||
this.lbl1.Location = new System.Drawing.Point(28, 45);
|
||||
this.lbl1.Location = new System.Drawing.Point(34, 45);
|
||||
this.lbl1.Name = "lbl1";
|
||||
this.lbl1.Size = new System.Drawing.Size(60, 13);
|
||||
this.lbl1.TabIndex = 2;
|
||||
@@ -78,7 +80,7 @@
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(21, 71);
|
||||
this.label1.Location = new System.Drawing.Point(27, 71);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(67, 13);
|
||||
this.label1.TabIndex = 4;
|
||||
@@ -86,7 +88,7 @@
|
||||
//
|
||||
// txtJiraPassword
|
||||
//
|
||||
this.txtJiraPassword.Location = new System.Drawing.Point(94, 68);
|
||||
this.txtJiraPassword.Location = new System.Drawing.Point(100, 68);
|
||||
this.txtJiraPassword.Name = "txtJiraPassword";
|
||||
this.txtJiraPassword.PasswordChar = '*';
|
||||
this.txtJiraPassword.Size = new System.Drawing.Size(100, 20);
|
||||
@@ -95,7 +97,7 @@
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(6, 97);
|
||||
this.label2.Location = new System.Drawing.Point(12, 98);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(82, 13);
|
||||
this.label2.TabIndex = 6;
|
||||
@@ -103,7 +105,7 @@
|
||||
//
|
||||
// txtMercurialEmail
|
||||
//
|
||||
this.txtMercurialEmail.Location = new System.Drawing.Point(94, 94);
|
||||
this.txtMercurialEmail.Location = new System.Drawing.Point(100, 95);
|
||||
this.txtMercurialEmail.Name = "txtMercurialEmail";
|
||||
this.txtMercurialEmail.Size = new System.Drawing.Size(100, 20);
|
||||
this.txtMercurialEmail.TabIndex = 5;
|
||||
@@ -111,15 +113,15 @@
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(45, 126);
|
||||
this.label3.Location = new System.Drawing.Point(7, 151);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(43, 13);
|
||||
this.label3.Size = new System.Drawing.Size(87, 13);
|
||||
this.label3.TabIndex = 7;
|
||||
this.label3.Text = "Время:";
|
||||
this.label3.Text = "Время запуска:";
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
this.btnSave.Location = new System.Drawing.Point(82, 169);
|
||||
this.btnSave.Location = new System.Drawing.Point(78, 196);
|
||||
this.btnSave.Name = "btnSave";
|
||||
this.btnSave.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnSave.TabIndex = 8;
|
||||
@@ -130,7 +132,7 @@
|
||||
// label4
|
||||
//
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(12, 19);
|
||||
this.label4.Location = new System.Drawing.Point(18, 19);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(76, 13);
|
||||
this.label4.TabIndex = 10;
|
||||
@@ -138,7 +140,7 @@
|
||||
//
|
||||
// txtRepoPath
|
||||
//
|
||||
this.txtRepoPath.Location = new System.Drawing.Point(94, 16);
|
||||
this.txtRepoPath.Location = new System.Drawing.Point(100, 16);
|
||||
this.txtRepoPath.Name = "txtRepoPath";
|
||||
this.txtRepoPath.Size = new System.Drawing.Size(100, 20);
|
||||
this.txtRepoPath.TabIndex = 9;
|
||||
@@ -150,12 +152,12 @@
|
||||
this.txtLog.Name = "txtLog";
|
||||
this.txtLog.ReadOnly = true;
|
||||
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtLog.Size = new System.Drawing.Size(510, 264);
|
||||
this.txtLog.Size = new System.Drawing.Size(510, 294);
|
||||
this.txtLog.TabIndex = 11;
|
||||
//
|
||||
// btnStart
|
||||
//
|
||||
this.btnStart.Location = new System.Drawing.Point(9, 224);
|
||||
this.btnStart.Location = new System.Drawing.Point(9, 254);
|
||||
this.btnStart.Name = "btnStart";
|
||||
this.btnStart.Size = new System.Drawing.Size(114, 23);
|
||||
this.btnStart.TabIndex = 12;
|
||||
@@ -177,7 +179,7 @@
|
||||
// txtDummyMode
|
||||
//
|
||||
this.txtDummyMode.AutoSize = true;
|
||||
this.txtDummyMode.Location = new System.Drawing.Point(9, 201);
|
||||
this.txtDummyMode.Location = new System.Drawing.Point(9, 231);
|
||||
this.txtDummyMode.Name = "txtDummyMode";
|
||||
this.txtDummyMode.Size = new System.Drawing.Size(114, 17);
|
||||
this.txtDummyMode.TabIndex = 13;
|
||||
@@ -186,7 +188,7 @@
|
||||
//
|
||||
// btnMeeting
|
||||
//
|
||||
this.btnMeeting.Location = new System.Drawing.Point(142, 224);
|
||||
this.btnMeeting.Location = new System.Drawing.Point(142, 254);
|
||||
this.btnMeeting.Name = "btnMeeting";
|
||||
this.btnMeeting.Size = new System.Drawing.Size(70, 23);
|
||||
this.btnMeeting.TabIndex = 14;
|
||||
@@ -197,7 +199,7 @@
|
||||
// btnCancel
|
||||
//
|
||||
this.btnCancel.Enabled = false;
|
||||
this.btnCancel.Location = new System.Drawing.Point(9, 256);
|
||||
this.btnCancel.Location = new System.Drawing.Point(9, 286);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(203, 23);
|
||||
this.btnCancel.TabIndex = 15;
|
||||
@@ -208,18 +210,37 @@
|
||||
// chkAddComments
|
||||
//
|
||||
this.chkAddComments.AutoSize = true;
|
||||
this.chkAddComments.Location = new System.Drawing.Point(61, 146);
|
||||
this.chkAddComments.Location = new System.Drawing.Point(45, 175);
|
||||
this.chkAddComments.Name = "chkAddComments";
|
||||
this.chkAddComments.Size = new System.Drawing.Size(133, 17);
|
||||
this.chkAddComments.TabIndex = 16;
|
||||
this.chkAddComments.Text = "Добавлять описание";
|
||||
this.chkAddComments.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(-2, 124);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(96, 13);
|
||||
this.label5.TabIndex = 18;
|
||||
this.label5.Text = "Округл. времени:";
|
||||
//
|
||||
// txtRoundTo
|
||||
//
|
||||
this.txtRoundTo.Location = new System.Drawing.Point(100, 121);
|
||||
this.txtRoundTo.Name = "txtRoundTo";
|
||||
this.txtRoundTo.Size = new System.Drawing.Size(100, 20);
|
||||
this.txtRoundTo.TabIndex = 17;
|
||||
this.txtRoundTo.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
|
||||
//
|
||||
// frmMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(740, 292);
|
||||
this.ClientSize = new System.Drawing.Size(740, 318);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.txtRoundTo);
|
||||
this.Controls.Add(this.chkAddComments);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Controls.Add(this.btnMeeting);
|
||||
@@ -270,6 +291,8 @@
|
||||
private System.Windows.Forms.Button btnMeeting;
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
private System.Windows.Forms.CheckBox chkAddComments;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.TextBox txtRoundTo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@ namespace JiraTimeBotForm.UI
|
||||
|
||||
public Settings ReadSettingsAndLock()
|
||||
{
|
||||
if (!int.TryParse(txtRoundTo.Text, out var roundTo))
|
||||
{
|
||||
roundTo = 15;
|
||||
}
|
||||
|
||||
var settings = new Settings
|
||||
{
|
||||
JiraUserName = txtJiraLogin.Text,
|
||||
@@ -68,6 +73,7 @@ namespace JiraTimeBotForm.UI
|
||||
RepositoryPath = txtRepoPath.Text,
|
||||
DummyMode = txtDummyMode.Checked,
|
||||
AddCommentsToWorklog = chkAddComments.Checked,
|
||||
RountToMinutes = roundTo
|
||||
};
|
||||
|
||||
LockUnlock(false);
|
||||
@@ -119,18 +125,13 @@ namespace JiraTimeBotForm.UI
|
||||
actTime.Text = settings.ActivationTime.ToString("hh\\:mm\\:ss");
|
||||
txtDummyMode.Checked = settings.DummyMode;
|
||||
chkAddComments.Checked = settings.AddCommentsToWorklog;
|
||||
txtRoundTo.Text = settings.RountToMinutes.ToString();
|
||||
}
|
||||
|
||||
private async void btnStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
var settings = ReadSettingsAndLock();
|
||||
|
||||
if (!Directory.Exists(settings.RepositoryPath))
|
||||
{
|
||||
MessageBox.Show("Папка с репо не сушествует.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
using (_tokenSource = GetTokenSource())
|
||||
{
|
||||
await _job.DoTheJob(settings, _tasksProcessors.WorkLogTasksProcessor, _tokenSource.Token);
|
||||
@@ -208,5 +209,10 @@ namespace JiraTimeBotForm.UI
|
||||
{
|
||||
_tokenSource.Cancel();
|
||||
}
|
||||
|
||||
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user