Beispiel #1
0
        private async Task UpdatePullRequestCommentReactions(IGitHubActor ghc, DataUpdater updater, ISet <long> knownPullRequestCommentIds)
        {
            IDictionary <long, GitHubMetadata> prcReactionMetadata = null;

            using (var context = _contextFactory.CreateInstance()) {
                prcReactionMetadata = await context.PullRequestComments
                                      .AsNoTracking()
                                      .Where(x => x.IssueId == _issueId)
                                      .ToDictionaryAsync(x => x.Id, x => x.ReactionMetadata);
            }

            if (prcReactionMetadata.Any())
            {
                var prcReactionRequests = new Dictionary <long, Task <GitHubResponse <IEnumerable <gm.Reaction> > > >();
                foreach (var reactionMetadata in prcReactionMetadata)
                {
                    if (reactionMetadata.Value.IsExpired())
                    {
                        prcReactionRequests.Add(reactionMetadata.Key, ghc.PullRequestCommentReactions(_repoFullName, reactionMetadata.Key, reactionMetadata.Value, RequestPriority.Interactive));
                    }
                }

                if (prcReactionRequests.Any())
                {
                    await Task.WhenAll(prcReactionRequests.Values);

                    foreach (var prcReactionsResponse in prcReactionRequests)
                    {
                        var resp = await prcReactionsResponse.Value;
                        switch (resp.Status)
                        {
                        case HttpStatusCode.NotModified:
                            break;

                        case HttpStatusCode.NotFound:
                            // knownPullRequestCommentIds can be null
                            if (knownPullRequestCommentIds?.Contains(prcReactionsResponse.Key) != true)
                            {
                                // null or false
                                await updater.DeletePullRequestComment(prcReactionsResponse.Key, resp.Date);
                            }
                            break;

                        default:
                            await updater.UpdatePullRequestCommentReactions(_repoId, resp.Date, prcReactionsResponse.Key, resp.Result);

                            break;
                        }
                        using (var context = _contextFactory.CreateInstance()) {
                            await context.UpdateMetadata("PullRequestComments", "ReactionMetadataJson", prcReactionsResponse.Key, resp);
                        }
                    }
                }
            }
        }
        public async Task PullRequestReviewComment(DateTimeOffset eventDate, PullRequestReviewCommentPayload payload)
        {
            var updater = new DataUpdater(_contextFactory, _mapper);

            await updater.UpdateRepositories(eventDate, new[] { payload.Repository });

            await updater.UpdatePullRequests(payload.Repository.Id, eventDate, new[] { payload.PullRequest });

            switch (payload.Action)
            {
            case "created":
                // We need the issueId
                // TODO: Modify BulkUpdate to work with PR/Issue Number instead?
                long?issueId;
                using (var context = _contextFactory.CreateInstance()) {
                    issueId = await context.Issues
                              .AsNoTracking()
                              .Where(x => x.RepositoryId == payload.Repository.Id && x.Number == payload.PullRequest.Number)
                              .Select(x => (long?)x.Id)
                              .SingleOrDefaultAsync();
                }

                if (issueId != null)
                {
                    await updater.UpdatePullRequestComments(payload.Repository.Id, issueId.Value, eventDate, new[] { payload.Comment }, dropWithMissingReview : true);
                }
                break;

            case "edited":
                // GitHub doesn't send the new comment body. We have to look it up ourselves.
                var repoActor = _grainFactory.GetGrain <IRepositoryActor>(payload.Repository.Id);
                await repoActor.RefreshPullRequestReviewComment(payload.Comment.Id);

                break;

            case "deleted":
                await updater.DeletePullRequestComment(payload.Comment.Id, null);

                break;

            default:
                throw new NotImplementedException($"Action '{payload.Action}' is not valid for event {nameof(PullRequestReviewComment)}.");
            }

            await updater.Changes.Submit(_queueClient);
        }