Making Config values lazy loaded so UpdateFiles can be run without setting the GitHub env vars.
This commit is contained in:
parent
2be5e84f87
commit
bdea82e7d5
1 changed files with 25 additions and 27 deletions
|
@ -27,38 +27,36 @@ namespace Microsoft.DotNet.Scripts
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class Config
|
public class Config
|
||||||
{
|
{
|
||||||
public static Config Instance { get; } = Read();
|
public static Config Instance { get; } = new Config();
|
||||||
|
|
||||||
public string UserName { get; set; }
|
private Lazy<string> _userName = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_USER"));
|
||||||
public string Email { get; set; }
|
private Lazy<string> _email = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_EMAIL"));
|
||||||
public string Password { get; set; }
|
private Lazy<string> _password = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PASSWORD"));
|
||||||
public string CoreFxVersionUrl { get; set; }
|
|
||||||
public string GitHubOriginOwner { get; set; }
|
private Lazy<string> _coreFxVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("COREFX_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/dotnet/corefx/release/1.0.0-rc2/LKG.txt"));
|
||||||
public string GitHubUpstreamOwner { get; set; }
|
private Lazy<string> _gitHubOriginOwner;
|
||||||
public string GitHubProject { get; set; }
|
private Lazy<string> _gitHubUpstreamOwner = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet"));
|
||||||
public string GitHubUpstreamBranch { get; set; }
|
private Lazy<string> _gitHubProject = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PROJECT", "cli"));
|
||||||
public string[] GitHubPullRequestNotifications { get; set; }
|
private Lazy<string> _gitHubUpstreamBranch = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "rel/1.0.0"));
|
||||||
|
private Lazy<string[]> _gitHubPullRequestNotifications = new Lazy<string[]>(() =>
|
||||||
|
GetEnvironmentVariable("GITHUB_PULL_REQUEST_NOTIFICATIONS", "")
|
||||||
|
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
|
||||||
|
|
||||||
private static Config Read()
|
private Config()
|
||||||
{
|
{
|
||||||
string userName = GetEnvironmentVariable("GITHUB_USER");
|
_gitHubOriginOwner = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_ORIGIN_OWNER", UserName));
|
||||||
|
|
||||||
return new Config
|
|
||||||
{
|
|
||||||
UserName = userName,
|
|
||||||
Email = GetEnvironmentVariable("GITHUB_EMAIL"),
|
|
||||||
Password = GetEnvironmentVariable("GITHUB_PASSWORD"),
|
|
||||||
|
|
||||||
CoreFxVersionUrl = GetEnvironmentVariable("COREFX_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/dotnet/corefx/release/1.0.0-rc2/LKG.txt"),
|
|
||||||
GitHubOriginOwner = GetEnvironmentVariable("GITHUB_ORIGIN_OWNER", userName),
|
|
||||||
GitHubUpstreamOwner = GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet"),
|
|
||||||
GitHubProject = GetEnvironmentVariable("GITHUB_PROJECT", "cli"),
|
|
||||||
GitHubUpstreamBranch = GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "rel/1.0.0"),
|
|
||||||
GitHubPullRequestNotifications = GetEnvironmentVariable("GITHUB_PULL_REQUEST_NOTIFICATIONS", "")
|
|
||||||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string UserName => _userName.Value;
|
||||||
|
public string Email => _email.Value;
|
||||||
|
public string Password => _password.Value;
|
||||||
|
public string CoreFxVersionUrl => _coreFxVersionUrl.Value;
|
||||||
|
public string GitHubOriginOwner => _gitHubOriginOwner.Value;
|
||||||
|
public string GitHubUpstreamOwner => _gitHubUpstreamOwner.Value;
|
||||||
|
public string GitHubProject => _gitHubProject.Value;
|
||||||
|
public string GitHubUpstreamBranch => _gitHubUpstreamBranch.Value;
|
||||||
|
public string[] GitHubPullRequestNotifications => _gitHubPullRequestNotifications.Value;
|
||||||
|
|
||||||
private static string GetEnvironmentVariable(string name, string defaultValue = null)
|
private static string GetEnvironmentVariable(string name, string defaultValue = null)
|
||||||
{
|
{
|
||||||
string value = Environment.GetEnvironmentVariable(name);
|
string value = Environment.GetEnvironmentVariable(name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue