Exemplo n.º 1
0
 public CommitChanges GetCommitChanges(IHostingEnvironment environment,string repoName, string hash)
 {
     var gitResult = StartGit($" show {hash}", $"{environment.WebRootPath}/Repos/{repoName}");
     if (String.IsNullOrWhiteSpace(gitResult))
         throw new ArgumentException("No commit with specified hash");
     gitResult = gitResult + "diff --git";
     var regex = new Regex(@"\+\+\+ b\/(.*)\n(?s:(.*?))diff --git");
     var matches = regex.Matches(gitResult);
     var result = new CommitChanges {Changes = new Dictionary<string, string[]>(matches.Count)};
     foreach (Match match in matches)
     {
         result.Changes[match.Groups[1].Value] = match.Groups[2].Value.Split('\n');
     }
     regex = new Regex(@".*b\/(.*)\n(?s:deleted file mode .*?)diff --git");
     matches = regex.Matches(gitResult);
     result.DeletedFiles = new List<string>(matches.Count);
     foreach (Match match in matches)
     {
         result.DeletedFiles.Add(match.Groups[1].Value);
     }
     regex = new Regex(@".*b\/(.*)\n(?s:new file mode .*?)diff --git");
     matches = regex.Matches(gitResult);
     result.NewFiles = new List<string>(matches.Count);
     foreach (Match match in matches)
     {
         result.NewFiles.Add(match.Groups[1].Value);
     }
     return result;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name        = "TeamCityIntegration",
                Description = "TeamCityIntegration for handling TeamCity CI/CD Automation.",
                ThrowOnUnexpectedArgument = false
            };


            CommitChanges.AddCommand(app);


            app.HelpOption("-? | -h | --help");

            try
            {
                // parse and call OnExecute handler specified above
                var result = app.Execute(args);
                Environment.Exit(result);
            }
            catch (CommandParsingException ex)
            {
                // handle parsing errors ...
            }
        }
Exemplo n.º 3
0
        private static bool CompareWordCount(CommitChanges change)
        {
            var wordCountInNewLines =
                string.Join(" ", change.NewLines).Split(" ").Count(s => !string.IsNullOrWhiteSpace(s));
            var wordCountInOldLines =
                string.Join(" ", change.OldLines).Split(" ").Count(s => !string.IsNullOrWhiteSpace(s));

            return(Math.Abs(wordCountInNewLines - wordCountInOldLines) >= 15);
        }
Exemplo n.º 4
0
        private bool CompareWords(CommitChanges change)
        {
            var wordsInNewLines = GetDistinctWordsFromLineList(change.NewLines);
            var wordsInOldLines = GetDistinctWordsFromLineList(change.OldLines);

            var differentWordsInNewLines = wordsInNewLines.Except(wordsInOldLines).Count();
            var differentWordsInOldLines = wordsInOldLines.Except(wordsInNewLines).Count();

            return(differentWordsInNewLines + differentWordsInOldLines >= 10);
        }
Exemplo n.º 5
0
        private CommitChanges MergeChanges(List <CommitChanges> changes)
        {
            var mergedChanges = new CommitChanges();

            foreach (var commitChanges in changes)
            {
                mergedChanges.NewLines.AddRange(commitChanges.NewLines);
                mergedChanges.OldLines.AddRange(commitChanges.OldLines);
            }

            return(mergedChanges);
        }
Exemplo n.º 6
0
        private CommitChanges GetChanges(string patch)
        {
            var changes     = new List <CommitChanges>();
            var pathSplited = patch.Split("@@");
            var changeList  = pathSplited.Where(s => !string.IsNullOrWhiteSpace(s)).Where((c, i) => i % 2 == 1).ToList();

            foreach (var change in changeList)
            {
                var commitChange = new CommitChanges();
                var lines        = change.Split("\n");

                commitChange.OldLines.AddRange(lines.Where(l => l.StartsWith("-")).Select(l => l.Substring(1)).Where(l => !string.IsNullOrWhiteSpace(l)));
                commitChange.NewLines.AddRange(lines.Where(l => l.StartsWith("+")).Select(l => l.Substring(1)).Where(l => !string.IsNullOrWhiteSpace(l)));

                changes.Add(commitChange);
            }

            return(MergeChanges(changes));
        }
Exemplo n.º 7
0
        private bool IsChangesSignificant(CommitChanges change)
        {
            if (CompareLineCount(change))
            {
                return(true);
            }

            if (CompareWordCount(change))
            {
                return(true);
            }

            if (CompareWords(change))
            {
                return(true);
            }

            return(false);
        }
 protected virtual void OnCommitChanges()
 {
     CommitChanges?.Invoke(this, EventArgs.Empty);
 }
Exemplo n.º 9
0
 private static bool CompareLineCount(CommitChanges change)
 {
     return(Math.Abs(change.NewLines.Count - change.OldLines.Count) >= 3);
 }