6
6
using rubberduckvba . Server . ContentSynchronization . XmlDoc . Schema ;
7
7
using rubberduckvba . Server . Model ;
8
8
using System . Collections . Immutable ;
9
+ using System . Diagnostics . CodeAnalysis ;
9
10
using System . Security . Claims ;
10
11
using System . Text ;
11
12
using System . Web ;
@@ -16,13 +17,20 @@ namespace rubberduckvba.Server.Services;
16
17
public interface IGitHubClientService
17
18
{
18
19
Task < ClaimsPrincipal ? > ValidateTokenAsync ( string token ) ;
19
- Task < IEnumerable < TagGraph > > GetAllTagsAsync ( ) ;
20
+ Task < IEnumerable < TagGraph > > GetAllTagsAsync ( string ? dbMainTagName ) ;
20
21
Task < TagGraph > GetTagAsync ( string ? token , string name ) ;
21
22
Task < IEnumerable < InspectionDefaultConfig > > GetCodeAnalysisDefaultsConfigAsync ( ) ;
22
23
}
23
24
24
25
public class GitHubClientService ( IOptions < GitHubSettings > configuration , ILogger < ServiceLogger > logger ) : IGitHubClientService
25
26
{
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
+
26
34
public async Task < ClaimsPrincipal ? > ValidateTokenAsync ( string ? token )
27
35
{
28
36
if ( token is null )
@@ -52,13 +60,18 @@ public class GitHubClientService(IOptions<GitHubSettings> configuration, ILogger
52
60
return new ClaimsPrincipal ( identity ) ;
53
61
}
54
62
55
- public async Task < IEnumerable < TagGraph > > GetAllTagsAsync ( )
63
+ public async Task < IEnumerable < TagGraph > > GetAllTagsAsync ( string ? dbMainTagName )
56
64
{
57
65
var config = configuration . Value ;
58
66
var credentials = new Credentials ( config . OrgToken ) ;
59
67
var client = new GitHubClient ( new ProductHeaderValue ( config . UserAgent ) , new InMemoryCredentialStore ( credentials ) ) ;
60
68
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 ( ) ) ;
62
75
63
76
return ( from release in releases
64
77
let installer = release . Assets . SingleOrDefault ( asset => asset . Name . EndsWith ( ".exe" ) && asset . Name . StartsWith ( "Rubberduck.Setup" ) )
0 commit comments