Skip to content

Commit bb7889d

Browse files
authored
Merge pull request #70 from rubberduck-vba/webhook
Fix tag updates
2 parents 5a7a945 + 0a5fa5d commit bb7889d

File tree

7 files changed

+144
-73
lines changed

7 files changed

+144
-73
lines changed

rubberduckvba.Server/ContentSynchronization/Pipeline/Abstract/SynchronizationPipelineFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public ISynchronizationPipeline<SyncContext, bool> Create<TParameters>(TParamete
5454
return parameters switch
5555
{
5656
XmldocSyncRequestParameters => new SynchronizeXmlPipeline(parameters, _logger, _content, _github, _merge, _staging, _markdown, tokenSource, _inspections, _quickfixes, _annotations, _annotationParser, _quickFixParser, _inspectionParser, _tagServices),
57-
TagSyncRequestParameters => new SynchronizeTagsPipeline(parameters, _logger, _content, _github, _merge, _staging, tokenSource),
57+
TagSyncRequestParameters => new SynchronizeTagsPipeline(parameters, _logger, _content, _tagServices, _github, _merge, _staging, tokenSource),
5858
_ => throw new NotSupportedException(),
5959
};
6060
}

rubberduckvba.Server/ContentSynchronization/Pipeline/Sections/SyncTags/LoadGitHubTagsBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public LoadGitHubTagsBlock(PipelineSection<SyncContext> parent, CancellationToke
1616

1717
public override async Task<SyncContext> TransformAsync(SyncContext input)
1818
{
19-
var githubTags = await _github.GetAllTagsAsync(Context.RubberduckDbMain.Name);
19+
var githubTags = await _github.GetAllTagsAsync();
2020
var (gitHubMain, gitHubNext, gitHubOthers) = githubTags.GetLatestTags();
2121

2222
Context.LoadGitHubTags(gitHubMain, gitHubNext, gitHubOthers);

rubberduckvba.Server/ContentSynchronization/Pipeline/Sections/SyncTags/SyncTagsSection.cs

Lines changed: 124 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,147 @@
22
using rubberduckvba.Server.ContentSynchronization.Pipeline.Sections.Context;
33
using rubberduckvba.Server.Model;
44
using rubberduckvba.Server.Services;
5+
using rubberduckvba.Server.Services.rubberduckdb;
56
using System.Threading.Tasks.Dataflow;
67

78
namespace rubberduckvba.Server.ContentSynchronization.Pipeline.Sections.SyncTags;
89

910
public class SyncTagsSection : PipelineSection<SyncContext>
1011
{
11-
public SyncTagsSection(IPipeline<SyncContext, bool> parent, CancellationTokenSource tokenSource, ILogger logger, IRubberduckDbService content, IGitHubClientService github, IStagingServices staging)
12+
public SyncTagsSection(IPipeline<SyncContext, bool> parent, CancellationTokenSource tokenSource, ILogger logger, TagServices tagServices, IGitHubClientService github, IStagingServices staging)
1213
: base(parent, tokenSource, logger)
1314
{
14-
ReceiveRequest = new ReceiveRequestBlock(this, tokenSource, logger);
15-
BroadcastParameters = new BroadcastParametersBlock(this, tokenSource, logger);
16-
AcquireDbMainTag = new AcquireDbMainTagGraphBlock(this, tokenSource, content, logger);
17-
AcquireDbNextTag = new AcquireDbNextTagGraphBlock(this, tokenSource, content, logger);
18-
JoinDbTags = new DataflowJoinBlock<TagGraph, TagGraph>(this, tokenSource, logger, nameof(JoinDbTags));
19-
LoadDbTags = new LoadDbLatestTagsBlock(this, tokenSource, logger);
20-
LoadGitHubTags = new LoadGitHubTagsBlock(this, tokenSource, github, logger);
21-
JoinTags = new DataflowJoinBlock<SyncContext, SyncContext>(this, tokenSource, logger, nameof(JoinTags));
22-
BroadcastTags = new BroadcastTagsBlock(this, tokenSource, logger);
23-
StreamGitHubTags = new StreamGitHubTagsBlock(this, tokenSource, logger);
24-
GetTagAssets = new GetTagAssetsBlock(this, tokenSource, github, logger);
25-
TagBuffer = new TagBufferBlock(this, tokenSource, logger);
26-
AccumulateProcessedTags = new AccumulateProcessedTagsBlock(this, tokenSource, logger);
27-
SaveTags = new BulkSaveStagingBlock(this, tokenSource, staging, logger);
15+
SynchronizeTags = new SynchronizeTagsBlock(this, tokenSource, logger, tagServices, github);
16+
//ReceiveRequest = new ReceiveRequestBlock(this, tokenSource, logger);
17+
//BroadcastParameters = new BroadcastParametersBlock(this, tokenSource, logger);
18+
//AcquireDbMainTag = new AcquireDbMainTagGraphBlock(this, tokenSource, content, logger);
19+
//AcquireDbNextTag = new AcquireDbNextTagGraphBlock(this, tokenSource, content, logger);
20+
//JoinDbTags = new DataflowJoinBlock<TagGraph, TagGraph>(this, tokenSource, logger, nameof(JoinDbTags));
21+
//LoadDbTags = new LoadDbLatestTagsBlock(this, tokenSource, logger);
22+
//LoadGitHubTags = new LoadGitHubTagsBlock(this, tokenSource, github, logger);
23+
//JoinTags = new DataflowJoinBlock<SyncContext, SyncContext>(this, tokenSource, logger, nameof(JoinTags));
24+
//BroadcastTags = new BroadcastTagsBlock(this, tokenSource, logger);
25+
//StreamGitHubTags = new StreamGitHubTagsBlock(this, tokenSource, logger);
26+
//GetTagAssets = new GetTagAssetsBlock(this, tokenSource, github, logger);
27+
//TagBuffer = new TagBufferBlock(this, tokenSource, logger);
28+
//AccumulateProcessedTags = new AccumulateProcessedTagsBlock(this, tokenSource, logger);
29+
//SaveTags = new BulkSaveStagingBlock(this, tokenSource, staging, logger);
2830
}
2931

30-
#region blocks
31-
private ReceiveRequestBlock ReceiveRequest { get; }
32-
private BroadcastParametersBlock BroadcastParameters { get; }
33-
private AcquireDbMainTagGraphBlock AcquireDbMainTag { get; }
34-
private AcquireDbNextTagGraphBlock AcquireDbNextTag { get; }
35-
private DataflowJoinBlock<TagGraph, TagGraph> JoinDbTags { get; }
36-
private LoadDbLatestTagsBlock LoadDbTags { get; }
37-
private LoadGitHubTagsBlock LoadGitHubTags { get; }
38-
private DataflowJoinBlock<SyncContext, SyncContext> JoinTags { get; }
39-
private BroadcastTagsBlock BroadcastTags { get; }
40-
private StreamGitHubTagsBlock StreamGitHubTags { get; }
41-
private GetTagAssetsBlock GetTagAssets { get; }
42-
private TagBufferBlock TagBuffer { get; }
43-
private AccumulateProcessedTagsBlock AccumulateProcessedTags { get; }
44-
private BulkSaveStagingBlock SaveTags { get; }
32+
//#region blocks
33+
private SynchronizeTagsBlock SynchronizeTags { get; }
34+
//private ReceiveRequestBlock ReceiveRequest { get; }
35+
//private BroadcastParametersBlock BroadcastParameters { get; }
36+
//private AcquireDbMainTagGraphBlock AcquireDbMainTag { get; }
37+
//private AcquireDbNextTagGraphBlock AcquireDbNextTag { get; }
38+
//private DataflowJoinBlock<TagGraph, TagGraph> JoinDbTags { get; }
39+
//private LoadDbLatestTagsBlock LoadDbTags { get; }
40+
//private LoadGitHubTagsBlock LoadGitHubTags { get; }
41+
//private DataflowJoinBlock<SyncContext, SyncContext> JoinTags { get; }
42+
//private BroadcastTagsBlock BroadcastTags { get; }
43+
//private StreamGitHubTagsBlock StreamGitHubTags { get; }
44+
//private GetTagAssetsBlock GetTagAssets { get; }
45+
//private TagBufferBlock TagBuffer { get; }
46+
//private AccumulateProcessedTagsBlock AccumulateProcessedTags { get; }
47+
//private BulkSaveStagingBlock SaveTags { get; }
4548

46-
public ITargetBlock<SyncRequestParameters> InputBlock => ReceiveRequest.Block;
47-
public Task OutputTask => SaveTags.Block.Completion;
49+
public ITargetBlock<TagSyncRequestParameters> InputBlock => SynchronizeTags.Block!;
50+
public Task OutputTask => SynchronizeTags.Block.Completion;
4851

4952
protected override IReadOnlyDictionary<string, IDataflowBlock> Blocks => new Dictionary<string, IDataflowBlock>
5053
{
51-
[nameof(ReceiveRequest)] = ReceiveRequest.Block,
52-
[nameof(BroadcastParameters)] = BroadcastParameters.Block,
53-
[nameof(AcquireDbMainTag)] = AcquireDbMainTag.Block,
54-
[nameof(AcquireDbNextTag)] = AcquireDbNextTag.Block,
55-
[nameof(JoinDbTags)] = JoinDbTags.Block,
56-
[nameof(LoadDbTags)] = LoadDbTags.Block,
57-
[nameof(LoadGitHubTags)] = LoadGitHubTags.Block,
58-
[nameof(JoinTags)] = JoinTags.Block,
59-
[nameof(BroadcastTags)] = BroadcastTags.Block,
60-
[nameof(StreamGitHubTags)] = StreamGitHubTags.Block,
61-
[nameof(GetTagAssets)] = GetTagAssets.Block,
62-
[nameof(TagBuffer)] = TagBuffer.Block,
63-
[nameof(AccumulateProcessedTags)] = AccumulateProcessedTags.Block,
64-
[nameof(SaveTags)] = SaveTags.Block,
54+
[nameof(SynchronizeTags)] = SynchronizeTags.Block,
55+
// [nameof(ReceiveRequest)] = ReceiveRequest.Block,
56+
// [nameof(BroadcastParameters)] = BroadcastParameters.Block,
57+
// [nameof(AcquireDbMainTag)] = AcquireDbMainTag.Block,
58+
// [nameof(AcquireDbNextTag)] = AcquireDbNextTag.Block,
59+
// [nameof(JoinDbTags)] = JoinDbTags.Block,
60+
// [nameof(LoadDbTags)] = LoadDbTags.Block,
61+
// [nameof(LoadGitHubTags)] = LoadGitHubTags.Block,
62+
// [nameof(JoinTags)] = JoinTags.Block,
63+
// [nameof(BroadcastTags)] = BroadcastTags.Block,
64+
// [nameof(StreamGitHubTags)] = StreamGitHubTags.Block,
65+
// [nameof(GetTagAssets)] = GetTagAssets.Block,
66+
// [nameof(TagBuffer)] = TagBuffer.Block,
67+
// [nameof(AccumulateProcessedTags)] = AccumulateProcessedTags.Block,
68+
// [nameof(SaveTags)] = SaveTags.Block,
6569
};
66-
#endregion
70+
//#endregion
6771

6872
public override void CreateBlocks()
6973
{
70-
ReceiveRequest.CreateBlock();
71-
BroadcastParameters.CreateBlock(ReceiveRequest);
72-
AcquireDbMainTag.CreateBlock(BroadcastParameters);
73-
AcquireDbNextTag.CreateBlock(BroadcastParameters);
74-
JoinDbTags.CreateBlock(AcquireDbMainTag, AcquireDbNextTag);
75-
LoadDbTags.CreateBlock(JoinDbTags);
76-
LoadGitHubTags.CreateBlock(LoadDbTags);
77-
JoinTags.CreateBlock(LoadDbTags, LoadGitHubTags);
78-
BroadcastTags.CreateBlock(JoinTags);
79-
StreamGitHubTags.CreateBlock(BroadcastTags);
80-
GetTagAssets.CreateBlock(StreamGitHubTags);
81-
TagBuffer.CreateBlock(GetTagAssets);
82-
AccumulateProcessedTags.CreateBlock(TagBuffer);
83-
SaveTags.CreateBlock(AccumulateProcessedTags);
74+
SynchronizeTags.CreateBlock();
75+
//ReceiveRequest.CreateBlock();
76+
//BroadcastParameters.CreateBlock(ReceiveRequest);
77+
//AcquireDbMainTag.CreateBlock(BroadcastParameters);
78+
//AcquireDbNextTag.CreateBlock(BroadcastParameters);
79+
//JoinDbTags.CreateBlock(AcquireDbMainTag, AcquireDbNextTag);
80+
//LoadDbTags.CreateBlock(JoinDbTags);
81+
//LoadGitHubTags.CreateBlock(LoadDbTags);
82+
//JoinTags.CreateBlock(LoadDbTags, LoadGitHubTags);
83+
//BroadcastTags.CreateBlock(JoinTags);
84+
//StreamGitHubTags.CreateBlock(BroadcastTags);
85+
//GetTagAssets.CreateBlock(StreamGitHubTags);
86+
//TagBuffer.CreateBlock(GetTagAssets);
87+
//AccumulateProcessedTags.CreateBlock(TagBuffer);
88+
//SaveTags.CreateBlock(AccumulateProcessedTags);
8489
}
8590
}
91+
92+
public class SynchronizeTagsBlock : ActionBlockBase<TagSyncRequestParameters, SyncContext>
93+
{
94+
private readonly IGitHubClientService _github;
95+
private readonly TagServices _tagServices;
96+
97+
public SynchronizeTagsBlock(PipelineSection<SyncContext> parent, CancellationTokenSource tokenSource, ILogger logger,
98+
TagServices tagServices,
99+
IGitHubClientService github)
100+
: base(parent, tokenSource, logger)
101+
{
102+
_tagServices = tagServices;
103+
_github = github;
104+
}
105+
106+
protected override async Task ActionAsync(TagSyncRequestParameters input)
107+
{
108+
var getGithubTags = _github.GetAllTagsAsync();
109+
var dbMain = _tagServices.GetLatestTag(false);
110+
var dbNext = _tagServices.GetLatestTag(true);
111+
112+
var githubTags = await getGithubTags;
113+
var (gitHubMain, gitHubNext, _) = githubTags.GetLatestTags();
114+
115+
var mergedMain = (dbMain ?? gitHubMain with { InstallerDownloads = gitHubMain.InstallerDownloads })!;
116+
var mergedNext = (dbNext ?? gitHubNext with { InstallerDownloads = gitHubNext.InstallerDownloads })!;
117+
118+
var inserts = new List<TagGraph>();
119+
var updates = new List<TagGraph>();
120+
121+
if (dbMain is null)
122+
{
123+
inserts.Add(mergedMain);
124+
}
125+
else
126+
{
127+
updates.Add(mergedMain);
128+
}
129+
130+
if (dbNext is null)
131+
{
132+
inserts.Add(mergedNext);
133+
}
134+
else
135+
{
136+
updates.Add(mergedNext);
137+
}
138+
139+
if (inserts.Any())
140+
{
141+
_tagServices.Create(inserts);
142+
}
143+
if (updates.Any())
144+
{
145+
_tagServices.Update(updates);
146+
}
147+
}
148+
}

rubberduckvba.Server/ContentSynchronization/Pipeline/Sections/SyncXmldoc/SyncXmldocSection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected override async Task ActionAsync(SyncRequestParameters input)
9393
var dbMain = await _content.GetLatestTagAsync(RepositoryId.Rubberduck, includePreRelease: false);
9494
Context.LoadRubberduckDbMain(dbMain);
9595

96-
var githubTags = await _github.GetAllTagsAsync(dbMain.Name);
96+
var githubTags = await _github.GetAllTagsAsync();
9797
// LoadInspectionDefaultConfig
9898
var config = await _github.GetCodeAnalysisDefaultsConfigAsync();
9999
Context.LoadInspectionDefaultConfig(config);

rubberduckvba.Server/ContentSynchronization/Pipeline/SynchronizeTagsPipeline.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using rubberduckvba.Server.ContentSynchronization.Pipeline.Sections.SyncTags;
44
using rubberduckvba.Server.ContentSynchronization.XmlDoc.Abstract;
55
using rubberduckvba.Server.Services;
6+
using rubberduckvba.Server.Services.rubberduckdb;
67

78
namespace rubberduckvba.Server.ContentSynchronization.Pipeline;
89

@@ -12,14 +13,17 @@ public class SynchronizeTagsPipeline : PipelineBase<SyncContext, bool>, ISynchro
1213
private readonly IGitHubClientService _github;
1314
private readonly IXmlDocMerge _merge;
1415
private readonly IStagingServices _staging;
16+
private readonly TagServices _tagServices;
1517

16-
public SynchronizeTagsPipeline(IRequestParameters parameters, ILogger logger, IRubberduckDbService content, IGitHubClientService github, IXmlDocMerge merge, IStagingServices staging, CancellationTokenSource tokenSource)
18+
public SynchronizeTagsPipeline(IRequestParameters parameters, ILogger logger,
19+
IRubberduckDbService content, TagServices tagServices, IGitHubClientService github, IXmlDocMerge merge, IStagingServices staging, CancellationTokenSource tokenSource)
1720
: base(new SyncContext(parameters), tokenSource, logger)
1821
{
1922
_content = content;
2023
_github = github;
2124
_merge = merge;
2225
_staging = staging;
26+
_tagServices = tagServices;
2327
}
2428

2529
public async Task<IPipelineResult<bool>> ExecuteAsync(SyncRequestParameters parameters, CancellationTokenSource tokenSource)
@@ -31,14 +35,14 @@ public async Task<IPipelineResult<bool>> ExecuteAsync(SyncRequestParameters para
3135
}
3236

3337
// 01. Create the pipeline sections
34-
var synchronizeTags = new SyncTagsSection(this, tokenSource, Logger, _content, _github, _staging);
38+
var synchronizeTags = new SyncTagsSection(this, tokenSource, Logger, _tagServices, _github, _staging);
3539

3640
// 02. Wire up the pipeline
3741
AddSections(parameters, synchronizeTags);
3842
DisposeAfter(synchronizeTags.WhenAllBlocksCompleted);
3943

4044
// 03. Light it up
41-
Start(synchronizeTags.InputBlock, parameters);
45+
Start(synchronizeTags.InputBlock, (TagSyncRequestParameters)parameters);
4246

4347
// 04. await completion
4448
await synchronizeTags.OutputTask;

rubberduckvba.Server/Services/GitHubClientService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace rubberduckvba.Server.Services;
1717
public interface IGitHubClientService
1818
{
1919
Task<ClaimsPrincipal?> ValidateTokenAsync(string token);
20-
Task<IEnumerable<TagGraph>> GetAllTagsAsync(string? dbMainTagName);
20+
Task<IEnumerable<TagGraph>> GetAllTagsAsync();
2121
Task<TagGraph> GetTagAsync(string? token, string name);
2222
Task<IEnumerable<InspectionDefaultConfig>> GetCodeAnalysisDefaultsConfigAsync();
2323
}
@@ -60,18 +60,18 @@ private class ReleaseComparer : IEqualityComparer<Release>
6060
return new ClaimsPrincipal(identity);
6161
}
6262

63-
public async Task<IEnumerable<TagGraph>> GetAllTagsAsync(string? dbMainTagName)
63+
public async Task<IEnumerable<TagGraph>> GetAllTagsAsync()
6464
{
6565
var config = configuration.Value;
6666
var credentials = new Credentials(config.OrgToken);
6767
var client = new GitHubClient(new ProductHeaderValue(config.UserAgent), new InMemoryCredentialStore(credentials));
6868

6969

7070
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);
71+
var getLatest = client.Repository.Release.GetLatest(config.OwnerOrg, config.Rubberduck);
72+
await Task.WhenAll(getReleases, getLatest);
7373

74-
var releases = (await getReleases).Append(await getKnownMain).ToHashSet(new ReleaseComparer());
74+
var releases = (await getReleases).Append(await getLatest).ToHashSet(new ReleaseComparer());
7575

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

rubberduckvba.Server/Services/rubberduckdb/TagServices.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public IEnumerable<Tag> GetLatestTags(IEnumerable<Tag> allTags) => allTags
3232
.SelectMany(tags => tags.Take(1))
3333
.ToList();
3434

35-
public TagGraph GetLatestTag(bool isPreRelease)
35+
public TagGraph? GetLatestTag(bool isPreRelease)
3636
{
3737
var latestTags = GetLatestTags();
38+
if (!latestTags.Any())
39+
{
40+
return null;
41+
}
3842

3943
if (!isPreRelease)
4044
{

0 commit comments

Comments
 (0)