Дополнен алгоритм работы с JIRA-задачами
This commit is contained in:
@@ -34,14 +34,13 @@ namespace JiraTimeBot.JiraIntegration
|
||||
}
|
||||
}
|
||||
|
||||
public List<Issue> GetTodayIssues(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public List<Issue> GetIssuesByJQL(string jql, Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
var jira = Jira.CreateRestClient(settings.JiraUrl, settings.JiraUserName, settings.JiraPassword);
|
||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||
|
||||
var userName = settings.JiraUserName;
|
||||
|
||||
var jql = settings.JiraQuery;
|
||||
if (string.IsNullOrEmpty(jql))
|
||||
{
|
||||
jql = $"status changed by '%USER%' during (\"%DATE%\",\"%DATE%\")";
|
||||
@@ -53,7 +52,7 @@ namespace JiraTimeBot.JiraIntegration
|
||||
try
|
||||
{
|
||||
List<Issue> affectedIssues =
|
||||
jira.Issues.GetIssuesFromJqlAsync(jql, 50, 0, cancellationToken).Result.ToList();
|
||||
jira.Issues.GetIssuesFromJqlAsync(jql, 100, 0, cancellationToken).Result.ToList();
|
||||
return affectedIssues;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Atlassian.Jira;
|
||||
using JiraTimeBot.Configuration;
|
||||
using JiraTimeBot.Mercurial;
|
||||
using JiraTimeBot.Mercurial.Objects;
|
||||
@@ -24,17 +26,52 @@ namespace JiraTimeBot.JiraIntegration
|
||||
{
|
||||
date = date.GetValueOrDefault(DateTime.Now.Date);
|
||||
var workTasks = new List<MercurialCommitItem>();
|
||||
var issues = _jiraApi.GetTodayIssues(settings, date, cancellationToken);
|
||||
var issues = _jiraApi.GetIssuesByJQL(settings.JiraQuery, settings, date, cancellationToken);
|
||||
|
||||
foreach (var issue in issues)
|
||||
{
|
||||
workTasks.Add(new MercurialCommitItem
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Description = issue.Summary,
|
||||
Time = issue.Updated.GetValueOrDefault(date.Value),
|
||||
Branch = issue.Key.Value,
|
||||
FilesAffected = 1
|
||||
});
|
||||
return new List<MercurialCommitItem>();
|
||||
}
|
||||
|
||||
List<Comment> comments = new List<Comment>();
|
||||
if (issue.Type?.Name != "Дубликат")
|
||||
{
|
||||
_log.Trace($"Получаю комментарии по задаче {issue.Key} ({issue.Type?.Name}).");
|
||||
comments = issue.GetCommentsAsync(cancellationToken).Result?.ToList() ?? new List<Comment>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.Trace($"Пропускаю комментарии по задаче {issue.Key} ({issue.Type?.Name}).");
|
||||
}
|
||||
|
||||
var user = settings.JiraUserName;
|
||||
var userComments = comments.Where(f => f.Author.Equals(user, StringComparison.InvariantCultureIgnoreCase)).ToList();
|
||||
|
||||
if (userComments.Any())
|
||||
{
|
||||
foreach (var comment in userComments)
|
||||
{
|
||||
workTasks.Add(new MercurialCommitItem
|
||||
{
|
||||
Description = issue.Summary,
|
||||
Time = issue.Updated.GetValueOrDefault(date.Value),
|
||||
Branch = issue.Key.Value,
|
||||
FilesAffected = 1
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
workTasks.Add(new MercurialCommitItem
|
||||
{
|
||||
Description = issue.Summary,
|
||||
Time = issue.Updated.GetValueOrDefault(date.Value),
|
||||
Branch = issue.Key.Value,
|
||||
FilesAffected = 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return workTasks;
|
||||
|
||||
Reference in New Issue
Block a user