mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Add links to license and source code in footer (#909)
* Display link to source code and license in footer
* Remove " (fetch)" suffix in remote URL
* Use split instead of replace for getting the clean remote URL
* Open license link in new tab as well
* LINQ-ify things and handle potential errors
* Properly detect remote URL type and parse accordingly
Squashed 3 commits:
* Properly detect remote URL type and parse accordingly
* Actually fix broken source code link...maybe
* Attempt to fix broken source code link
* Fix a kokoism
Perhaps we should actually utilize the firstRemoteUnparsedUrl variable instead of getting the FirstOrDefault remote over and over
* Fix missing slash when using an SSH remote
* Assign null to parsed URL variable by default
Thank you clyde discord
* Only perform the null check on the unparsed URL once
Thank you again clyde discord
* Handle exception when there are no defined remotes
* 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
* Add param to include HTTPS prefix in DetermineRemoteUrl method
* Remove warnings from XML doc
Not needed as of c63284cb37
* Properly insert HTTPS prefix into SSH remotes
* Fix license layout and improve git remote parsing
---------
Co-authored-by: Slendy <josh@slendy.pw>
This commit is contained in:
parent
c314e8d340
commit
248f141c65
2 changed files with 64 additions and 24 deletions
|
@ -191,8 +191,28 @@
|
|||
<footer>
|
||||
<div class="ui black attached inverted segment">
|
||||
<div class="ui container">
|
||||
|
||||
<p>@Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion)</p>
|
||||
@{
|
||||
string? remoteUrl = VersionHelper.DetermineRemoteUrl();
|
||||
}
|
||||
<span>
|
||||
@Model.Translate(BaseLayoutStrings.GeneratedBy, VersionHelper.FullVersion)
|
||||
</span>
|
||||
<span style="float: right;">
|
||||
<a href="https://github.com/LBPUnion/ProjectLighthouse/blob/main/LICENSE" target="_blank">
|
||||
AGPL-3.0 License
|
||||
</a>
|
||||
·
|
||||
@if (!string.IsNullOrWhiteSpace(remoteUrl))
|
||||
{
|
||||
<a href="https://@remoteUrl" target="_blank">
|
||||
Source Code
|
||||
</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="ui text red">Cannot Detect Source Code</span>
|
||||
}
|
||||
</span>
|
||||
@if (VersionHelper.IsDirty)
|
||||
{
|
||||
<p>@Model.Translate(BaseLayoutStrings.GeneratedModified)</p>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Logging;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
||||
public static class VersionHelper
|
||||
public static partial class VersionHelper
|
||||
{
|
||||
static VersionHelper()
|
||||
{
|
||||
|
@ -32,11 +33,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 +42,59 @@ 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;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"((git|ssh|http(s)?)|(git@[\w\.-]+))(:(\/\/)?)([\w\.@\:\/\-~]+)((\.git)(\/))?( .+)?")]
|
||||
private static partial Regex GitRemoteRegex();
|
||||
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// Determines the URL of the git remote.
|
||||
/// </summary>
|
||||
public static string? DetermineRemoteUrl()
|
||||
{
|
||||
string? remote = Remotes?.FirstOrDefault();
|
||||
if (remote == null) return null;
|
||||
|
||||
Match match = GitRemoteRegex().Match(remote);
|
||||
|
||||
if (!match.Success || match.Groups.Count != 12) return null;
|
||||
|
||||
return match.Groups[7].Value;
|
||||
}
|
||||
#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