public async Task <(Guid RevisionId, Dictionary <ClientFileId, Guid> ClientFileIdMap, Dictionary <string, Guid> ByName)> FindOrCreateRevision(ReviewIdentifier reviewId, PublishReview.RevisionCommits commits, FeatureToggle features) { var existingRevision = await _sessionAdapter.GetRevision(reviewId, commits); if (existingRevision != null) { var fileHistory = _sessionAdapter.GetFileHistoryEntries(existingRevision); var idMap = fileHistory.ToDictionary(x => ClientFileId.Persistent(x.FileId), x => x.FileId); var nameMap = fileHistory.GroupBy(x => x.FileName).ToDictionary(x => x.Key, x => x.First().FileId); return(existingRevision.Id, idMap, nameMap); } // create revision var nextNumber = _sessionAdapter.GetNextRevisionNumber(reviewId); await CreateRef(reviewId, nextNumber, commits.Base, "base", _api); try { await CreateRef(reviewId, nextNumber, commits.Head, "head", _api); } catch (ExistingRefConflictException unexpectedException) { // The base ref is already created, we must add the record to database no matter what Console.WriteLine("Failed to create ref for head commit - ignoring"); Console.WriteLine(unexpectedException.ToString()); } var revision = await _factory.Create(reviewId, nextNumber, commits.Base, commits.Head); await _sessionAdapter.Save(revision); var clientFileIdMap = await new FillFileHistory(_sessionAdapter, _api, revision, features).Fill(); var byClientId = clientFileIdMap.ToDictionary(x => x.Key, x => x.Value.Item2); var byName = clientFileIdMap.GroupBy(x => x.Value.Item1).ToDictionary(x => x.Key, x => x.First().Value.Item2); return(RevisionId : revision.Id, ClientFileIdMap : byClientId, byName); }
public async Task Publish(NewFileDiscussion[] discussions, Dictionary <string, Guid> newCommentsMap, Dictionary <string, Guid> newDiscussionsMap) { foreach (var discussion in discussions) { var commentId = GuidComb.Generate(); var discussionId = GuidComb.Generate(); newCommentsMap[discussion.TemporaryId] = commentId; newDiscussionsMap[discussion.TemporaryId] = discussionId; var review = _reviewForRevision(discussion.TargetRevisionId); var resolvedFileId = _resolveFileId(discussion.FileId); var currentRevision = _sessionAdapter.GetRevision(review.RevisionId); var prevRevision = _sessionAdapter.GetPreviousRevision(currentRevision); var currentEntry = _sessionAdapter.GetFileHistoryEntry(resolvedFileId, currentRevision); var prevEntry = _sessionAdapter.GetFileHistoryEntry(resolvedFileId, prevRevision); _sessionAdapter.Save(new FileDiscussion { RevisionId = review.RevisionId, Id = discussionId, FileId = resolvedFileId, File = PathPair.Make(prevEntry?.FileName ?? currentEntry.FileName, currentEntry.FileName), LineNumber = discussion.LineNumber, State = discussion.State.AsCommentState(), RootComment = new Comment { Id = commentId, PostedInReviewId = review.Id, Content = discussion.Content, CreatedAt = DateTimeOffset.UtcNow } }); } }
private IEnumerable <(ClientFileId Id, PathPair Path)> UnpackIds(Guid revisionId, List <ClientFileId> fileIds) { var result = new List <(ClientFileId Id, PathPair Path)>(); foreach (var clientFileId in fileIds) { if (clientFileId.PersistentId == Guid.Empty) { result.Add((clientFileId, clientFileId.ProvisionalPathPair)); continue; } var currentRevision = _sessionAdapter.GetRevision(revisionId); var currentEntry = _sessionAdapter.GetFileHistoryEntry(clientFileId.PersistentId, currentRevision); var prevRevision = _sessionAdapter.GetPreviousRevision(currentRevision); var prevEntry = _sessionAdapter.GetFileHistoryEntry(clientFileId.PersistentId, prevRevision); result.Add((clientFileId, PathPair.Make(prevEntry?.FileName ?? currentEntry.FileName, currentEntry.FileName))); } return(result); }