Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
arturcic committed Oct 18, 2019
commit 71fac224e10628185d715cc80cdb4d3c7c9c66c2
6 changes: 4 additions & 2 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ public void NoWarnOnGitVersionYmlFile()
SetupConfigFileContent(string.Empty);

var s = string.Empty;
Action<string> action = info => { s = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => s = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
{
ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
}
Expand Down
18 changes: 12 additions & 6 deletions src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public void WarnOnExistingGitVersionConfigYamlFile(string path)
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.ObsoleteFileName, path);

var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => logOutput = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
{
configFileLocator.Verify(workingPath, repoPath, fileSystem);
}
Expand All @@ -55,8 +57,10 @@ public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path)
SetupConfigFileContent(string.Empty, DefaultConfigFileLocator.DefaultFileName, path);

var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => logOutput = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
{
configFileLocator.Verify(workingPath, repoPath, fileSystem);
}
Expand Down Expand Up @@ -86,8 +90,10 @@ public void NoWarnOnGitVersionYmlFile()
SetupConfigFileContent(string.Empty);

var s = string.Empty;
Action<string> action = info => { s = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => s = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
{
ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
}
Expand Down
13 changes: 7 additions & 6 deletions src/GitVersionCore.Tests/LoggerTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using System;
using NUnit.Framework;
using Shouldly;
using GitVersion.Helpers;

Expand All @@ -16,8 +15,10 @@ public void LoggerObscuresPassword(string protocol)
const string username = "username%40domain.com";
const string password = "password";
var s = string.Empty;
Action<string> action = info => { s = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => s = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
Logger.WriteInfo($"{protocol}://{username}:{password}@workspace.visualstudio.com/DefaultCollection/_git/CAS");

s.Contains(password).ShouldBe(false);
Expand All @@ -27,9 +28,9 @@ public void LoggerObscuresPassword(string protocol)
public void UsernameWithoutPassword()
{
var s = string.Empty;
Action<string> action = info => { s = info; };
void Action(string info) => s = info;
const string repoUrl = "http://[email protected]/DefaultCollection/_git/CAS";
using (Logger.AddLoggersTemporarily(action, action, action, action))
using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
Logger.WriteInfo(repoUrl);

s.Contains(repoUrl).ShouldBe(true);
Expand Down
10 changes: 5 additions & 5 deletions src/GitVersionCore.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using GitVersion.Helpers;

namespace GitVersionCore.Tests
Expand All @@ -14,10 +14,10 @@ public static class ModuleInitializer
public static void Initialize()
{
Logger.SetLoggers(
s => Console.WriteLine(s),
s => Console.WriteLine(s),
s => Console.WriteLine(s),
s => Console.WriteLine(s));
Console.WriteLine,
Console.WriteLine,
Console.WriteLine,
Console.WriteLine);
}
}
}
9 changes: 5 additions & 4 deletions src/GitVersionCore.Tests/NamedConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.IO;
using NUnit.Framework;
using Shouldly;
Expand Down Expand Up @@ -49,8 +48,10 @@ public void NoWarnOnCustomYmlFile()
SetupConfigFileContent(string.Empty);

var s = string.Empty;
Action<string> action = info => { s = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))

void Action(string info) => s = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
{
ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
}
Expand All @@ -63,7 +64,7 @@ public void NoWarnOnCustomYmlFileOutsideRepoPath()
SetupConfigFileContent(string.Empty, path: @"c:\\Unrelated\\path");

var s = string.Empty;
Action<string> action = info => { s = info; };
void action(string info) => s = info;
using (Logger.AddLoggersTemporarily(action, action, action, action))
{
ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
Expand Down
44 changes: 22 additions & 22 deletions src/GitVersionCore/Helpers/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace GitVersion.Helpers
{
public static class Logger
{
static readonly Regex ObscurePasswordRegex = new Regex("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
static string indent = string.Empty;
private static readonly Regex ObscurePasswordRegex = new Regex("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
private static string indent = string.Empty;

static Logger()
{
Expand All @@ -23,7 +23,7 @@ public static IDisposable IndentLog(string operationDescription)
{
var start = DateTime.Now;
WriteInfo("Begin: " + operationDescription);
indent = indent + " ";
indent += " ";
return new ActionDisposable(() =>
{
var length = indent.Length - 2;
Expand All @@ -32,17 +32,6 @@ public static IDisposable IndentLog(string operationDescription)
});
}

static Action<string> ObscurePassword(Action<string> info)
{
void LogAction(string s)
{
s = ObscurePasswordRegex.Replace(s, "$1$2:*******@");
info(s);
}

return LogAction;
}

public static void SetLoggers(Action<string> debug, Action<string> info, Action<string> warn, Action<string> error)
{
if (debug == null) throw new ArgumentNullException(nameof(debug));
Expand Down Expand Up @@ -89,22 +78,33 @@ public static IDisposable AddLoggersTemporarily(Action<string> debug, Action<str
});
}

static Action<string> LogMessage(Action<string> logAction, string level)
private static Action<string> ObscurePassword(Action<string> info)
{
void LogAction(string s)
{
s = ObscurePasswordRegex.Replace(s, "$1$2:*******@");
info(s);
}

return LogAction;
}

private static Action<string> LogMessage(Action<string> logAction, string level)
{
return s => logAction(string.Format(CultureInfo.InvariantCulture, "{0}{1} [{2:MM/dd/yy H:mm:ss:ff}] {3}", indent, level, DateTime.Now, s));
}

public static void Reset()
private static void Reset()
{
WriteDebug = s => { throw new Exception("Debug logger not defined. Attempted to log: " + s); };
WriteInfo = s => { throw new Exception("Info logger not defined. Attempted to log: " + s); };
WriteWarning = s => { throw new Exception("Warning logger not defined. Attempted to log: " + s); };
WriteError = s => { throw new Exception("Error logger not defined. Attempted to log: " + s); };
WriteDebug = s => throw new Exception("Debug logger not defined. Attempted to log: " + s);
WriteInfo = s => throw new Exception("Info logger not defined. Attempted to log: " + s);
WriteWarning = s => throw new Exception("Warning logger not defined. Attempted to log: " + s);
WriteError = s => throw new Exception("Error logger not defined. Attempted to log: " + s);
}

class ActionDisposable : IDisposable
private class ActionDisposable : IDisposable
{
readonly Action action;
private readonly Action action;

public ActionDisposable(Action action)
{
Expand Down