Skip to content

Commit

Permalink
⬆️ Bump files with dotnet-file sync
Browse files Browse the repository at this point in the history
# devlooped/SponsorLink

- Add Grace period info reporting devlooped/SponsorLink@46e9abe
- Fix intellisense for SL resources devlooped/SponsorLink@a4c3bbe
- Make the funding help url configurable via MSBuild devlooped/SponsorLink@efdaa7c
  • Loading branch information
devlooped-bot authored and kzu committed Sep 13, 2024
1 parent 9427a92 commit 11a39df
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 34 deletions.
32 changes: 16 additions & 16 deletions .netconfig
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
url = https://github.com/devlooped/SponsorLink/tree/main/samples/dotnet/
[file "src/SponsorLink/Analyzer/Analyzer.csproj"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/Analyzer/Analyzer.csproj
sha = 7407f5b3461213ae764f53ee93651a34487e458c
etag = 2842ea95c956faa47e997a7d20c39df2efc5b9c4f37fe1c2eeea297ee4ba9889
sha = efdaa7c93cca3bed49aafdca4a1f29e85126c94f
etag = 3a15ca6d1eec97f5280de063a3463dd24eafe47a8a9ac193bc0ecb2603643b6e
weak
[file "src/SponsorLink/Analyzer/Properties/launchSettings.json"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/Analyzer/Properties/launchSettings.json
Expand Down Expand Up @@ -191,8 +191,8 @@
weak
[file "src/SponsorLink/SponsorLink/DiagnosticsManager.cs"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/DiagnosticsManager.cs
sha = 076078a2747b15a61c1003552c5c2677fae08435
etag = 5a9692feffa3fa03fc81769ec6cd8f72460df223993c6f49584a1892cf7a6306
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = 72fe901dd67f30c1b78990599303ec6f409b2021a6da20edd66cc57f5d6e299c
weak
[file "src/SponsorLink/SponsorLink/ManifestStatus.cs"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/ManifestStatus.cs
Expand All @@ -201,13 +201,13 @@
weak
[file "src/SponsorLink/SponsorLink/Resources.es.resx"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/Resources.es.resx
sha = 076078a2747b15a61c1003552c5c2677fae08435
etag = d456d80074ebba8109b914aec9ca31cd6269ea56159adaa7b7bae4497e1e60f7
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = b7c9ab61fd7aa4b27e5bc3b6d3c54e80fabae1f5d0816ada621c48fad7e6db06
weak
[file "src/SponsorLink/SponsorLink/Resources.resx"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/Resources.resx
sha = 076078a2747b15a61c1003552c5c2677fae08435
etag = 3be4a6dc6162f52e33f01110a2739e18fcec8886ca7f4d82e9688fec684f8158
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = 20564ce16ec1b437fc057f78c5e712f88d63979754cbb42b70357a320c254214
weak
[file "src/SponsorLink/SponsorLink/SponsorLink.cs"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/SponsorLink.cs
Expand All @@ -216,13 +216,13 @@
weak
[file "src/SponsorLink/SponsorLink/SponsorLink.csproj"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/SponsorLink.csproj
sha = d5300a8c7cd8df9ce8ee0ef7714e17cfcc5d9454
etag = 88652b0720f718ecedb3768b20b7a59bf38d635b3a1c2278c7603f99cc02b517
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = 9674d70c0042b3b973846d5252d6861a981e1e7b84bc806a8d20698ba0c27481
weak
[file "src/SponsorLink/SponsorLink/SponsorLinkAnalyzer.cs"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/SponsorLinkAnalyzer.cs
sha = ca82a9d6298a933192c5dfd2c5881ebadb85d0fe
etag = 2b4bf43116b7bd745e0415248c94cdae63d8d241f326117c8bcb30d3700c0e46
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = 062a02b6eb45e5e49cc73c77c25d66bf2695fc365e13ce7dc39f813a030fc370
weak
[file "src/SponsorLink/SponsorLink/SponsorStatus.cs"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/SponsorStatus.cs
Expand Down Expand Up @@ -351,8 +351,8 @@
weak
[file "src/SponsorLink/SponsorLink.Analyzer.targets"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink.Analyzer.targets
sha = 3845393462f5a89f90e2c795345d9342bf87dbe2
etag = 08e58ed40ea91fdbe1a798c623f1048955880575fb01e16bfd5003fc288b173b
sha = efdaa7c93cca3bed49aafdca4a1f29e85126c94f
etag = 96480c337e10cdca35957d41b651879b146da30a6e6db234f2bb6f09e88e3a7f
weak
[file "src/SponsorLink/SponsorLink.Analyzer.Tests.targets"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink.Analyzer.Tests.targets
Expand All @@ -361,8 +361,8 @@
weak
[file "src/SponsorLink/SponsorLink/Resources.es-AR.resx"]
url = https://github.com/devlooped/SponsorLink/blob/main/samples/dotnet/SponsorLink/Resources.es-AR.resx
sha = 076078a2747b15a61c1003552c5c2677fae08435
etag = e1bfe540f1e1a33540f79da409e4f5c24069340913966b3d4a074a83ccb7bba0
sha = 46e9abe02e5a6abadda66ef050ddc5b9859aa2b8
etag = f9ee3b0f072504f662def880b10d24865fcab110f797383066737d38980102de
weak
[file ".github/workflows/triage.yml"]
url = https://github.com/devlooped/oss/blob/main/.github/workflows/triage.yml
Expand Down
1 change: 0 additions & 1 deletion src/SponsorLink/Analyzer/Analyzer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Git" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Constants" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Strings" Version="1.4.3" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Project" Version="1.4.3" PrivateAssets="all" />
</ItemGroup>

Expand Down
14 changes: 9 additions & 5 deletions src/SponsorLink/SponsorLink.Analyzer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
<FundingPrefix Condition="'$(FundingPrefix)' == ''">$([System.Text.RegularExpressions.Regex]::Replace("$(FundingProduct)", "[^A-Z]", ""))</FundingPrefix>
<!-- Default grace days for an expired sponsor manifest or unknown status -->
<FundingGrace Condition="'$(FundingGrace)' == ''">15</FundingGrace>
<!-- Url to use as the helpUrl in diagnostics, to learn more about SL -->
<FundingHelpUrl Condition="'$(FundingHelpUrl)' == ''">https://github.com/devlooped#sponsorlink</FundingHelpUrl>

<!-- Strong-naming analyzers is both unnecessary and additionally unsupported by ILRepack when run as a dotnet tool -->
<SignAssembly Condition="'$(MergeAnalyzerAssemblies)' == 'true'">false</SignAssembly>
</PropertyGroup>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)SponsorLink/*.cs"
Expand All @@ -32,11 +34,12 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)SponsorLink/*.resx"
Exclude="$(MSBuildThisFileDirectory)SponsorLink/bin/**;$(MSBuildThisFileDirectory)SponsorLink/obj/**"
Source="SponsorLink"
Type="Resx"
ManifestResourceName="Devlooped.Sponsors.%(Filename)"/>
<EmbeddedResource Update="$(MSBuildThisFileDirectory)SponsorLink/Resources.resx"
StronglyTypedManifestPrefix="Devlooped.Sponsors"
StronglyTypedClassName="%(Filename)"
StronglyTypedNamespace="Devlooped.Sponsors"
<EmbeddedResource Update="$(MSBuildThisFileDirectory)SponsorLink/Resources.resx"
StronglyTypedManifestPrefix="Devlooped.Sponsors"
StronglyTypedClassName="%(Filename)"
StronglyTypedNamespace="Devlooped.Sponsors"
StronglyTypedLanguage="$(Language)" />
<None Include="$(MSBuildThisFileDirectory)SponsorLink/buildTransitive/*.*"
Source="SponsorLink"
Expand Down Expand Up @@ -122,6 +125,7 @@ partial class SponsorLink
public static HashSet&lt;string&gt; PackageIds { get%3B } = [$(_FundingPackageIds)]%3B
public const string Product = "$(FundingProduct)"%3B
public const string Prefix = "$(FundingPrefix)"%3B
public const string HelpUrl = "$(FundingHelpUrl)"%3B
public const int Grace = $(FundingGrace)%3B
}
}
Expand Down
51 changes: 40 additions & 11 deletions src/SponsorLink/SponsorLink/DiagnosticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.IO;
using System.Linq;
using Humanizer;
using Humanizer.Localisation;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using static Devlooped.Sponsors.SponsorLink;
Expand All @@ -29,6 +28,7 @@ class DiagnosticsManager
// <Constant Include="Funding.Product" Value="[PRODUCT_NAME]" />
// <Constant Include="Funding.AnalyzerPrefix" Value="[PREFIX]" />
{ SponsorStatus.Unknown, CreateUnknown([.. Sponsorables.Keys], Funding.Product, Funding.Prefix) },
{ SponsorStatus.Grace, CreateGrace([.. Sponsorables.Keys], Funding.Product, Funding.Prefix) },
{ SponsorStatus.User, CreateSponsor([.. Sponsorables.Keys], Funding.Prefix) },
{ SponsorStatus.Contributor, CreateContributor([.. Sponsorables.Keys], Funding.Prefix) },
// NOTE: organization is a special case of sponsor, but we report it as hidden since the user isn't directly involved.
Expand Down Expand Up @@ -76,12 +76,16 @@ public SponsorStatus GetOrSetStatus(Func<AnalyzerOptions?> options)
=> GetOrSetStatus(() => options().GetSponsorAdditionalFiles(), () => options()?.AnalyzerConfigOptionsProvider.GlobalOptions);

/// <summary>
/// Attemps to remove a diagnostic for the given product.
/// Attemps to get the diagnostic for the given product.
/// </summary>
/// <param name="product">The product diagnostic that might have been pushed previously.</param>
/// <returns>The removed diagnostic, or <see langword="null" /> if none was previously pushed.</returns>
public Diagnostic? Pop(string product = Funding.Product)
public Diagnostic? TryGet(string product = Funding.Product)
{
// Don't pop grace diagnostics, as we report them more than once.
if (GetStatus() == SponsorStatus.Grace && Diagnostics.TryGetValue(product, out var grace))
return grace;

if (Diagnostics.TryRemove(product, out var diagnostic) &&
GetStatus(diagnostic) != SponsorStatus.Grace)
{
Expand Down Expand Up @@ -126,10 +130,16 @@ SponsorStatus GetOrSetStatus(Func<ImmutableArray<AdditionalText>> getAdditionalF

if (installed != default && ((DateTime.Now - installed).TotalDays <= Funding.Grace))
{
// get days until grace expiration
var days = Math.Abs((int)(installed.Date.AddDays(Funding.Grace) - DateTime.Now.Date).TotalDays);
// report unknown, either unparsed manifest or one with no expiration (which we never emit).
return Push(Diagnostic.Create(KnownDescriptors[SponsorStatus.Unknown], null,
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Grace)),
Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)),
return Push(Diagnostic.Create(KnownDescriptors[SponsorStatus.Grace], null,
effectiveSeverity: DiagnosticSeverity.Info,
additionalLocations: null,
properties: ImmutableDictionary.Create<string, string?>()
.Add(nameof(SponsorStatus), nameof(SponsorStatus.Grace))
.Add(nameof(SponsorStatus.Grace), days.ToString()),
days, Funding.Product, Sponsorables.Keys.Humanize(Resources.Or)),
SponsorStatus.Grace);
}
}
Expand All @@ -142,19 +152,25 @@ SponsorStatus GetOrSetStatus(Func<ImmutableArray<AdditionalText>> getAdditionalF
}
else if (exp < DateTime.Now)
{
var days = Math.Abs((int)(exp.AddDays(Funding.Grace) - DateTime.Now).TotalDays);
// report expired or expiring soon if still within the configured days of grace period
if (exp.AddDays(Funding.Grace) < DateTime.Now)
{
// report expiring soon
return Push(Diagnostic.Create(KnownDescriptors[SponsorStatus.Expiring], null,
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Expiring))),
properties: ImmutableDictionary.Create<string, string?>()
.Add(nameof(SponsorStatus), nameof(SponsorStatus.Expiring))
.Add(nameof(SponsorStatus.Expiring), days.ToString())),
SponsorStatus.Expiring);
}
else
{
// report expired
return Push(Diagnostic.Create(KnownDescriptors[SponsorStatus.Expired], null,
properties: ImmutableDictionary.Create<string, string?>().Add(nameof(SponsorStatus), nameof(SponsorStatus.Expired))),
properties: ImmutableDictionary.Create<string, string?>()
.Add(nameof(SponsorStatus), nameof(SponsorStatus.Expired))
// add how many days ago expiration happened
.Add(nameof(SponsorStatus.Expired), days.ToString())),
SponsorStatus.Expired);
}
}
Expand Down Expand Up @@ -202,9 +218,22 @@ SponsorStatus GetOrSetStatus(Func<ImmutableArray<AdditionalText>> getAdditionalF
description: string.Format(CultureInfo.CurrentCulture, Resources.Unknown_Description,
string.Join(", ", sponsorable.Select(x => $"https://github.com/sponsors/{x}")),
string.Join(" ", sponsorable.Select(x => "@" + x))),
helpLinkUri: "https://github.com/devlooped#sponsorlink",
helpLinkUri: Funding.HelpUrl,
WellKnownDiagnosticTags.NotConfigurable, "CompilationEnd");

internal static DiagnosticDescriptor CreateGrace(string[] sponsorable, string product, string prefix) => new(
$"{prefix}101",
Resources.Grace_Title,
Resources.Grace_Message,
"SponsorLink",
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: string.Format(CultureInfo.CurrentCulture, Resources.Grace_Description,
string.Join(", ", sponsorable.Select(x => $"https://github.com/sponsors/{x}")),
string.Join(" ", sponsorable.Select(x => "@" + x))),
helpLinkUri: Funding.HelpUrl,
WellKnownDiagnosticTags.NotConfigurable);

internal static DiagnosticDescriptor CreateExpiring(string[] sponsorable, string prefix) => new(
$"{prefix}101",
Resources.Expiring_Title,
Expand Down Expand Up @@ -235,7 +264,7 @@ SponsorStatus GetOrSetStatus(Func<ImmutableArray<AdditionalText>> getAdditionalF
hidden ? DiagnosticSeverity.Hidden : DiagnosticSeverity.Info,
isEnabledByDefault: true,
description: Resources.Sponsor_Description,
helpLinkUri: "https://github.com/devlooped#sponsorlink",
helpLinkUri: Funding.HelpUrl,
"DoesNotSupportF1Help", "CompilationEnd");

internal static DiagnosticDescriptor CreateContributor(string[] sponsorable, string prefix, bool hidden = false) => new(
Expand All @@ -246,6 +275,6 @@ SponsorStatus GetOrSetStatus(Func<ImmutableArray<AdditionalText>> getAdditionalF
hidden ? DiagnosticSeverity.Hidden : DiagnosticSeverity.Info,
isEnabledByDefault: true,
description: Resources.Contributor_Description,
helpLinkUri: "https://github.com/devlooped#sponsorlink",
helpLinkUri: Funding.HelpUrl,
"DoesNotSupportF1Help", "CompilationEnd");
}
10 changes: 10 additions & 0 deletions src/SponsorLink/SponsorLink/Resources.es-AR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,14 @@ Por favor considerá apoyar el proyecto patrocinando en {0} y ejecutando posteri
<data name="Contributor_Title" xml:space="preserve">
<value>Sos un contribuidor al proyecto, sos groso 💟!</value>
</data>
<data name="Grace_Description" xml:space="preserve">
<value>Patrocinar los proyectos en que dependés asegura que se mantengan activos, y que recibas el apoyo que necesitás. También es muy económico y está disponible en todo el mundo!
Por favor considerá apoyar el proyecto patrocinando en {0} y ejecutando posteriormente 'sponsor sync {1}'.</value>
</data>
<data name="Grace_Message" xml:space="preserve">
<value>El período de prueba finaliza en {0} día(s). Disfrutá y por favor considerá apoyar {1} patrocinando {2} 🙏</value>
</data>
<data name="Grace_Title" xml:space="preserve">
<value>Estado de patrocinio desconocido, período de prueba</value>
</data>
</root>
10 changes: 10 additions & 0 deletions src/SponsorLink/SponsorLink/Resources.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,14 @@ Por favor considera apoyar el proyecto patrocinando en {0} y ejecutando posterio
<data name="Contributor_Title" xml:space="preserve">
<value>Eres un contribuidor al proyecto, eres lo máximo 💟!</value>
</data>
<data name="Grace_Description" xml:space="preserve">
<value>Patrocinar los proyectos en que dependes asegura que se mantengan activos, y que recibas el apoyo que necesitas. También es muy económico y está disponible en todo el mundo!
Por favor considera apoyar el proyecto patrocinando en {0} y ejecutando posteriormente 'sponsor sync {1}'.</value>
</data>
<data name="Grace_Message" xml:space="preserve">
<value>El período de prueba finaliza en {0} día(s). Disfrute y por favor considere apoyar {1} patrocinando {2} 🙏</value>
</data>
<data name="Grace_Title" xml:space="preserve">
<value>Estado de patrocinio desconocido, período de prueba</value>
</data>
</root>
13 changes: 13 additions & 0 deletions src/SponsorLink/SponsorLink/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,17 @@ Please consider supporting the project by sponsoring at {0} and running 'sponsor
<data name="Contributor_Title" xml:space="preserve">
<value>You are a contributor to the project, you rock 💟!</value>
</data>
<data name="Editor_Disabled" xml:space="preserve">
<value>Editor usage of {0} requires an active sponsorship. Learn more at {1}.</value>
</data>
<data name="Grace_Description" xml:space="preserve">
<value>Sponsoring projects you depend on ensures they remain active, and that you get the support you need. It's also super affordable and available worldwide!
Please consider supporting the project by sponsoring at {0} and running 'sponsor sync {1}' afterwards.</value>
</data>
<data name="Grace_Message" xml:space="preserve">
<value>Grace period ends in {0} days. Enjoy and please consider supporting {1} by sponsoring {2} 🙏</value>
</data>
<data name="Grace_Title" xml:space="preserve">
<value>Unknown sponsor status, grace period</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/SponsorLink/SponsorLink/SponsorLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<FundingPrefix Condition="'$(FundingPrefix)' == ''">$([System.Text.RegularExpressions.Regex]::Replace("$(FundingProduct)", "[^A-Z]", ""))</FundingPrefix>
<!-- Default grace days for an expired sponsor manifest -->
<FundingGrace Condition="'$(FundingGrace)' == ''">21</FundingGrace>
<!-- Url to use as the helpUrl in diagnostics, to learn more about SL -->
<FundingHelpUrl Condition="'$(FundingHelpUrl)' == ''">https://github.com/devlooped#sponsorlink</FundingHelpUrl>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -68,6 +70,7 @@ partial class SponsorLink
public static HashSet&lt;string&gt; PackageIds { get%3B } = [$(_FundingPackageIds)]%3B
public const string Product = "$(FundingProduct)"%3B
public const string Prefix = "$(FundingPrefix)"%3B
public const string HelpUrl = "$(FundingHelpUrl)"%3B
public const int Grace = $(FundingGrace)%3B
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SponsorLink/SponsorLink/SponsorLinkAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override void Initialize(AnalysisContext context)
{
if (ctx.Options.AnalyzerConfigOptionsProvider.GlobalOptions.TryGetValue("build_property." + prop, out var package) &&
package?.Length > 0 &&
Diagnostics.Pop() is { } diagnostic)
Diagnostics.TryGet() is { } diagnostic)
{
ctx.ReportDiagnostic(diagnostic);
break;
Expand Down

0 comments on commit 11a39df

Please sign in to comment.