private ConventionalCommit Parse(Commit commit)
        {
            var commitMessageLines = commit.Message.Split(
                new[] { CARRIAGE_RETURN, LINE_FEED },
                System.StringSplitOptions.RemoveEmptyEntries)
                                     .Select(line => line.Trim())
                                     .Where(line => !string.IsNullOrWhiteSpace(line));

            var header = commitMessageLines.ElementAt(0);
            ConventionalCommit conventionalCommit = default;

            if (header is object)
            {
                var matchHeader = HEADER_PATTERN.Match(header);
                if (matchHeader.Success)
                {
                    string type    = matchHeader.Groups[nameof(type)].Value;
                    string scope   = matchHeader.Groups[nameof(scope)].Value;
                    string subject = matchHeader.Groups[nameof(subject)].Value;

                    conventionalCommit = new ConventionalCommit(type, scope, subject);

                    for (var i = 1; i < commitMessageLines.Count(); i++)
                    {
                        string line         = commitMessageLines.ElementAt(i);
                        var    matchTrailer = HEADER_PATTERN.Match(line);

                        if (matchTrailer.Success)
                        {
                            var trailerType    = matchTrailer.Groups[nameof(type)].Value;
                            var trailerScope   = matchTrailer.Groups[nameof(scope)].Value;
                            var trailerSubject = matchTrailer.Groups[nameof(subject)].Value;

                            conventionalCommit.AppendTrailer(trailerType, trailerScope, trailerSubject);

                            if (trailerType.Equals(BREAKING_CHANGE_TOKEN))
                            {
                                conventionalCommit.FoundBreakingChangeToken();
                            }
                        }
                    }
                }
            }

            return(conventionalCommit);
        }
Пример #2
0
        public void AppendTrailer(string token, string scope, string subject)
        {
            var trailer = new ConventionalCommit(token, scope, subject);

            _trailers.Add(trailer);
        }