public static ConventionalCommit Parse(Commit commit)
        {
            var conventionalCommit = new ConventionalCommit
            {
                Sha = commit.Sha
            };

            var commitMessageLines = commit.Message.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None
                )
                                     .Select(line => line.Trim())
                                     .Where(line => !string.IsNullOrWhiteSpace(line))
                                     .ToList();

            var header = commitMessageLines.FirstOrDefault();

            if (header == null)
            {
                return(conventionalCommit);
            }

            var match = HeaderPattern.Match(header);

            if (match.Success)
            {
                conventionalCommit.Scope   = match.Groups["scope"].Value;
                conventionalCommit.Type    = match.Groups["type"].Value;
                conventionalCommit.Subject = match.Groups["subject"].Value;
            }
            else
            {
                conventionalCommit.Subject = header;
            }

            for (var i = 1; i < commitMessageLines.Count; i++)
            {
                foreach (var noteKeyword in NoteKeywords)
                {
                    var line = commitMessageLines[i];
                    if (line.StartsWith($"{noteKeyword}:"))
                    {
                        conventionalCommit.Notes.Add(new ConventionalCommitNote
                        {
                            Title = noteKeyword,
                            Text  = line.Substring($"{noteKeyword}:".Length).TrimStart()
                        });
                    }
                }
            }

            return(conventionalCommit);
        }
Ejemplo n.º 2
0
        public static string BuildCommit(ConventionalCommit commit, IChangelogLinkBuilder linkBuilder)
        {
            var sb = new StringBuilder("* ");

            if (!string.IsNullOrWhiteSpace(commit.Scope))
            {
                sb.Append($"**{commit.Scope}:** ");
            }

            sb.Append(commit.Subject);

            var commitLink = linkBuilder.BuildCommitLink(commit);

            if (!string.IsNullOrWhiteSpace(commitLink))
            {
                sb.Append($" ([{commit.Sha.Substring(0, 7)}]({commitLink}))");
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
 public string BuildCommitLink(ConventionalCommit commit)
 {
     return($"https://{_organization}@dev.azure.com/{_organization}/{_repository}/commit/{commit.Sha}");
 }