From 4202b95076810567ac6a3bacb3f8f2446148df2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Tue, 4 Aug 2015 16:03:13 +0200 Subject: [PATCH 1/3] Add --base option --- README.md | 11 +++++++++++ .../generator/generator_generation.rb | 2 ++ lib/github_changelog_generator/parser.rb | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 5b44191..29e36ed 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,17 @@ So, if you got error like this: It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP. + +## Migrating from a manual changelog + +Knowing how dedicated you are to your project, you probably haven't been waiting for github-changelog-generator to keep a changelog, +but you most likely wouln't like to have to open issues and PRs for all past features listed in your historic changelog. + +That's where `--base` comes handy. This option lets you pass a static changelog to be appended at the end of the generated entries. + +If you have a `HISTORY.md` file in your project, it will automatically be picked as the static historical changelog and appended. + + ##Features and advantages of this project - Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com/) :gem: - Possible to generate **Unreleased** changes (closed issues that have not released yet) :dizzy: diff --git a/lib/github_changelog_generator/generator/generator_generation.rb b/lib/github_changelog_generator/generator/generator_generation.rb index 7e8f7a2..a3dc986 100644 --- a/lib/github_changelog_generator/generator/generator_generation.rb +++ b/lib/github_changelog_generator/generator/generator_generation.rb @@ -16,6 +16,8 @@ module GitHubChangelogGenerator log += generate_log_for_all_tags end + log += File.read(@options[:base]) if File.file?(@options[:base]) + log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*" @log = log end diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index ff1b6f9..72dc79e 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -50,6 +50,9 @@ module GitHubChangelogGenerator opts.on("-o", "--output [NAME]", "Output file. Default is CHANGELOG.md") do |last| options[:output] = last end + opts.on("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last| + options[:base] = last + end opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v| options[:bug_prefix] = v end @@ -153,6 +156,7 @@ module GitHubChangelogGenerator tag2: nil, date_format: "%Y-%m-%d", output: "CHANGELOG.md", + base: "HISTORY.md", issues: true, add_issues_wo_labels: true, add_pr_wo_labels: true, From bfae7b9a452863ee01c06080e72811d8284753f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 5 Aug 2015 10:43:17 +0200 Subject: [PATCH 2/3] Auto detect since tag from base file --- .../generator/generator_tags.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 81c4466..7275fe3 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -52,6 +52,14 @@ module GitHubChangelogGenerator [newer_tag_link, newer_tag_name, newer_tag_time] end + def detect_since_tag + if File.file?(@options[:base]) + reader = GitHubChangelogGenerator::Reader.new + content = reader.read(@options[:base]) + return content[0]["version"] if content + end + end + # Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags # # @return [Array] @@ -64,6 +72,7 @@ module GitHubChangelogGenerator def filter_since_tag(all_tags) filtered_tags = all_tags tag = @options[:since_tag] + tag ||= detect_since_tag if tag if all_tags.map(&:name).include? tag idx = all_tags.index { |t| t.name == tag } From 9acca33bc2f845fc8b1c5442cf75d855204d6875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Wed, 12 Aug 2015 16:35:47 +0200 Subject: [PATCH 3/3] Test if @options[:base] is set --- lib/github_changelog_generator/generator/generator_tags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/generator/generator_tags.rb b/lib/github_changelog_generator/generator/generator_tags.rb index 7275fe3..bdc078d 100644 --- a/lib/github_changelog_generator/generator/generator_tags.rb +++ b/lib/github_changelog_generator/generator/generator_tags.rb @@ -53,7 +53,7 @@ module GitHubChangelogGenerator end def detect_since_tag - if File.file?(@options[:base]) + if @options[:base] && File.file?(@options[:base]) reader = GitHubChangelogGenerator::Reader.new content = reader.read(@options[:base]) return content[0]["version"] if content