Skip to content

Commit 4fca946

Browse files
committed
Simplify and unify manifest reading implementation
No need for a separate Manifest class, just extend the existing SponsorLink class.
1 parent a0ae727 commit 4fca946

8 files changed

Lines changed: 215 additions & 241 deletions

File tree

src/SponsorLink/SponsorLink/DiagnosticsManager.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ ConcurrentDictionary<string, Diagnostic> Diagnostics
2828
/// <param name="sponsorable">The names of the sponsorable accounts that can be funded for the given product.</param>
2929
/// <param name="product">The product or project developed by the sponsorable(s).</param>
3030
/// <param name="prefix">Custom prefix to use for diagnostic IDs.</param>
31-
/// <param name="kind">The kind of diagnostic to create.</param>
31+
/// <param name="status">The kind of status diagnostic to create.</param>
3232
/// <returns>The given <see cref="DiagnosticDescriptor"/>.</returns>
33-
/// <exception cref="NotImplementedException">The <paramref name="kind"/> is not one of the known ones.</exception>
34-
public DiagnosticDescriptor GetDescriptor(string[] sponsorable, string product, string prefix, DiagnosticKind kind) => kind switch
33+
/// <exception cref="NotImplementedException">The <paramref name="status"/> is not one of the known ones.</exception>
34+
public DiagnosticDescriptor GetDescriptor(string[] sponsorable, string product, string prefix, SponsorStatus status) => status switch
3535
{
36-
DiagnosticKind.Unknown => CreateUnknown(sponsorable, product, prefix),
37-
DiagnosticKind.Sponsor => CreateSponsor(sponsorable, prefix),
38-
DiagnosticKind.Expiring => CreateExpiring(sponsorable, prefix),
39-
DiagnosticKind.Expired => CreateExpired(sponsorable, prefix),
36+
SponsorStatus.Unknown => CreateUnknown(sponsorable, product, prefix),
37+
SponsorStatus.Sponsor => CreateSponsor(sponsorable, prefix),
38+
SponsorStatus.Expiring => CreateExpiring(sponsorable, prefix),
39+
SponsorStatus.Expired => CreateExpired(sponsorable, prefix),
4040
_ => throw new NotImplementedException(),
4141
};
4242

@@ -67,23 +67,23 @@ public Diagnostic Push(string product, Diagnostic diagnostic)
6767
/// Gets the status of the given product based on a previously stored diagnostic.
6868
/// </summary>
6969
/// <param name="product">The product to check status for.</param>
70-
/// <returns>Optional <see cref="DiagnosticKind"/> that was reported, if any.</returns>
71-
public DiagnosticKind? GetStatus(string product)
70+
/// <returns>Optional <see cref="SponsorStatus"/> that was reported, if any.</returns>
71+
public SponsorStatus? GetStatus(string product)
7272
{
7373
// NOTE: the SponsorLinkAnalyzer.SetStatus uses diagnostic properties to store the
7474
// kind of diagnostic as a simple string instead of the enum. We do this so that
7575
// multiple analyzers or versions even across multiple products, which all would
7676
// have their own enum, can still share the same diagnostic kind.
7777
if (Diagnostics.TryGetValue(product, out var diagnostic) &&
78-
diagnostic.Properties.TryGetValue(nameof(DiagnosticKind), out var value))
78+
diagnostic.Properties.TryGetValue(nameof(SponsorStatus), out var value))
7979
{
8080
// Switch on value matching DiagnosticKind names
8181
return value switch
8282
{
83-
nameof(DiagnosticKind.Unknown) => DiagnosticKind.Unknown,
84-
nameof(DiagnosticKind.Sponsor) => DiagnosticKind.Sponsor,
85-
nameof(DiagnosticKind.Expiring) => DiagnosticKind.Expiring,
86-
nameof(DiagnosticKind.Expired) => DiagnosticKind.Expired,
83+
nameof(SponsorStatus.Unknown) => SponsorStatus.Unknown,
84+
nameof(SponsorStatus.Sponsor) => SponsorStatus.Sponsor,
85+
nameof(SponsorStatus.Expiring) => SponsorStatus.Expiring,
86+
nameof(SponsorStatus.Expired) => SponsorStatus.Expired,
8787
_ => null,
8888
};
8989
}

src/SponsorLink/SponsorLink/Manifest.cs

Lines changed: 0 additions & 178 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// <autogenerated />
2+
#nullable enable
3+
namespace Devlooped.Sponsors;
4+
5+
/// <summary>
6+
/// The resulting status from validation.
7+
/// </summary>
8+
public enum ManifestStatus
9+
{
10+
/// <summary>
11+
/// The manifest couldn't be read at all.
12+
/// </summary>
13+
Unknown,
14+
/// <summary>
15+
/// The manifest was read and is valid (not expired and properly signed).
16+
/// </summary>
17+
Valid,
18+
/// <summary>
19+
/// The manifest was read but has expired.
20+
/// </summary>
21+
Expired,
22+
/// <summary>
23+
/// The manifest was read, but its signature is invalid.
24+
/// </summary>
25+
Invalid,
26+
}

0 commit comments

Comments
 (0)