readonly record struct CommitLink(

This commit is contained in:
M-L-Ml 2025-04-21 20:50:23 +02:00
parent 46ae4064f9
commit f381c1cfdb
3 changed files with 78 additions and 84 deletions

View file

@ -8,17 +8,9 @@ namespace SourceGit.Models
/// <summary> /// <summary>
/// Represents a commit link for a remote repository. /// Represents a commit link for a remote repository.
/// </summary> /// </summary>
public class CommitLink public readonly record struct CommitLink(string Name, string URLPrefix)
{ {
public string Name { get; set; }
public string URLPrefix { get; set; }
public CommitLink(string name, string prefix)
{
Name = name;
URLPrefix = prefix;
} }
public readonly record struct ProviderInfo( public readonly record struct ProviderInfo(
string Name, string Name,
string HostPrefix, string HostPrefix,
@ -27,8 +19,9 @@ namespace SourceGit.Models
{ {
public bool IsMatch(string url) => url.StartsWith(HostPrefix, StringComparison.Ordinal); public bool IsMatch(string url) => url.StartsWith(HostPrefix, StringComparison.Ordinal);
} }
public static class CommitLinkDetails // Changed from private to internal to fix CS1527
private static readonly ProviderInfo[] Providers = new[] {
static readonly ProviderInfo[] Providers = new[]
{ {
new ProviderInfo( new ProviderInfo(
"Github", "Github",
@ -97,7 +90,7 @@ namespace SourceGit.Models
/// </summary> /// </summary>
public static List<CommitLink> Get(List<Remote> remotes) public static List<CommitLink> Get(List<Remote> remotes)
{ {
return remotes.Select(remote => return remotes.Select(static remote =>
{ {
var rr = TryCreateCommitLink(remote); var rr = TryCreateCommitLink(remote);
@ -111,7 +104,8 @@ namespace SourceGit.Models
} }
#endif #endif
return rr; return rr;
}).Where(cl => cl != null).ToList(); }).Select(cl => cl.Value) // Convert nullable CommitLink to non-nullable CommitLink
.Where(cl => cl != null).ToList();
} }
#if DEBUG #if DEBUG
@ -144,7 +138,7 @@ namespace SourceGit.Models
return outs.FirstOrDefault(); return outs.FirstOrDefault();
} }
static CommitLink() static CommitLinkDetails()
{ {
//Unit tests , TODO: make normal UnitTests, delete this code. //Unit tests , TODO: make normal UnitTests, delete this code.

View file

@ -134,7 +134,7 @@ namespace SourceGit.ViewModels
public CommitDetail(Repository repo) public CommitDetail(Repository repo)
{ {
_repo = repo; _repo = repo;
WebLinks = Models.CommitLink.Get(repo.Remotes); WebLinks = Models.CommitLinkDetails.Get(repo.Remotes);
} }
public void Cleanup() public void Cleanup()

View file

@ -37,7 +37,7 @@ namespace SourceGit.Views
get => GetValue(SupportsContainsInProperty); get => GetValue(SupportsContainsInProperty);
set => SetValue(SupportsContainsInProperty, value); set => SetValue(SupportsContainsInProperty, value);
} }
//TODO: Maybe some observable container instead List? Add a comment for explanation.
public static readonly StyledProperty<List<Models.CommitLink>> WebLinksProperty = public static readonly StyledProperty<List<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, List<Models.CommitLink>>(nameof(WebLinks)); AvaloniaProperty.Register<CommitBaseInfo, List<Models.CommitLink>>(nameof(WebLinks));