Exemplo n.º 1
0
        public void Test()
        {
            const string text = @"
Did stuff!

:cl: Ev1__l P-JB2323
- add: Did the thing
- remove: Removed the thing
- fix: A
- bugfix: B
- bug: C
";

            var time   = new DateTimeOffset(2021, 1, 1, 1, 1, 1, TimeSpan.Zero);
            var pr     = new GHPullRequest(true, text, new GHUser("PJB"), time, new GHPullRequestBase("master"), 123);
            var parsed = WebhookController.ParsePRBody(pr);

            Assert.That(parsed, Is.Not.Null);
            Assert.That(parsed.Author, Is.EqualTo("Ev1__l P-JB2323"));
            Assert.That(parsed.Time, Is.EqualTo(time));
            Assert.That(parsed.Changes, Is.EquivalentTo(new[]
Exemplo n.º 2
0
        internal static ChangelogData?ParsePRBody(GHPullRequest pr)
        {
            var match = ChangelogHeaderRegex.Match(pr.Body);

            if (!match.Success)
            {
                return(null);
            }

            var author  = match.Groups[1].Success ? match.Groups[1].Value.Trim() : pr.User.Login;
            var entries = new List <(ChangelogEntryType, string)>();

            var changelogBody = pr.Body.Substring(match.Index + match.Length);

            foreach (Match entryMatch in ChangelogEntryRegex.Matches(changelogBody))
            {
                var type = entryMatch.Groups[1].Value.ToLowerInvariant() switch
                {
                    "add" => ChangelogEntryType.Add,
                    "remove" => ChangelogEntryType.Remove,
                    "fix" or "bugfix" or "bug" => ChangelogEntryType.Fix,
                    "tweak" => ChangelogEntryType.Tweak,
                    _ => (ChangelogEntryType?)null
                };

                var message = entryMatch.Groups[2].Value.Trim();

                if (type is { } t)
                {
                    entries.Add((t, message));
                }
            }

            return(new ChangelogData(author, entries.ToImmutableArray(), pr.MergedAt ?? DateTimeOffset.Now)
            {
                Number = pr.Number
            });
        }
    }