Esempio n. 1
0
        private static List <NoteData> UpdateOrAddNote(ReleaseNotesData releaseNotes, Description title)
        {
            List <NoteData> currentNotes;

            if (releaseNotes.Notes.ContainsKey(title.Singular))
            {
                currentNotes = releaseNotes.Notes[title.Singular];
                if (title.Plural != null)
                {
                    releaseNotes.Notes.Remove(title.Singular);
                    releaseNotes.Notes.Add(title.Plural, currentNotes);
                }
            }
            else if (title.Plural != null && releaseNotes.Notes.ContainsKey(title.Plural))
            {
                currentNotes = releaseNotes.Notes[title.Plural];
            }
            else
            {
                currentNotes = new List <NoteData>();
                releaseNotes.Notes.Add(title.Singular, currentNotes);
            }

            return(currentNotes);
        }
Esempio n. 2
0
        public void ParseReleaseNotes(ReleaseNotesData releaseNotes, ConventionalCommitInfo commit)
        {
            var typeScope = GetMatchingTypeScop(commit, this.types);

            Description?title;

            if (typeScope != null && (typeScope.IncludeInChangelog || commit.IsBreakingChange))
            {
                title = typeScope.Description;
            }
            else
            {
                this.writer.AddIndent();
                this.writer.WriteInfoLine("[dim]:white_exclamation_mark: Not a commit to include in the changelog.[/]");
                this.writer.RemoveIndent();
                return;
            }

            var note = new NoteData(commit.CommitType, commit.Message, commit.CommitScope ?? string.Empty);

            note.Issues.AddRange(commit.IssueRefs);

            if (commit.IsBreakingChange)
            {
                if (!string.IsNullOrEmpty(commit.BreakingChangeNote))
                {
                    releaseNotes.BreakingChanges.Add(commit.BreakingChangeNote);
                }
                else
                {
                    title = new Description("BREAKING CHANGE", "BREAKING CHANGES");
                }
            }

            var currentNotes = UpdateOrAddNote(releaseNotes, title);

            currentNotes.Add(note);

            this.writer.AddIndent();

            this.writer.WriteInfoLine(":check_mark_button: [teal]A new [fuchsia on black]{0}[/] was found. Adding to changelog![/]", title.Singular);

            this.writer.RemoveIndent();
        }
Esempio n. 3
0
        public ParsedData ParseVersionFromCommits(IEnumerable <CommitInfo> commits)
        {
            if (commits is null)
            {
                throw new ArgumentNullException(nameof(commits));
            }

            VersionData?version          = null;
            var         releaseNotes     = new ReleaseNotesData();
            var         firstCommit      = true;
            var         firstCommitIsTag = false;
            var         metadata         = string.Empty;
            var         commitCount      = 0;

            foreach (var commit in commits)
            {
                this._writer.AddIndent();
                var parsedCommit = ParseConventionalCommit(commit, firstCommit || !commit.IsTag);
                if (parsedCommit != null || commit.IsTag)
                {
                    version = this._versionParser.ParseVersion(version, parsedCommit ?? commit);
                }

                if (parsedCommit != null && (firstCommit || !commit.IsTag))
                {
                    this._releaseNoteParser.ParseReleaseNotes(releaseNotes, parsedCommit);
                }

                this._writer.RemoveIndent();

                if (firstCommit)
                {
                    if (!commit.IsTag && commit.RawText.StartsWith("Merge ", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    firstCommitIsTag = commit.IsTag;
                    metadata         = commit.Sha;
                }

                if (!firstCommit && commit.IsTag)
                {
                    break;
                }

                if (firstCommit || !commit.IsTag)
                {
                    commitCount++;
                }

                firstCommit = false;
            }

            if (version?.IsEmpty() != false)
            {
                if (!string.IsNullOrEmpty(this.config.Tag))
                {
                    version = VersionData.Parse(this.config.NextVersion + "-" + this.config.Tag);
                    if (firstCommitIsTag)
                    {
                        version.Weight = 1;
                    }
                }
                else
                {
                    version = VersionData.Parse(this.config.NextVersion);
                }
            }

            var versionBumped = false;

            if (!firstCommitIsTag)
            {
                versionBumped = ForceNextVersion(version);
            }
            else if (version.MajorMinorPatch == "0.0.0")
            {
                version.SetNextBump(VersionBump.None, true);
                versionBumped = ForceNextVersion(version);
            }

            version.Metadata = metadata;
            version.Commits  = commitCount;
            if (!firstCommitIsTag && versionBumped &&
                !string.IsNullOrEmpty(this.config.Tag) &&
                !string.Equals(this.config.Tag, version.PreReleaseLabel, StringComparison.OrdinalIgnoreCase) &&
                string.Compare(this.config.Tag, version.PreReleaseLabel, StringComparison.OrdinalIgnoreCase) > 0)
            {
                version.PreReleaseLabel = this.config.Tag;
                version.Weight          = Math.Max(version.Weight ?? 1, 1);
            }

            return(new ParsedData(version, releaseNotes));
        }