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 black attached inverted segment">
|
||||||
<div class="ui container">
|
<div class="ui container">
|
||||||
@{
|
@{
|
||||||
string? firstRemoteUnparsedUrl = null;
|
string? remoteUrl = VersionHelper.DetermineRemoteUrl();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
<span>
|
<span>
|
||||||
@Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion)
|
@Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion)
|
||||||
|
@ -224,11 +206,11 @@
|
||||||
AGPL-3.0 License
|
AGPL-3.0 License
|
||||||
</a>
|
</a>
|
||||||
·
|
·
|
||||||
@if (!string.IsNullOrWhiteSpace(firstRemoteParsedUrl))
|
@if (!string.IsNullOrWhiteSpace(remoteUrl))
|
||||||
{
|
{
|
||||||
<a href="https://@firstRemoteParsedUrl" target="_blank">
|
<a href="https://@remoteUrl" target="_blank">
|
||||||
Source Code
|
Source Code
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,11 +32,8 @@ public static class VersionHelper
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Logger.Error
|
Logger.Error("Project Lighthouse was built incorrectly. Please make sure git is available when building.",
|
||||||
(
|
LogArea.Startup);
|
||||||
"Project Lighthouse was built incorrectly. Please make sure git is available when building.",
|
|
||||||
LogArea.Startup
|
|
||||||
);
|
|
||||||
CommitHash = "invalid";
|
CommitHash = "invalid";
|
||||||
Branch = "invalid";
|
Branch = "invalid";
|
||||||
CanCheckForUpdates = false;
|
CanCheckForUpdates = false;
|
||||||
|
@ -44,37 +41,65 @@ public static class VersionHelper
|
||||||
|
|
||||||
if (!IsDirty) return;
|
if (!IsDirty) return;
|
||||||
|
|
||||||
Logger.Warn
|
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.",
|
||||||
"This is a modified version of Project Lighthouse. " +
|
LogArea.Startup);
|
||||||
"Please make sure you are properly disclosing the source code to any users who may be using this instance.",
|
|
||||||
LogArea.Startup
|
|
||||||
);
|
|
||||||
CanCheckForUpdates = false;
|
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 CommitHash { get; set; }
|
||||||
public static string Branch { get; set; }
|
public static string Branch { get; set; }
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public static string FullRevision { get; set; }
|
private static string FullRevision { get; set; }
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {FullRevision}";
|
public static string EnvVer => $"{ServerConfiguration.Instance.Customization.EnvironmentName} {FullRevision}";
|
||||||
public static string FullVersion => $"Project Lighthouse {ServerConfiguration.Instance.Customization.EnvironmentName} {Branch}@{CommitHash} {Build}";
|
public static string FullVersion =>
|
||||||
public static bool IsDirty => CommitHash.EndsWith("-dirty") || CommitsOutOfDate != 1 || CommitHash == "invalid" || Branch == "invalid";
|
$"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 int CommitsOutOfDate { get; set; }
|
||||||
public static bool CanCheckForUpdates { get; set; }
|
public static bool CanCheckForUpdates { get; set; }
|
||||||
public static string[] Remotes { get; set; }
|
public static string[] Remotes { get; set; }
|
||||||
|
|
||||||
public const string Build =
|
public const string Build =
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
"Debug";
|
"Debug";
|
||||||
#elif RELEASE
|
#elif RELEASE
|
||||||
"Release";
|
"Release";
|
||||||
#else
|
#else
|
||||||
"Unknown";
|
"Unknown";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue