private string WriteLog(List <CommitMessage> commits, ChangelogOptions options) { Writer writer = new Writer(); string changelog = writer.WriteLog(commits, new WriterOptions() { Version = options.Version, Subtitle = options.Subtitle, WriteOthers = options.WriteOthers }); string filePath = Path.IsPathRooted(options.File) ? options.File : Path.Combine(options.WorkingDirectory, options.File); string currentlog = ""; if (File.Exists(filePath)) { currentlog = File.ReadAllText(filePath, Encoding.UTF8); } //var matches = Regex.Match(currentlog, @"<a\s+name=\""(?<version>.+)""></a>.*"); //if (matches.Success && options.Version.Equals(matches.Groups["version"].Value, StringComparison.InvariantCultureIgnoreCase)) if (!options.AlwaysPrepends && currentlog.StartsWith(string.Format(Writer.HEADER_TPL_PRE, options.Version))) { currentlog = RemoveLastVersion(currentlog, options.Version); } File.WriteAllText(filePath, changelog + "\n" + currentlog, Encoding.UTF8); return(changelog); }
public static string GitChangelog(this ICakeContext context, ChangeLogSettings settings) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (settings.WorkingDirectory.IsRelative) { settings.WorkingDirectory = settings.WorkingDirectory.MakeAbsolute(context.Environment); } if (settings.File.IsRelative) { settings.File = settings.File.MakeAbsolute(settings.WorkingDirectory); } var options = new ChangelogOptions { Version = settings.Version, From = settings.From, To = settings.To, Grep = settings.Grep, Subtitle = settings.Subtitle, WorkingDirectory = settings.WorkingDirectory.FullPath, File = settings.File.FullPath, AlwaysPrepends = settings.AlwaysPrepends }; var gen = new Changelog(); return(gen.Generate(options)); }
private string GetChangelogCommits(string tag, ChangelogOptions options) { string from = (!String.IsNullOrEmpty(tag)) ? tag : options.From; var git = new Git(options.WorkingDirectory); var commits = git.GetCommits(grep: options.Grep, from: from, to: options.To ?? "HEAD"); return(WriteLog(commits, options)); }
public string Generate(ChangelogOptions options) { if (String.IsNullOrEmpty(options.Version)) { throw new Exception("No version specified"); } var git = new Git(options.WorkingDirectory); // Get the latest tag or commit string tag; try { tag = git.LatestTag(); } catch (GitException ex) { throw new GitException("Failed to read git tags: " + ex.Message, ex); } return(GetChangelogCommits(tag, options)); }