renogen 0.0.1 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -3
- data/bin/renogen +2 -58
- data/lib/renogen.rb +9 -0
- data/lib/renogen/change_log.rb +9 -0
- data/lib/renogen/change_log/group.rb +21 -0
- data/lib/renogen/change_log/item.rb +60 -0
- data/lib/renogen/change_log/model.rb +41 -0
- data/lib/renogen/change_log/writer.rb +39 -0
- data/lib/renogen/cli.rb +60 -0
- data/lib/renogen/cli/param_parser.rb +73 -0
- data/lib/renogen/config.rb +35 -0
- data/lib/renogen/exceptions.rb +8 -0
- data/lib/renogen/exceptions/base.rb +7 -0
- data/lib/renogen/exceptions/extraction_stratagy_not_found.rb +20 -0
- data/lib/renogen/exceptions/formatter_not_found.rb +20 -0
- data/lib/renogen/extraction_stratagies.rb +42 -0
- data/lib/renogen/extraction_stratagies/base.rb +29 -0
- data/lib/renogen/extraction_stratagies/yaml_file.rb +10 -0
- data/lib/renogen/extraction_stratagies/yaml_file/parser.rb +39 -0
- data/lib/renogen/extraction_stratagies/yaml_file/provider.rb +24 -0
- data/lib/renogen/extraction_stratagies/yaml_file/reader.rb +48 -0
- data/lib/renogen/formatters.rb +43 -0
- data/lib/renogen/formatters/base.rb +54 -0
- data/lib/renogen/formatters/html.rb +47 -0
- data/lib/renogen/formatters/markdown.rb +33 -0
- data/lib/renogen/formatters/plain_text.rb +33 -0
- data/lib/renogen/generator.rb +34 -0
- data/lib/renogen/version.rb +3 -0
- data/spec/lib/renogen/change_log/group_spec.rb +13 -0
- data/spec/lib/renogen/change_log/item_spec.rb +51 -0
- data/spec/lib/renogen/change_log/model_spec.rb +36 -0
- data/spec/lib/renogen/change_log/writer_spec.rb +8 -0
- data/spec/lib/renogen/config_spec.rb +19 -0
- data/spec/lib/renogen/exceptions/extraction_stratagy_not_found_spec.rb +13 -0
- data/spec/lib/renogen/exceptions/formatter_not_found_spec.rb +13 -0
- data/spec/lib/renogen/extraction_stratagies/base_spec.rb +10 -0
- data/spec/lib/renogen/extraction_stratagies/yaml_file/parser_spec.rb +24 -0
- data/spec/lib/renogen/extraction_stratagies/yaml_file/provider_spec.rb +12 -0
- data/spec/lib/renogen/extraction_stratagies/yaml_file/reader_spec.rb +20 -0
- data/spec/lib/renogen/formatters/base_spec.rb +21 -0
- data/spec/lib/renogen/formatters/html_spec.rb +38 -0
- data/spec/lib/renogen/formatters/markdown_spec.rb +29 -0
- data/spec/lib/renogen/formatters/plain_text_spec.rb +29 -0
- data/spec/lib/renogen_spec.rb +11 -0
- data/spec/spec_helper.rb +76 -0
- metadata +67 -9
@@ -0,0 +1,33 @@
|
|
1
|
+
module Renogen
|
2
|
+
module Formatters
|
3
|
+
# For formatting a change into markdown format
|
4
|
+
class Markdown < Base
|
5
|
+
register :markdown
|
6
|
+
register :md
|
7
|
+
|
8
|
+
# Outputs a line or block of text appearing at the top of the change log.
|
9
|
+
#
|
10
|
+
# @param header [String]
|
11
|
+
# @return [String]
|
12
|
+
def write_header(header)
|
13
|
+
"# #{header}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Outputs a line or block as a header for a group.
|
17
|
+
#
|
18
|
+
# @param group [String]
|
19
|
+
# @return [String]
|
20
|
+
def write_group(group)
|
21
|
+
"### #{group}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Outputs a line or block as the body for a change.
|
25
|
+
#
|
26
|
+
# @param change [String]
|
27
|
+
# @return [String]
|
28
|
+
def write_change(change)
|
29
|
+
"* #{change}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Renogen
|
2
|
+
module Formatters
|
3
|
+
# For formatting a change as plain text
|
4
|
+
class PlainText < Base
|
5
|
+
register :plain_text
|
6
|
+
register :text
|
7
|
+
|
8
|
+
# Outputs a line or block of text appearing at the top of the change log.
|
9
|
+
#
|
10
|
+
# @param header [String]
|
11
|
+
# @return [String]
|
12
|
+
def write_header(header)
|
13
|
+
"#{header}\n "
|
14
|
+
end
|
15
|
+
|
16
|
+
# Outputs a line or block as a header for a group.
|
17
|
+
#
|
18
|
+
# @param group [String]
|
19
|
+
# @return [String]
|
20
|
+
def write_group(group)
|
21
|
+
"#{group}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Outputs a line or block as the body for a change.
|
25
|
+
#
|
26
|
+
# @param change [String]
|
27
|
+
# @return [String]
|
28
|
+
def write_change(change)
|
29
|
+
"- #{change}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Renogen
|
2
|
+
class Generator
|
3
|
+
attr_accessor :source, :version, :output_format, :options
|
4
|
+
|
5
|
+
def initialize(version, source, output_format, options={})
|
6
|
+
@version = version
|
7
|
+
@source = source
|
8
|
+
@output_format = output_format
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
# Create the change log
|
13
|
+
def generate!
|
14
|
+
changelog = extraction_stratagy.extract
|
15
|
+
changelog.version = version
|
16
|
+
|
17
|
+
writer.write!(changelog)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def writer
|
23
|
+
Renogen::ChangeLog::Writer.new(formatter)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extraction_stratagy
|
27
|
+
Renogen::ExtractionStratagies.obtain(source, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def formatter
|
31
|
+
Renogen::Formatters.obtain(output_format, options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::ChangeLog::Item do
|
4
|
+
let(:change) { Array.new }
|
5
|
+
subject { described_class.new('foo', change) }
|
6
|
+
|
7
|
+
describe '#to_s' do
|
8
|
+
context "when change type is a 'String'" do
|
9
|
+
let(:change) { "foo\nbar\n" }
|
10
|
+
it 'returns string with newline at end' do
|
11
|
+
expect(subject.to_s).to eql "foo\nbar\n\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when change type is a 'Hash'" do
|
16
|
+
let(:change) { Hash.new }
|
17
|
+
it 'returns single line string' do
|
18
|
+
config = Renogen::Config.instance
|
19
|
+
string = config.single_line_format.downcase.gsub('\n', '\n ')
|
20
|
+
config.supported_keys.each do |key|
|
21
|
+
string = string.gsub(key, '')
|
22
|
+
end
|
23
|
+
expect(subject.to_s).to eql string
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when change type is a 'Array'" do
|
28
|
+
let(:change) { Array.new }
|
29
|
+
it 'returns array' do
|
30
|
+
expect(subject.to_s).to eql change
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when change type is unknown" do
|
35
|
+
let(:change) { described_class }
|
36
|
+
it 'raises a type error' do
|
37
|
+
expect{subject.to_s}.to raise_error TypeError
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#list?' do
|
43
|
+
it 'returns true when change is an array type' do
|
44
|
+
expect(subject.list?).to be_truthy
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#each' do
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::ChangeLog::Model do
|
4
|
+
let(:change_item) { Renogen::ChangeLog::Item.new('foo', 'bar') }
|
5
|
+
|
6
|
+
describe '#groups' do
|
7
|
+
it 'returns an empty hash when no changes' do
|
8
|
+
expect(subject.groups).to eql Hash.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns hash of changes by group_name' do
|
12
|
+
subject.add_change(change_item)
|
13
|
+
expect(subject.groups).to eql({change_item.group_name => [change_item]})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#header' do
|
18
|
+
it 'returns version and date' do
|
19
|
+
subject.version = '123'
|
20
|
+
expect(subject.header).to eql "123 (#{Date.today})"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#add_change' do
|
25
|
+
it 'adds change to changes store' do
|
26
|
+
subject.add_change(change_item)
|
27
|
+
expect(subject.items.first).to eql change_item
|
28
|
+
expect(subject.items.size).to eql 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises error when non valid change is added' do
|
32
|
+
expect{subject.add_change('bar')}.to raise_error TypeError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Config do
|
4
|
+
|
5
|
+
subject { described_class.instance }
|
6
|
+
|
7
|
+
describe '#configure' do
|
8
|
+
before :each do
|
9
|
+
described_class.configure do |config|
|
10
|
+
config.single_line_format = 'bar'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can set value' do
|
15
|
+
expect(subject.single_line_format).to eql 'bar'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Exceptions::ExtractionStratagyNotFound do
|
4
|
+
let(:name) { 'foobar' }
|
5
|
+
subject { described_class.new(name) }
|
6
|
+
|
7
|
+
describe '#message' do
|
8
|
+
it 'returns friendly error message' do
|
9
|
+
expect(subject.message).to eql "Error: Unsupported source type '#{name}'"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Exceptions::FormatterNotFound do
|
4
|
+
let(:name) { 'foobar' }
|
5
|
+
subject { described_class.new(name) }
|
6
|
+
|
7
|
+
describe '#message' do
|
8
|
+
it 'returns friendly error message' do
|
9
|
+
expect(subject.message).to eql "Error: Unsupported format type '#{name}'"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::ExtractionStratagies::YamlFile::Parser do
|
4
|
+
let(:file_contents) { { 'Foo' => 'Bar' } }
|
5
|
+
|
6
|
+
describe '#parse!' do
|
7
|
+
before :each do
|
8
|
+
yaml_file_reader = double(Renogen::ExtractionStratagies::YamlFile::Reader)
|
9
|
+
allow(yaml_file_reader).to receive(:each_yaml_file).and_yield(file_contents)
|
10
|
+
allow(Renogen::ExtractionStratagies::YamlFile::Reader).to receive(:new).and_return(yaml_file_reader)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'extracts contents from file' do
|
14
|
+
changelog_item = Renogen::ChangeLog::Item.new('Foo', 'Bar')
|
15
|
+
allow(Renogen::ChangeLog::Item).to receive(:new).with('Foo', 'Bar').and_return changelog_item
|
16
|
+
|
17
|
+
changelog = subject.parse!
|
18
|
+
|
19
|
+
expect(changelog.items).to include changelog_item
|
20
|
+
expect(changelog.items.size).to eql 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::ExtractionStratagies::YamlFile::Provider do
|
4
|
+
it "is returned for 'yaml_file'" do
|
5
|
+
expect(Renogen::ExtractionStratagies.obtain(:yaml_file)).to be_a described_class
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is returned for 'yaml'" do
|
9
|
+
expect(Renogen::ExtractionStratagies.obtain(:yaml)).to be_a described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe Renogen::ExtractionStratagies::YamlFile::Reader do
|
5
|
+
let(:directory_path) { './my/directory/path' }
|
6
|
+
subject { described_class.new(directory_path) }
|
7
|
+
|
8
|
+
describe '#each_yaml_file' do
|
9
|
+
let(:file_contents) { { 'Foo' => 'Bar' }.to_json }
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
allow(Dir).to receive(:glob).with([File.join(directory_path, 'next', "*.yml")]).and_return(['foo_file'])
|
13
|
+
allow(YAML).to receive(:load_file).with('foo_file').and_return(file_contents)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'yields each yaml file within given directory' do
|
17
|
+
expect{ |b| subject.each_yaml_file(&b) }.to yield_with_args(file_contents)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Formatters::Base do
|
4
|
+
describe '#write_header' do
|
5
|
+
it 'raises an NotImplementedError' do
|
6
|
+
expect{subject.write_header('header')}.to raise_error NotImplementedError
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#write_group' do
|
11
|
+
it 'raises an NotImplementedError' do
|
12
|
+
expect{subject.write_group('group_name')}.to raise_error NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#write_change' do
|
17
|
+
it 'raises an NotImplementedError' do
|
18
|
+
expect{subject.write_change('change')}.to raise_error NotImplementedError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Formatters::Html do
|
4
|
+
|
5
|
+
it 'is registered' do
|
6
|
+
expect(Renogen::Formatters.obtain(:html)).to be_kind_of described_class
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#write_header' do
|
10
|
+
it 'returns header with newline' do
|
11
|
+
expect(subject.write_header('header')).to eql "<html>\n<h1>header</h1>"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#write_group' do
|
16
|
+
it 'returns group' do
|
17
|
+
expect(subject.write_group('group')).to eql "<h2>group</h2>\n<ul>"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#write_group_end' do
|
22
|
+
it 'returns closing list tag' do
|
23
|
+
expect(subject.write_group_end).to eql "</ul>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#write_change' do
|
28
|
+
it 'returns change with newline and hyphen' do
|
29
|
+
expect(subject.write_change('change')).to eql " <li>change</li>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#write_footer' do
|
34
|
+
it 'returns closing html tag' do
|
35
|
+
expect(subject.write_footer('change')).to eql '</html>'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Formatters::Markdown do
|
4
|
+
it "is returned for 'markdown'" do
|
5
|
+
expect(Renogen::Formatters.obtain(:markdown)).to be_kind_of described_class
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is returned for 'md'" do
|
9
|
+
expect(Renogen::Formatters.obtain(:md)).to be_kind_of described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#write_header' do
|
13
|
+
it 'returns header with newline' do
|
14
|
+
expect(subject.write_header('header')).to eql "# header"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#write_group' do
|
19
|
+
it 'returns group' do
|
20
|
+
expect(subject.write_group('group')).to eql "### group"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#write_change' do
|
25
|
+
it 'returns change with newline and hyphen' do
|
26
|
+
expect(subject.write_change('change')).to eql "* change"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Renogen::Formatters::PlainText do
|
4
|
+
it "is returned for 'plain_text'" do
|
5
|
+
expect(Renogen::Formatters.obtain(:plain_text)).to be_kind_of described_class
|
6
|
+
end
|
7
|
+
|
8
|
+
it "is returned for 'text'" do
|
9
|
+
expect(Renogen::Formatters.obtain(:text)).to be_kind_of described_class
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#write_header' do
|
13
|
+
it 'returns header with newline' do
|
14
|
+
expect(subject.write_header('header')).to eql "header\n "
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#write_group' do
|
19
|
+
it 'returns group' do
|
20
|
+
expect(subject.write_group('group')).to eql "group"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#write_change' do
|
25
|
+
it 'returns change with newline and hyphen' do
|
26
|
+
expect(subject.write_change('change')).to eql "- change"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|