/// <summary> /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release. /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p> /// </summary> /// <param name="changelogFile">The path to the changelog file.</param> /// <param name="tag">The <see cref="NuGetVersion"/> to finalize the changelog.</param> /// <param name="repository">The repository to create the version overview for.</param> /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/> public static void FinalizeChangelog(ChangeLog changelogFile, NuGetVersion tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRootRelativePath(changelogFile.Path)} for '{tag}'..."); var unreleasedNotes = changelogFile.Unreleased; var releaseNotes = changelogFile.ReleaseNotes; var lastReleased = changelogFile.LatestVersion; ControlFlow.Assert(unreleasedNotes != null, "Changelog should have draft section."); ControlFlow.Assert(releaseNotes.Any(x => x.Version != null && x.Version.Equals(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(lastReleased != null && tag.CompareTo(lastReleased.Version) > 0, $"Tag '{tag}' is not greater compared to last tag '{lastReleased.NotNull().Version}'."); var path = changelogFile.Path; var content = TextTasks.ReadAllLines(path).ToList(); content.Insert(unreleasedNotes.StartIndex + 1, string.Empty); content.Insert(unreleasedNotes.EndIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); UpdateVersionSummary(tag.ToString(), content, repository); content.Add(string.Empty); TextTasks.WriteAllLines(path, content); }
/// <summary> /// Finalizes the changelog by moving all entries from `[vNext]` to the version specified by release. /// <p>If <paramref name="repository"/> is specified a summary with all versions and links to list the changes directly on GitHub is appended to the end of the changelog.</p> /// </summary> /// <param name="changelogFile">The path to the changelog file.</param> /// <param name="tag">The version to finalize the changelog.</param> /// <param name="repository">The repository to create the version overview for.</param> /// <seealso cref="FinalizeChangelog(ChangeLog,NuGetVersion,GitRepository)"/> public static void FinalizeChangelog(string changelogFile, string tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRootRelativePath(changelogFile)} for '{tag}'..."); var content = TextTasks.ReadAllLines(changelogFile).ToList(); var sections = GetReleaseSections(content).ToList(); var firstSection = sections.First(); var secondSection = sections.Skip(1).FirstOrDefault(); ControlFlow.Assert(firstSection.Caption.All(char.IsLetter), "Cannot find a draft section."); ControlFlow.Assert(sections.All(x => !x.Caption.EqualsOrdinalIgnoreCase(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(firstSection.EndIndex > firstSection.StartIndex, $"Draft section '{firstSection.Caption}' does not contain any information."); ControlFlow.Assert(secondSection == null || NuGetVersion.Parse(tag).CompareTo(NuGetVersion.Parse(secondSection.Caption)) > 0, $"Tag '{tag}' is not greater compared to last tag '{secondSection?.Caption}'."); content.Insert(firstSection.StartIndex + 1, string.Empty); content.Insert(firstSection.StartIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); UpdateVersionSummary(tag, content, repository); content.Add(string.Empty); TextTasks.WriteAllLines(changelogFile, content); }
public static void FinalizeChangelog(string changelogFile, string tag, [CanBeNull] GitRepository repository = null) { Logger.Info($"Finalizing {PathConstruction.GetRootRelativePath(changelogFile)} for '{tag}'..."); var content = TextTasks.ReadAllLines(changelogFile).ToList(); var sections = GetReleaseSections(content).ToList(); var firstSection = sections.First(); var secondSection = sections.Skip(1).FirstOrDefault(); ControlFlow.Assert(firstSection.Caption.All(char.IsLetter), "Cannot find a draft section."); ControlFlow.Assert(sections.All(x => !x.Caption.EqualsOrdinalIgnoreCase(tag)), $"Tag '{tag}' already exists."); ControlFlow.Assert(firstSection.EndIndex > firstSection.StartIndex, $"Draft section '{firstSection.Caption}' does not contain any information."); ControlFlow.Assert(secondSection == null || NuGetVersion.Parse(tag).CompareTo(NuGetVersion.Parse(secondSection.Caption)) > 0, $"Tag '{tag}' is not greater compared to last tag '{secondSection?.Caption}'."); content.Insert(firstSection.StartIndex + 1, string.Empty); content.Insert(firstSection.StartIndex + 2, $"## [{tag}] / {DateTime.Now:yyyy-MM-dd}"); if (repository != null && repository.IsGitHubRepository()) { sections = GetReleaseSections(content).ToList(); firstSection = sections.First(); var lastSection = sections.Last(); content.RemoveRange(lastSection.EndIndex + 1, content.Count - lastSection.EndIndex - 1); content.Add(string.Empty); content.Add($"[{firstSection.Caption}]: {repository}/compare/{tag}...HEAD"); for (var i = 1; i + 1 < sections.Count; i++) { content.Add($"[{sections[i].Caption}]: {repository}/compare/{sections[i + 1].Caption}...{sections[i].Caption}"); } content.Add($"[{lastSection.Caption}]: {repository}/tree/{lastSection.Caption}"); } content.Add(string.Empty); TextTasks.WriteAllLines(changelogFile, content); }