-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility class UserNameProvider
- Loading branch information
Thomas Duft
committed
Feb 19, 2024
1 parent
14d1f08
commit e2225fd
Showing
6 changed files
with
39 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |