Skip to content

Commit

Permalink
Added utility class UserNameProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Duft committed Feb 19, 2024
1 parent 14d1f08 commit e2225fd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TODO:

- ...

----------------------------------------------------------------------------------------------------
Links:
Expand Down
19 changes: 11 additions & 8 deletions releasy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5B165FC2-791
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "releasy", "src\releasy\releasy.csproj", "{465C7145-7B4D-4476-B49A-E0BE796FEDFF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "targets", "build\targets.csproj", "{BFC41007-C126-4638-ABE3-7AF6ECB99448}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{17E01B48-449A-4AF6-8B34-4F80A343BC69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "targets", "build\targets.csproj", "{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{465C7145-7B4D-4476-B49A-E0BE796FEDFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{465C7145-7B4D-4476-B49A-E0BE796FEDFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{465C7145-7B4D-4476-B49A-E0BE796FEDFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{465C7145-7B4D-4476-B49A-E0BE796FEDFF}.Release|Any CPU.Build.0 = Release|Any CPU
{BFC41007-C126-4638-ABE3-7AF6ECB99448}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFC41007-C126-4638-ABE3-7AF6ECB99448}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFC41007-C126-4638-ABE3-7AF6ECB99448}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFC41007-C126-4638-ABE3-7AF6ECB99448}.Release|Any CPU.Build.0 = Release|Any CPU
{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{465C7145-7B4D-4476-B49A-E0BE796FEDFF} = {5B165FC2-791D-48B7-8999-024A385AB207}
{68F97F92-9ED2-4BC7-BBA7-C2A63911FD26} = {17E01B48-449A-4AF6-8B34-4F80A343BC69}
EndGlobalSection
EndGlobal
Empty file added samples/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion src/releasy/Changelog/ChangelogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class ChangelogEntry
public string Tag { get; set; } = string.Empty;
public string Message { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; } = DateTime.Now;
public string CreatedBy { get; set; } = Environment.UserName;
public string CreatedBy { get; set; } = UserNameProvider.GetUserName();

public static ChangelogEntry Create(
string issueId,
Expand Down
2 changes: 1 addition & 1 deletion src/releasy/Releasenotes/ReleaseNoteEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal sealed class ReleaseNoteEntry
public string Message { get; set; } = string.Empty;
public string[] Instructions { get; set; } = [];
public DateTime CreatedAt { get; set; } = DateTime.Now;
public string CreatedBy { get; set; } = Environment.UserName;
public string CreatedBy { get; set; } = UserNameProvider.GetUserName();

public static ReleaseNoteEntry Create(
string issueId,
Expand Down
25 changes: 25 additions & 0 deletions src/releasy/Utils/UserNameProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Diagnostics;

namespace tomware.Releasy;

public static class UserNameProvider
{
public static string GetUserName()
{
// 1. try to read the user name from the git username config
using Process proc = new();
proc.StartInfo.FileName = "git";
proc.StartInfo.Arguments = "config user.name";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string? userName = proc.StandardOutput
.ReadToEnd()
.Replace(Environment.NewLine, string.Empty)
.Replace("\n", string.Empty);
proc.WaitForExit();

// 2. try to read the user name from the environment
return userName ?? Environment.UserName;
}
}

0 comments on commit e2225fd

Please sign in to comment.