Skip to content

Commit f8d8e62

Browse files
committed
fix tag metadata update blowing up after 10 pre-releases
1 parent 23cefe0 commit f8d8e62

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

rubberduckvba.Server/Services/GitHubClientService.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using rubberduckvba.Server.ContentSynchronization.XmlDoc.Schema;
77
using rubberduckvba.Server.Model;
88
using System.Collections.Immutable;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Security.Claims;
1011
using System.Text;
1112
using System.Web;
@@ -16,13 +17,20 @@ namespace rubberduckvba.Server.Services;
1617
public interface IGitHubClientService
1718
{
1819
Task<ClaimsPrincipal?> ValidateTokenAsync(string token);
19-
Task<IEnumerable<TagGraph>> GetAllTagsAsync();
20+
Task<IEnumerable<TagGraph>> GetAllTagsAsync(string? dbMainTagName);
2021
Task<TagGraph> GetTagAsync(string? token, string name);
2122
Task<IEnumerable<InspectionDefaultConfig>> GetCodeAnalysisDefaultsConfigAsync();
2223
}
2324

2425
public class GitHubClientService(IOptions<GitHubSettings> configuration, ILogger<ServiceLogger> logger) : IGitHubClientService
2526
{
27+
private class ReleaseComparer : IEqualityComparer<Release>
28+
{
29+
public bool Equals(Release? x, Release? y) => x?.Name == y?.Name;
30+
31+
public int GetHashCode([DisallowNull] Release obj) => HashCode.Combine(obj.Name);
32+
}
33+
2634
public async Task<ClaimsPrincipal?> ValidateTokenAsync(string? token)
2735
{
2836
if (token is null)
@@ -52,13 +60,18 @@ public class GitHubClientService(IOptions<GitHubSettings> configuration, ILogger
5260
return new ClaimsPrincipal(identity);
5361
}
5462

55-
public async Task<IEnumerable<TagGraph>> GetAllTagsAsync()
63+
public async Task<IEnumerable<TagGraph>> GetAllTagsAsync(string? dbMainTagName)
5664
{
5765
var config = configuration.Value;
5866
var credentials = new Credentials(config.OrgToken);
5967
var client = new GitHubClient(new ProductHeaderValue(config.UserAgent), new InMemoryCredentialStore(credentials));
6068

61-
var releases = await client.Repository.Release.GetAll(config.OwnerOrg, config.Rubberduck, new ApiOptions { PageCount = 1, PageSize = 10 });
69+
70+
var getReleases = client.Repository.Release.GetAll(config.OwnerOrg, config.Rubberduck, new ApiOptions { PageCount = 1, PageSize = 10 });
71+
var getKnownMain = client.Repository.Release.Get(config.OwnerOrg, config.Rubberduck, dbMainTagName);
72+
await Task.WhenAll(getReleases, getKnownMain);
73+
74+
var releases = (await getReleases).Append(await getKnownMain).ToHashSet(new ReleaseComparer());
6275

6376
return (from release in releases
6477
let installer = release.Assets.SingleOrDefault(asset => asset.Name.EndsWith(".exe") && asset.Name.StartsWith("Rubberduck.Setup"))

0 commit comments

Comments
 (0)