public async Task CommitComment(DateTimeOffset eventDate, CommitCommentPayload payload) { var updater = new DataUpdater(_contextFactory, _mapper); await updater.UpdateRepositories(eventDate, new[] { payload.Repository }); // NOTE: As of this commit, edited and deleted are never sent. // We're ready to support it if they're added later switch (payload.Action) { case "created": case "edited": await updater.UpdateCommitComments(payload.Repository.Id, eventDate, new[] { payload.Comment }); break; case "deleted": await updater.DeleteCommitComment(payload.Comment.Id, null); break; default: throw new NotImplementedException($"Action '{payload.Action}' is not valid for event {nameof(CommitComment)}."); } await updater.Changes.Submit(_queueClient); }
private async Task UpdateCommitCommentReactions(IGitHubActor ghc, DataUpdater updater, ISet <long> knownCommitCommentIds) { // TODO: Use knownCommitCommentIds and response date to prune deleted comments in one go. IssueEvent[] committedEvents; string[] commitShas; IDictionary <long, GitHubMetadata> commitCommentCommentMetadata = null; using (var context = _contextFactory.CreateInstance()) { committedEvents = await context.IssueEvents .AsNoTracking() .Where(x => x.IssueId == _issueId && x.Event == "committed") .ToArrayAsync(); commitShas = committedEvents .Select(x => x.ExtensionData.DeserializeObject <JToken>().Value <string>("sha")) .ToArray(); if (commitShas.Any()) { commitCommentCommentMetadata = await context.CommitComments .AsNoTracking() .Where(x => commitShas.Contains(x.CommitId)) .ToDictionaryAsync(x => x.Id, x => x.ReactionMetadata); } } if (commitShas.Any()) { var commitCommentReactionRequests = new Dictionary <long, Task <GitHubResponse <IEnumerable <gm.Reaction> > > >(); foreach (var reactionMetadata in commitCommentCommentMetadata) { if (reactionMetadata.Value.IsExpired()) { commitCommentReactionRequests.Add(reactionMetadata.Key, ghc.CommitCommentReactions(_repoFullName, reactionMetadata.Key, reactionMetadata.Value, RequestPriority.Interactive)); } } if (commitCommentReactionRequests.Any()) { await Task.WhenAll(commitCommentReactionRequests.Values); foreach (var commitCommentReactionsResponse in commitCommentReactionRequests) { var resp = await commitCommentReactionsResponse.Value; switch (resp.Status) { case HttpStatusCode.NotModified: break; case HttpStatusCode.NotFound: if (!knownCommitCommentIds.Contains(commitCommentReactionsResponse.Key)) { await updater.DeleteCommitComment(commitCommentReactionsResponse.Key, resp.Date); } break; default: await updater.UpdateCommitCommentReactions(_repoId, resp.Date, commitCommentReactionsResponse.Key, resp.Result); break; } using (var context = _contextFactory.CreateInstance()) { await context.UpdateMetadata("CommitComments", "ReactionMetadataJson", commitCommentReactionsResponse.Key, resp); } } } } }