diff --git a/CHANGELOG.md b/CHANGELOG.md index b3dd910..8dc2b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Next + + ## 2.5.0 (September 2019) ### User-facing diff --git a/tasks/changelog.rake b/tasks/changelog.rake new file mode 100644 index 0000000..857e257 --- /dev/null +++ b/tasks/changelog.rake @@ -0,0 +1,37 @@ +require "fileutils" + +# Helper method to insert text after a line that matches the regex +def insert_after_line(file, insert, regex = /^## Next/) + tempfile = File.open("#{file}.tmp", "w") + f = File.new(file) + f.each do |line| + tempfile << line + next unless line =~ regex + + tempfile << "\n" + tempfile << insert + tempfile << "\n" + end + f.close + tempfile.close + + FileUtils.mv("#{file}.tmp", file) +end + +# Extracts all changes that have been made after the latest pushed tag +def changes_since_last_tag + `git --no-pager log $(git describe --tags --abbrev=0)..HEAD --grep="Merge" --pretty=format:"%t - %s%n%b%n"` +end + +# Extracts all github users contributed since last tag +def users_since_last_tag + `git --no-pager log $(git describe --tags --abbrev=0)..HEAD --grep="Merge" --pretty=format:"%s" | cut -d' ' -f 6 | cut -d/ -f1 | uniq` +end + +namespace :changelog do + task :generate do + insert_after_line("CHANGELOG.md", changes_since_last_tag, /^## Next/) + printf("Users contributed since last release:\n") + printf(users_since_last_tag) + end +end