コード例 #1
0
        /// <summary>
        /// Throws ArgumentException.
        /// Throws GitOperationException in case of problems with git.
        /// </summary>
        public DiffContext GetContext(DiffPosition position, ContextDepth depth)
        {
            if (!Context.Helpers.IsValidPosition(position))
            {
                throw new ArgumentException(
                          String.Format("Bad \"position\": {0}", position.ToString()));
            }

            if (!Context.Helpers.IsValidContextDepth(depth))
            {
                throw new ArgumentException(
                          String.Format("Bad \"depth\": {0}", depth.ToString()));
            }

            bool   isRightSideContext = position.RightLine != null;
            int    linenumber         = isRightSideContext ? int.Parse(position.RightLine) : int.Parse(position.LeftLine);
            string filename           = isRightSideContext ? position.RightPath : position.LeftPath;
            string sha = isRightSideContext ? position.Refs.RightSHA : position.Refs.LeftSHA;

            List <string> contents = _gitRepository.ShowFileByRevision(filename, sha);

            if (linenumber > contents.Count)
            {
                throw new ArgumentException(
                          String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}",
                                        linenumber.ToString(), position.ToString()));
            }

            return(createDiffContext(linenumber, contents, isRightSideContext, depth));
        }
コード例 #2
0
        /// <summary>
        /// Throws ArgumentException, ContextMakingException.
        /// </summary>
        public DiffContext GetContext(DiffPosition position, ContextDepth depth)
        {
            if (!Context.Helpers.IsValidPosition(position))
            {
                throw new ArgumentException(
                          String.Format("Bad \"position\": {0}", position.ToString()));
            }

            if (!Context.Helpers.IsValidContextDepth(depth))
            {
                throw new ArgumentException(
                          String.Format("Bad \"depth\": {0}", depth.ToString()));
            }

            // If RightLine is valid, then it points to either added/modified or unchanged line, handle them the same way
            bool   isRightSideContext = position.RightLine != null;
            int    linenumber         = isRightSideContext ? int.Parse(position.RightLine) : int.Parse(position.LeftLine);
            string leftFilename       = position.LeftPath;
            string rightFilename      = position.RightPath;
            string leftSHA            = position.Refs.LeftSHA;
            string rightSHA           = position.Refs.RightSHA;

            FullContextDiffProvider provider = new FullContextDiffProvider(_git);
            FullContextDiff         context  = provider.GetFullContextDiff(leftSHA, rightSHA, leftFilename, rightFilename);

            Debug.Assert(context.Left.Count == context.Right.Count);
            if (linenumber > context.Left.Count)
            {
                throw new ArgumentException(
                          String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}",
                                        linenumber.ToString(), position.ToString()));
            }

            return(createDiffContext(linenumber, isRightSideContext, context, depth));
        }
コード例 #3
0
        /// <summary>
        /// Throws ArgumentException, ContextMakingException.
        /// </summary>
        public DiffContext GetContext(DiffPosition position, ContextDepth depth)
        {
            if (!Context.Helpers.IsValidPosition(position))
            {
                throw new ArgumentException(
                          String.Format("Bad \"position\": {0}", position.ToString()));
            }

            if (!Context.Helpers.IsValidContextDepth(depth))
            {
                throw new ArgumentException(
                          String.Format("Bad \"depth\": {0}", depth.ToString()));
            }

            GitDiffAnalyzer analyzer = new GitDiffAnalyzer(_git,
                                                           position.Refs.LeftSHA, position.Refs.RightSHA, position.LeftPath, position.RightPath);

            // If RightLine is valid, then it points to either added/modified or unchanged line, handle them the same way
            bool   isRightSideContext = position.RightLine != null;
            int    linenumber         = isRightSideContext ? int.Parse(position.RightLine) : int.Parse(position.LeftLine);
            string filename           = isRightSideContext ? position.RightPath : position.LeftPath;
            string sha = isRightSideContext ? position.Refs.RightSHA : position.Refs.LeftSHA;

            GitShowRevisionArguments arguments = new GitShowRevisionArguments(filename, sha);

            IEnumerable <string> contents;

            try
            {
                contents = _git?.ShowRevision(arguments);
            }
            catch (GitNotAvailableDataException ex)
            {
                throw new ContextMakingException("Cannot obtain git revision", ex);
            }

            if (contents == null)
            {
                throw new ContextMakingException("Cannot obtain git revision", null);
            }

            if (linenumber > contents.Count())
            {
                throw new ArgumentException(
                          String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}",
                                        linenumber.ToString(), position.ToString()));
            }

            return(createDiffContext(linenumber, isRightSideContext, contents, analyzer, depth));
        }
コード例 #4
0
        /// <summary>
        /// Throws ArgumentException, ContextMakingException.
        /// </summary>
        public DiffContext GetContext(DiffPosition position, ContextDepth depth, UnchangedLinePolicy unchangedLinePolicy)
        {
            if (!Context.Helpers.IsValidPosition(position))
            {
                throw new ArgumentException(
                          String.Format("Bad \"position\": {0}", position.ToString()));
            }

            if (!Context.Helpers.IsValidContextDepth(depth))
            {
                throw new ArgumentException(
                          String.Format("Bad \"depth\": {0}", depth.ToString()));
            }

            bool   isRightSideContext = Helpers.IsRightSidePosition(position, unchangedLinePolicy);
            int    linenumber         = isRightSideContext ? Helpers.GetRightLineNumber(position) : Helpers.GetLeftLineNumber(position);
            string filename           = isRightSideContext ? position.RightPath : position.LeftPath;
            string sha = isRightSideContext ? position.Refs.RightSHA : position.Refs.LeftSHA;

            GitShowRevisionArguments arguments = new GitShowRevisionArguments(filename, sha);

            IEnumerable <string> contents;

            try
            {
                contents = _git?.ShowRevision(arguments);
            }
            catch (GitNotAvailableDataException ex)
            {
                throw new ContextMakingException("Cannot obtain git revision", ex);
            }

            if (contents == null)
            {
                throw new ContextMakingException("Cannot obtain git revision", null);
            }

            if (linenumber > contents.Count())
            {
                throw new ArgumentException(
                          String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}",
                                        linenumber.ToString(), position.ToString()));
            }

            return(createDiffContext(linenumber, contents, isRightSideContext, depth));
        }
コード例 #5
0
        /// <summary>
        /// Throws ArgumentException, ContextMakingException.
        /// </summary>
        public DiffContext GetContext(DiffPosition position, ContextDepth depth, UnchangedLinePolicy unchangedLinePolicy)
        {
            if (!Context.Helpers.IsValidPosition(position))
            {
                throw new ArgumentException(
                          String.Format("Bad \"position\": {0}", position.ToString()));
            }

            if (!Context.Helpers.IsValidContextDepth(depth))
            {
                throw new ArgumentException(
                          String.Format("Bad \"depth\": {0}", depth.ToString()));
            }

            bool   isRightSideContext = Helpers.IsRightSidePosition(position, unchangedLinePolicy);
            int    linenumber         = isRightSideContext ? Helpers.GetRightLineNumber(position) : Helpers.GetLeftLineNumber(position);
            string leftFilename       = position.LeftPath;
            string rightFilename      = position.RightPath;
            string leftSHA            = position.Refs.LeftSHA;
            string rightSHA           = position.Refs.RightSHA;

            try
            {
                FullContextDiff context = _git.FullContextDiffProvider.GetFullContextDiff(
                    leftSHA, rightSHA, leftFilename, rightFilename);
                Debug.Assert(context.Left.Count == context.Right.Count);
                if (linenumber > context.Left.Count)
                {
                    throw new ArgumentException(
                              String.Format("Line number {0} is greater than total line number count, invalid \"position\": {1}",
                                            linenumber.ToString(), position.ToString()));
                }

                return(createDiffContext(linenumber, isRightSideContext, context, depth));
            }
            catch (FullContextDiffProviderException ex)
            {
                throw new ContextMakingException("Cannot obtain full context diff", ex);
            }
        }
コード例 #6
0
        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;
                }
            }
        }
コード例 #7
0
        async private Task submitDiscussionAsync(MatchInfo matchInfo, Snapshot snapshot, DiffPosition position,
                                                 string body, bool includeContext)
        {
            if (body.Length == 0)
            {
                MessageBox.Show("Discussion text cannot be empty", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                return;
            }

            NewDiscussionParameters parameters = new NewDiscussionParameters(
                body, includeContext ? createPositionParameters(position) : new PositionParameters?());

            MergeRequestKey    mrk            = getMergeRequestKey(snapshot);
            GitLabInstance     gitLabInstance = new GitLabInstance(snapshot.Host, Program.Settings);
            IDiscussionCreator creator        = Shortcuts.GetDiscussionCreator(
                gitLabInstance, _modificationListener, mrk, _currentUser);

            try
            {
                await creator.CreateDiscussionAsync(parameters, true);
            }
            catch (DiscussionCreatorException ex)
            {
                Trace.TraceInformation(
                    "Additional information about exception:\n" +
                    "Position: {0}\n" +
                    "Include context: {1}\n" +
                    "Snapshot refs: {2}\n" +
                    "MatchInfo: {3}\n" +
                    "Body:\n{4}",
                    position.ToString(),
                    includeContext.ToString(),
                    snapshot.Refs.ToString(),
                    matchInfo.ToString(),
                    body);

                if (!ex.Handled)
                {
                    throw;
                }
            }
        }