public PullRequestFilesViewModel( IPullRequestService service, IPullRequestEditorService editorService) { Guard.ArgumentNotNull(service, nameof(service)); Guard.ArgumentNotNull(editorService, nameof(editorService)); this.service = service; DiffFile = ReactiveCommand.CreateAsyncTask(x => (Task)editorService.OpenDiff(pullRequestSession, ((IPullRequestFileNode)x).RelativePath, "HEAD")); ViewFile = ReactiveCommand.CreateAsyncTask(x => (Task)editorService.OpenFile(pullRequestSession, ((IPullRequestFileNode)x).RelativePath, false)); DiffFileWithWorkingDirectory = ReactiveCommand.CreateAsyncTask( isBranchCheckedOut, x => (Task)editorService.OpenDiff(pullRequestSession, ((IPullRequestFileNode)x).RelativePath)); OpenFileInWorkingDirectory = new NonDeletedFileCommand( isBranchCheckedOut, x => (Task)editorService.OpenFile(pullRequestSession, ((IPullRequestFileNode)x).RelativePath, true)); OpenFirstComment = ReactiveCommand.CreateAsyncTask(async x => { var file = (IPullRequestFileNode)x; var thread = await GetFirstCommentThread(file); if (thread != null) { await editorService.OpenDiff(pullRequestSession, file.RelativePath, thread); } }); }
public PullRequestFilesViewModel( IPullRequestService service, IPullRequestEditorService editorService) { Guard.ArgumentNotNull(service, nameof(service)); Guard.ArgumentNotNull(editorService, nameof(editorService)); this.service = service; DiffFile = ReactiveCommand.CreateFromTask <IPullRequestFileNode>(x => editorService.OpenDiff(pullRequestSession, x.RelativePath, "HEAD")); ViewFile = ReactiveCommand.CreateFromTask <IPullRequestFileNode>(x => editorService.OpenFile(pullRequestSession, x.RelativePath, false)); DiffFileWithWorkingDirectory = ReactiveCommand.CreateFromTask <IPullRequestFileNode>( x => editorService.OpenDiff(pullRequestSession, x.RelativePath), isBranchCheckedOut); OpenFileInWorkingDirectory = ReactiveCommand.CreateFromTask <IPullRequestFileNode>( x => editorService.OpenFile(pullRequestSession, x.RelativePath, true), isBranchCheckedOut); OpenFirstComment = ReactiveCommand.CreateFromTask <IPullRequestFileNode>(async file => { var thread = await GetFirstCommentThread(file); if (thread != null) { await editorService.OpenDiff(pullRequestSession, file.RelativePath, thread); } }); }
private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file, CheckAnnotationLevel checkAnnotationLevel) { var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel); if (annotationModel != null) { await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, annotationModel.EndLine); } }
private async Task OpenFirstAnnotation(IPullRequestEditorService editorService, IPullRequestFileNode file, CheckAnnotationLevel checkAnnotationLevel) { var annotationModel = await GetFirstAnnotation(file, checkAnnotationLevel); if (annotationModel != null) { //AnnotationModel.EndLine is a 1-based number //EditorService.OpenDiff takes a 0-based line number to start searching AFTER and will open the next tag var nextInlineCommentFromLine = annotationModel.EndLine - 2; await editorService.OpenDiff(pullRequestSession, file.RelativePath, annotationModel.HeadSha, nextInlineCommentFromLine); } }
/// <summary> /// Initializes the <see cref="PullRequestAnnotationItemViewModel"/>. /// </summary> /// <param name="annotation">The check run annotation model.</param> /// <param name="isFileInPullRequest">A flag that denotes if the annotation is part of the pull request's changes.</param> /// <param name="checkSuite">The check suite model.</param> /// <param name="session">The pull request session.</param> /// <param name="editorService">The pull request editor service.</param> public PullRequestAnnotationItemViewModel( CheckRunAnnotationModel annotation, bool isFileInPullRequest, CheckSuiteModel checkSuite, IPullRequestSession session, IPullRequestEditorService editorService) { Annotation = annotation; IsFileInPullRequest = isFileInPullRequest; OpenAnnotation = ReactiveCommand.CreateFromTask <Unit>( async _ => await editorService.OpenDiff(session, annotation.Path, checkSuite.HeadSha, annotation.EndLine - 1), Observable.Return(IsFileInPullRequest)); }
async Task DoOpen() { try { if (thread == null) { var file = await session.GetFile(RelativePath, model.Thread.CommitSha); thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); } if (thread != null && thread.LineNumber != -1) { await editorService.OpenDiff(session, RelativePath, thread); } } catch (Exception) { // TODO: Show error. } }
async Task DoOpen() { try { if (thread == null) { if (model.Thread.IsOutdated) { var file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha); thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); } else { var file = await session.GetFile(RelativePath, model.Thread.CommitSha); thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); if (thread?.LineNumber == -1) { log.Warning("Couldn't find line number for comment on {RelativePath} @ {CommitSha}", RelativePath, model.Thread.CommitSha); // Fall back to opening outdated file if we can't find a line number for the comment file = await session.GetFile(RelativePath, model.Thread.OriginalCommitSha); thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Comment.Id == model.Id)); } } } if (thread != null && thread.LineNumber != -1) { await editorService.OpenDiff(session, RelativePath, thread); } } catch (Exception e) { log.Error(e, nameof(DoOpen)); } }
async Task DoOpen(object o) { try { if (thread == null) { var commit = model.Position.HasValue ? model.CommitId : model.OriginalCommitId; var file = await session.GetFile(RelativePath, commit); thread = file.InlineCommentThreads.FirstOrDefault(t => t.Comments.Any(c => c.Id == model.Id)); } if (thread != null && thread.LineNumber != -1) { await editorService.OpenDiff(session, RelativePath, thread); } } catch (Exception) { // TODO: Show error. } }