mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 09:48:37 +00:00
Move remote determination to VersionHelper and format file
Squashed 4 commits: * Nitpick variable naming and add XML doc * Use preferred braces style * Return null directly if unparsed URL is null * Move remote determination to VersionHelper and format file
This commit is contained in:
parent
5bc6d39add
commit
7edef5010d
2 changed files with 50 additions and 43 deletions
|
@ -192,25 +192,7 @@
|
|||
<div class="ui black attached inverted segment">
|
||||
<div class="ui container">
|
||||
@{
|
||||
string? firstRemoteUnparsedUrl = null;
|
||||
string? firstRemoteParsedUrl = null;
|
||||
|
||||
if (VersionHelper.Remotes != null)
|
||||
{
|
||||
firstRemoteUnparsedUrl = VersionHelper.Remotes.FirstOrDefault();
|
||||
}
|
||||
|
||||
if (firstRemoteUnparsedUrl != null)
|
||||
{
|
||||
if (firstRemoteUnparsedUrl.Contains("git@"))
|
||||
{
|
||||
firstRemoteParsedUrl = firstRemoteUnparsedUrl.Replace("git@", "").Replace(":", "/").Split(".git").FirstOrDefault();
|
||||
}
|
||||
else if (firstRemoteUnparsedUrl.Contains("https://"))
|
||||
{
|
||||
firstRemoteParsedUrl = firstRemoteUnparsedUrl.Replace("https://", "").Split(".git").FirstOrDefault();
|
||||
}
|
||||
}
|
||||
string? remoteUrl = VersionHelper.DetermineRemoteUrl();
|
||||
}
|
||||
<span>
|
||||
@Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion)
|
||||
|
@ -224,9 +206,9 @@
|
|||
AGPL-3.0 License
|
||||
</a>
|
||||
·
|
||||
@if (!string.IsNullOrWhiteSpace(firstRemoteParsedUrl))
|
||||
@if (!string.IsNullOrWhiteSpace(remoteUrl))
|
||||
{
|
||||
<a href="https://@firstRemoteParsedUrl" target="_blank">
|
||||
<a href="https://@remoteUrl" target="_blank">
|
||||
Source Code
|
||||
</a>
|
||||
}
|
||||
|
|
|
@ -32,11 +32,8 @@ public static class VersionHelper
|
|||
}
|
||||
catch
|
||||
{
|
||||
Logger.Error
|
||||
(
|
||||
"Project Lighthouse was built incorrectly. Please make sure git is available when building.",
|
||||
LogArea.Startup
|
||||
);
|
||||
Logger.Error("Project Lighthouse was built incorrectly. Please make sure git is available when building.",
|
||||
LogArea.Startup);
|
||||
CommitHash = "invalid";
|
||||
Branch = "invalid";
|
||||
CanCheckForUpdates = false;
|
||||
|
@ -44,37 +41,65 @@ public static class VersionHelper
|
|||
|
||||
if (!IsDirty) return;
|
||||
|
||||
Logger.Warn
|
||||
(
|
||||
"This is a modified version of Project Lighthouse. " +
|
||||
"Please make sure you are properly disclosing the source code to any users who may be using this instance.",
|
||||
LogArea.Startup
|
||||
);
|
||||
Logger.Warn("This is a modified version of Project Lighthouse. " +
|
||||
"Please make sure you are properly disclosing the source code to any users who may be using this instance.",
|
||||
LogArea.Startup);
|
||||
CanCheckForUpdates = false;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Determines the URL of the git remote. This doesn't return a complete URL and it's only really used for the
|
||||
/// "Source Code" hyperlink in the BaseLayout. Use this with caution.
|
||||
/// </summary>
|
||||
public static string? DetermineRemoteUrl()
|
||||
{
|
||||
string? remoteUnparsedUrl = null;
|
||||
string? remoteParsedUrl = null;
|
||||
|
||||
if (Remotes != null) remoteUnparsedUrl = Remotes.FirstOrDefault();
|
||||
if (remoteUnparsedUrl == null) return null;
|
||||
|
||||
if (remoteUnparsedUrl.Contains("git@"))
|
||||
{
|
||||
remoteParsedUrl = remoteUnparsedUrl.Replace("git@", "").Replace(":", "/").Split(".git").FirstOrDefault();
|
||||
}
|
||||
else if (remoteUnparsedUrl.Contains("https://"))
|
||||
{
|
||||
remoteParsedUrl = remoteUnparsedUrl.Replace("https://", "").Split(".git").FirstOrDefault();
|
||||
}
|
||||
|
||||
return remoteParsedUrl;
|
||||
}
|
||||
#nullable disable
|
||||
|
||||
public static string CommitHash { get; set; }
|
||||
public static string Branch { get; set; }
|
||||
/// <summary>
|
||||
/// The full revision string. States current revision hash and, if not main, the branch.
|
||||
/// The full revision string. States current revision hash and, if not main, the branch.
|
||||
/// </summary>
|
||||
public static string FullRevision { get; set; }
|
||||
private static string FullRevision { get; set; }
|
||||
/// <summary>
|
||||
/// The server's branding (environment version) to show to LBP clients. Shows the environment name next to the revision.
|
||||
/// The server's branding (environment version) to show to LBP clients. Shows the environment name next to the
|
||||
/// revision.
|
||||
/// </summary>
|
||||
public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {FullRevision}";
|
||||
public static string FullVersion => $"Project Lighthouse {ServerConfiguration.Instance.Customization.EnvironmentName} {Branch}@{CommitHash} {Build}";
|
||||
public static bool IsDirty => CommitHash.EndsWith("-dirty") || CommitsOutOfDate != 1 || CommitHash == "invalid" || Branch == "invalid";
|
||||
public static string FullVersion =>
|
||||
$"Project Lighthouse {ServerConfiguration.Instance.Customization.EnvironmentName} {Branch}@{CommitHash} {Build}";
|
||||
public static bool IsDirty => CommitHash.EndsWith("-dirty") ||
|
||||
CommitsOutOfDate != 1 ||
|
||||
CommitHash == "invalid" ||
|
||||
Branch == "invalid";
|
||||
public static int CommitsOutOfDate { get; set; }
|
||||
public static bool CanCheckForUpdates { get; set; }
|
||||
public static string[] Remotes { get; set; }
|
||||
|
||||
public const string Build =
|
||||
#if DEBUG
|
||||
#if DEBUG
|
||||
"Debug";
|
||||
#elif RELEASE
|
||||
#elif RELEASE
|
||||
"Release";
|
||||
#else
|
||||
"Unknown";
|
||||
#endif
|
||||
#else
|
||||
"Unknown";
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue