Ejemplo n.º 1
0
 private void WriteToDisk(string outputFileName, SerializableChanges changes)
 {
     using (var fileStream = File.Create(outputFileName))
     {
         changes.Serialize(fileStream);
     }
 }
Ejemplo n.º 2
0
        public void TestFilterIncludeOnly()
        {
            var changes = new SerializableChanges
            {
                Changes =
                {
                    new SerializableChange {
                        Summary = "Rimworld"
                    },
                    new SerializableChange {
                        Summary = "VA-11"
                    },
                    new SerializableChange {
                        Summary = "Whatever", Description = "Hey, VA-11 is a pretty good game"
                    }
                }
            };
            var filtered = GitGetChanges.Filter(changes, "VA", null);

            filtered.Should().NotBeNull();
            filtered.Changes.Should().HaveCount(2);
            filtered.Changes[0].Summary.Should().Be("VA-11");
            filtered.Changes[1].Summary.Should().Be("Whatever");
            filtered.Changes[1].Description.Should().Be("Hey, VA-11 is a pretty good game");
        }
Ejemplo n.º 3
0
        public void TestRoundtripOneTwoChanges()
        {
            var changes = new SerializableChanges
            {
                Changes =
                {
                    new SerializableChange
                    {
                        Summary     = "When the fire nation attacked...",
                        Description = "Everything changed"
                    },
                    new SerializableChange
                    {
                        Summary = "My cabbages",
                    }
                }
            };
            var actualChanges = Roundtrip(changes);

            actualChanges.Changes.Should().HaveCount(2);
            actualChanges.Changes[0].Summary.Should().Be("When the fire nation attacked...");
            actualChanges.Changes[0].Description.Should().Be("Everything changed");

            actualChanges.Changes[1].Summary.Should().Be("My cabbages");
            actualChanges.Changes[1].Description.Should().BeNullOrEmpty();
        }
Ejemplo n.º 4
0
        public static SerializableChanges Filter(SerializableChanges changes, string include, string exclude)
        {
            var filtered = new SerializableChanges();

            filtered.Changes.AddRange(changes.Changes.Where(x => Matches(x, include, exclude)));
            return(filtered);
        }
Ejemplo n.º 5
0
        private static SerializableChanges Parse(string output)
        {
            var regex   = new Regex(@"commit ([0-9a-f]{40})\s*(\(tag:\s+([^)]+)\)){0,1}\nAuthor:[^\n]+\nDate:[^\n]+", RegexOptions.Multiline);
            var matches = regex.Matches(output);
            var changes = new SerializableChanges();

            for (int i = 0; i < matches.Count - 1; ++i)
            {
                var match     = matches[i];
                var nextMatch = matches[i + 1];

                var id      = match.Groups[1].Value;
                var start   = match.Index + match.Length;
                var end     = nextMatch.Index;
                var message = output.Substring(start, end - start);
                TryAddChange(id, message, changes);
            }

            if (matches.Count > 0)
            {
                var lastMatch = matches[matches.Count - 1];
                var id        = lastMatch.Groups[1].Value;
                var start     = lastMatch.Index + lastMatch.Length;
                var message   = output.Substring(start);
                TryAddChange(id, message, changes);
            }

            return(changes);
        }
Ejemplo n.º 6
0
        private static SerializableChanges Roundtrip(SerializableChanges changes)
        {
            using (var stream = new MemoryStream())
            {
                changes.Serialize(stream);

                stream.Position = 0;
                return(SerializableChanges.Deserialize(stream));
            }
        }
Ejemplo n.º 7
0
        public void TestRoundtripEmpty()
        {
            var changes       = new SerializableChanges();
            var actualChanges = Roundtrip(changes);

            actualChanges.Should().NotBeNull();
            actualChanges.Should().NotBeSameAs(changes);
            actualChanges.Changes.Should().NotBeNull();
            actualChanges.Changes.Should().BeEmpty();
        }
Ejemplo n.º 8
0
        private static void TryAddChange(string id, string message, SerializableChanges changes)
        {
            var split = message.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            if (split.Length > 0)
            {
                var change = new SerializableChange
                {
                    Id      = id,
                    Summary = split[0].Trim()
                };
                change.Description = string.Join(Environment.NewLine, split.Skip(1).Select(x => x.Trim()));

                changes.Changes.Add(change);
            }
        }
Ejemplo n.º 9
0
        public void TestRoundtripOneChange()
        {
            var changes = new SerializableChanges
            {
                Changes =
                {
                    new SerializableChange
                    {
                        Summary = "I made a booboo"
                    }
                }
            };
            var actualChanges = Roundtrip(changes);

            actualChanges.Changes.Should().HaveCount(1);
            actualChanges.Changes[0].Summary.Should().Be("I made a booboo");
            actualChanges.Changes[0].Description.Should().BeNullOrEmpty();
        }
Ejemplo n.º 10
0
        public void TestFilterIncludeExclude()
        {
            var changes = new SerializableChanges
            {
                Changes =
                {
                    new SerializableChange {
                        Summary = "Bugfix for merge"
                    },
                    new SerializableChange {
                        Summary = "Bugfix test"
                    }
                }
            };
            var filtered = GitGetChanges.Filter(changes, "bugfix", "merge");

            filtered.Should().NotBeNull();
            filtered.Changes.Should().HaveCount(1);
            filtered.Changes[0].Summary.Should().Be("Bugfix test");
        }
Ejemplo n.º 11
0
        public void TestFilterExcludeOnly()
        {
            var changes = new SerializableChanges
            {
                Changes =
                {
                    new SerializableChange {
                        Summary = "Rimworld"
                    },
                    new SerializableChange {
                        Summary = "VA-11"
                    }
                }
            };
            var filtered = GitGetChanges.Filter(changes, null, "VA");

            filtered.Should().NotBeNull();
            filtered.Changes.Should().HaveCount(1);
            filtered.Changes[0].Summary.Should().Be("Rimworld");
        }