Рефакторинг + DI
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace JiraTimeBotForm.Mercurial
|
||||
{
|
||||
public class CommitSkipper : ICommitSkipper
|
||||
{
|
||||
public bool IsNeedToSkip(string branch, string commitMessage)
|
||||
{
|
||||
if (!branch.Contains("-"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//Пропускаем Close и Merge коммиты
|
||||
if (commitMessage.StartsWith($"Close {branch} ", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
commitMessage.StartsWith($"Merge with ", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JiraTimeBotForm.Mercurial
|
||||
{
|
||||
public interface ICommitSkipper
|
||||
{
|
||||
bool IsNeedToSkip(string branch, string commitMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using JiraTimeBotForm.Configuration;
|
||||
|
||||
namespace JiraTimeBotForm.Mercurial
|
||||
{
|
||||
public interface IMercurialLog
|
||||
{
|
||||
List<MercurialCommitItem> GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,15 @@ using Mercurial;
|
||||
|
||||
namespace JiraTimeBotForm.Mercurial
|
||||
{
|
||||
public class MercurialLog
|
||||
public class MercurialLog: IMercurialLog
|
||||
{
|
||||
private readonly ILog _log;
|
||||
private readonly ICommitSkipper _commitSkipper;
|
||||
|
||||
public MercurialLog(ILog log)
|
||||
public MercurialLog(ILog log, ICommitSkipper commitSkipper)
|
||||
{
|
||||
_log = log;
|
||||
_commitSkipper = commitSkipper;
|
||||
}
|
||||
|
||||
public List<MercurialCommitItem> GetMercurialLog(Settings settings, DateTime? date = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||
@@ -54,7 +56,7 @@ namespace JiraTimeBotForm.Mercurial
|
||||
}
|
||||
|
||||
var commitMessage = FixEncoding(changeset.CommitMessage);
|
||||
if (IsNeedToSkip(changeset.Branch, commitMessage))
|
||||
if (_commitSkipper.IsNeedToSkip(changeset.Branch, commitMessage))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -113,23 +115,6 @@ namespace JiraTimeBotForm.Mercurial
|
||||
return message;
|
||||
}
|
||||
|
||||
private bool IsNeedToSkip(string branch, string commitMessage)
|
||||
{
|
||||
if (!branch.Contains("-"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//Пропускаем Close и Merge коммиты
|
||||
if (commitMessage.StartsWith($"Close {branch} ", StringComparison.InvariantCultureIgnoreCase) ||
|
||||
commitMessage.StartsWith($"Merge with ", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string FixEncoding(string source)
|
||||
{
|
||||
//перекодируем сообщение - ибо оно криво забирается в 1252
|
||||
|
||||
Reference in New Issue
Block a user