Skip to content
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

Add pending changelog for unreleased changes #51

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
The format is 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).

## Pending Changes
### Added
- Ability to include pending changes in changelog for unreleased changes
- Test for the release preview flag

---
## 0.8.0
### Added
- Preview option for changelogs on the `release` and `bump` command
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ $ codelog release 1.0.0 --preview
```
Will display a preview of your changes on your console as if the version **1.0.0** has been released.

### Add Pending Releases to Changelog

You may find yourself wanting to include all of your unreleased changes in your changelog, whether it be for testing purposes or as a list of changes coming soon. The `pending` command does that for you.

```bash
$ codelog pending <TITLE>
```

`TITLE` is an option argument that is effectively the "Version" pending. The default value is `Pending Changes`.

## Configuring

Since version 0.3.0, there are a few configurations that are possible. You can choose:
Expand Down
1 change: 1 addition & 0 deletions changelogs/codelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

header_textfile: changelogs/header.txt
default_changelog_filename: CHANGELOG.md
default_pending_changes_title: "Pending Changes"

# Tag formatting ---------------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions changelogs/releases/pending.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Pending Changes
### Added
- Ability to include pending changes in changelog for unreleased changes
- Test for the release preview flag

---
3 changes: 3 additions & 0 deletions changelogs/unreleased/20210407134249312_change.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Added":
- Ability to include pending changes in changelog for unreleased changes
- Test for the release preview flag
1 change: 1 addition & 0 deletions lib/codelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'codelog/command/regenerate'
require 'codelog/command/release'
require 'codelog/command/preview'
require 'codelog/command/pending'
require 'codelog/command/bump'
require 'codelog/command/step/changelog'
require 'codelog/command/step/delete'
Expand Down
7 changes: 7 additions & 0 deletions lib/codelog/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def release(version_number,
end
end

desc 'pending <TITLE>', 'Generate pending changelog from unreleased files'
method_option :title, desc: 'Title to use for the unreleased changes section',
aliases: ['-t', '--title'], type: :string
def pending(title = Codelog::Config.pending_changes_title)
Codelog::Command::Pending.run title
end

desc 'bump [VERSION_TYPE] <RELEASE_DATE>', "Bumps the next version, \
being it major, minor or patch"
method_option :preview, desc: 'Prints the preview of the next version',
Expand Down
20 changes: 20 additions & 0 deletions lib/codelog/command/pending.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Codelog
module Command
class Pending
RELEASES_PATH = 'changelogs/releases'.freeze

def self.run(title)
Codelog::Command::Pending.new.run title
end

def run(title)
outputter = Codelog::Output::ReleaseFile.new("#{RELEASES_PATH}/pending.md")
Codelog::Command::Step::Version.run title,
Date.today.strftime(Codelog::Config.date_input_format),
outputter
Codelog::Command::Step::Changelog.run
puts "\n== Pending changes added to changelog =="
end
end
end
end
2 changes: 1 addition & 1 deletion lib/codelog/command/regenerate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.run

def run
Codelog::Command::Step::Changelog.run
puts "The CHANGELOG was regenerated successfully!"
puts 'The CHANGELOG was regenerated successfully!'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/codelog/command/step/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def changes
version_changelogs = Dir['changelogs/releases/*.md']
version_changelogs.sort_by! do |file_name|
version_number = file_name.split('/').last.chomp('.md')
Gem::Version.new(version_number)
version_number == 'pending' ? version_number : Gem::Version.new(version_number).to_s
end.reverse!
version_changelogs.inject([]) do |partial_changes, version_changelog|
partial_changes + File.readlines(version_changelog)
Expand Down
1 change: 1 addition & 0 deletions lib/codelog/command/step/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.run
def run
chdir Dir.pwd do
system('rm -rv changelogs/unreleased/*.yml')
system('[ -f changelogs/releases/pending.md ] && rm -rv changelogs/releases/pending.md')
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/codelog/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def filename
settings['default_changelog_filename'] || 'CHANGELOG.md'
end

def pending_changes_title
settings['default_pending_changes_title'] || 'Pending Changes'
end

def header
File.open(settings['header_textfile'], 'r').read || ''
end
Expand Down
2 changes: 1 addition & 1 deletion lib/codelog/output/release_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.print(content, file_path)

def print(content)
Dir.chdir Dir.pwd do
File.open(@file_path, 'a') do |line|
File.open(@file_path, 'w+') do |line|
line.puts content
end
end
Expand Down
25 changes: 25 additions & 0 deletions spec/codelog/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@
subject.release '1.2.3', '2012-12-12'
expect(Codelog::Command::Release).to have_received(:run).with '1.2.3', '2012-12-12'
end

it 'calls the release command with the preview flag' do
allow(Codelog::Command::Preview).to receive(:run)
subject.options = {preview: true}
subject.release '1.2.3', '2012-12-12'
expect(Codelog::Command::Preview).to have_received(:run).with '1.2.3', '2012-12-12'
end
end
end

describe '#regenerate' do
it 'calls the regenerate command' do
allow(Codelog::Command::Regenerate).to receive(:run)
subject.regenerate
expect(Codelog::Command::Regenerate).to have_received(:run)
end
end

describe '#pending' do
context 'passing the title as an argument' do
it 'calls the pending command' do
allow(Codelog::Command::Pending).to receive(:run)
subject.pending 'Pending Changes'
expect(Codelog::Command::Pending).to have_received(:run).with 'Pending Changes'
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions spec/codelog/command/pending_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe Codelog::Command::Pending do
describe '#run' do
let(:mock_file_outputter) { double(Codelog::Output::ReleaseFile) }

it 'adds the pending changes to the changelog' do
allow(Codelog::Command::Step::Version).to receive(:new)
allow(Codelog::Output::ReleaseFile).to receive(:new).and_return(mock_file_outputter)

expect(Codelog::Command::Step::Version).to receive(:run).with('Pending Changes', Date.today.strftime(Codelog::Config.date_input_format), mock_file_outputter)
expect(Codelog::Command::Step::Changelog).to receive(:run)
expect(subject).to receive(:puts).with("\n== Pending changes added to changelog ==")
subject.run 'Pending Changes'
end
end

describe '.run' do
it 'creates an instance of the class to run the command' do
expect_any_instance_of(described_class).to receive(:run).with 'Pending Changes'
described_class.run 'Pending Changes'
end
end
end
10 changes: 8 additions & 2 deletions spec/codelog/command/regenerate_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'spec_helper'

describe Codelog::Command::Regenerate do
describe '#run' do
it 'calls the "Changelog" step to re-generate the CHANGELOG using existing releases' do
expect(Codelog::Command::Step::Changelog).to receive(:run)
expect(subject).to receive(:puts).with("The CHANGELOG was regenerated successfully!")
subject.run
end
end

describe '.run' do
it 'calls the "Changelog" step to re-generate the CHANGELOG using existing releases' do
allow(Codelog::Command::Step::Changelog).to receive(:run)

described_class.run

expect(Codelog::Command::Step::Changelog).to have_received(:run)
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/codelog/command/step/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

it 'creates a changelog file from the releases' do
allow(mocked_changelog).to receive(:puts)
expect(File).to receive(:open).with('changelogs/header.txt', 'r').and_return(mocked_header_textfile)
expect(File).to receive(:open).with('CHANGELOG.md', 'w+').and_yield mocked_changelog
subject.run
expect(mocked_changelog).to have_received(:puts).with(['line_2\n', 'line_1\n'])
Expand Down
2 changes: 2 additions & 0 deletions spec/codelog/command/step/delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
it 'removes all the files from the unreleased folder' do
expect(subject).to have_received(:system)
.with('rm -rv changelogs/unreleased/*.yml')
expect(subject).to have_received(:system)
.with('[ -f changelogs/releases/pending.md ] && rm -rv changelogs/releases/pending.md')
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/codelog/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
end
end

describe '#pending_changes_title' do
it 'returns the correct pending changelog title' do
expect(described_class.pending_changes_title).to eq('Pending Changes')
end
end

describe '#header' do
let(:mocked_header_file) { double(File, read: 'stubbed header') }

Expand Down
2 changes: 1 addition & 1 deletion spec/codelog/output/release_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it 'prints the passed content in a file on the passed path' do
subject

expect(File).to have_received(:open).with(file_path, 'a')
expect(File).to have_received(:open).with(file_path, 'w+')
expect(mocked_file).to have_received(:puts).with(file_content)
end
end
Expand Down