/// <summary> /// Return DiffPosition if match succeeded and throw if match failed /// Throws ArgumentException in case of bad arguments. /// Throws GitOperationException in case of problems with git. /// </summary> public DiffPosition Match(DiffRefs diffRefs, DiffToolInfo difftoolInfo) { if (!difftoolInfo.IsValid()) { throw new ArgumentException( String.Format("Bad diff tool info: {0}", difftoolInfo.ToString())); } MatchResult matchResult = match(diffRefs, difftoolInfo); return(createPosition(matchResult, diffRefs, difftoolInfo)); }
private static void submitDiscussion(Snapshot snapshot, DiffToolInfo diffToolInfo, DiffPosition position, string body, bool includeContext) { if (body.Length == 0) { MessageBox.Show("Discussion text cannot be empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } NewDiscussionParameters parameters = new NewDiscussionParameters { Body = body, Position = includeContext ? createPositionParameters(position) : new Nullable <PositionParameters>() }; MergeRequestDescriptor mergeRequestDescriptor = new MergeRequestDescriptor { HostName = snapshot.Host, ProjectName = snapshot.Project, IId = snapshot.MergeRequestIId }; UserDefinedSettings settings = new UserDefinedSettings(false); DiscussionManager manager = new DiscussionManager(settings); DiscussionCreator creator = manager.GetDiscussionCreator(mergeRequestDescriptor); try { creator.CreateDiscussionAsync(parameters).Wait(); } catch (DiscussionCreatorException ex) { Trace.TraceInformation( "Additional information about exception:\n" + "Position: {0}\n" + "Include context: {1}\n" + "Snapshot refs: {2}\n" + "DiffToolInfo: {3}\n" + "Body:\n{4}", position.ToString(), includeContext.ToString(), snapshot.Refs.ToString(), diffToolInfo.ToString(), body); if (!ex.Handled) { throw; } } }
private static bool handleFileRename(DiffToolInfo source, string currentName, string anotherName, bool moved, out DiffToolInfo dest) { dest = source; if (moved) { MessageBox.Show( "Merge Request Helper detected that current file is a moved version of another file. " + "GitLab does not allow to create discussions on moved files.\n\n" + "Current file:\n" + currentName + "\n\n" + "Another file:\n" + anotherName, "Cannot create a discussion", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } bool isLeftSide = source.IsLeftSideCurrent; string fileStatus = isLeftSide ? "new" : "deleted"; if (MessageBox.Show( "Merge Request Helper detected that current file is a renamed version of another file. " + "Do you really want to review this file as a " + fileStatus + " file? " + "It is recommended to press \"No\" and match files manually in the diff tool.\n" + "Current file:\n" + currentName + "\n\n" + "Another file:\n" + anotherName, "Cannot create a discussion", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.No) { Trace.TraceInformation("User decided to match files manually"); return(false); } dest = createDiffToolInfoCloneWithFakeSide(source, anotherName); Trace.TraceInformation("Updated DiffToolInfo: {0}", dest.ToString()); return(true); }
/// <summary> /// Throws GitOperationException in case of problems with git. /// </summary> public bool Process(DiffToolInfo source, Core.Matching.DiffRefs refs, out DiffToolInfo dest) { string currentName; string anotherName; bool moved; bool renamed; try { renamed = checkForRenamedFile(refs, source, out currentName, out anotherName, out moved); } catch (GitOperationException) { throw; // fatal error } if (renamed) { Trace.TraceInformation("Detected file {0}. Git repository path: {1}. DiffRefs: {2}\nDiffToolInfo: {3}", (moved ? "move" : "rename"), _gitRepository.Path, refs.ToString(), source.ToString()); } dest = source; return(!renamed || handleFileRename(source, currentName, anotherName, moved, out dest)); }