Skip to content

Add --base option #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def compound_changelog
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
Expand Down
9 changes: 9 additions & 0 deletions lib/github_changelog_generator/generator/generator_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def detect_link_tag_time(newer_tag)
[newer_tag_link, newer_tag_name, newer_tag_time]
end

def detect_since_tag
if @options[:base] && 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]
Expand All @@ -64,6 +72,7 @@ def get_filtered_tags(all_tags)
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 }
Expand Down
4 changes: 4 additions & 0 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def self.setup_parser(options)
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
Expand Down Expand Up @@ -153,6 +156,7 @@ def self.get_default_options
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,
Expand Down