codelog 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8ac42eba02c56c3f16d9726d8912bf96fdb8a0b
4
- data.tar.gz: f5ad7ff1277ebd0e34e7dfcb31dda71675c8344e
3
+ metadata.gz: 67568d91a6f6e61135b6fc3da1aa52ba3c393d1b
4
+ data.tar.gz: b43bfaca90fe3fdaed293812190bb6bbd4dd2c1b
5
5
  SHA512:
6
- metadata.gz: 281e98ad63b396e1ed291f8c276a2a9721359b817fee5ce3da115280dab3915eacb725f4736200c81ba6a041dac52638278fc6013962dd141e1656c555c31a9d
7
- data.tar.gz: 83b6518cddb2cf1ea6d09d4149e68517907aed4cb5a5f22b85f5d08f18e25a4a69cf98d9e4507f1169323dfc86d05d78bc0a7efaa7df542e37488291bd30eb6e
6
+ metadata.gz: 95ea31468c7bb6b76132bff6283e14af7fb1b40b4b8f1990b088201e5e3c2f656c276f8477af07608c9fb07b2479cb3fd9ab9ae05c782f3d6d5e3d7dcab5bae4
7
+ data.tar.gz: be34ae8933a17d24be14d5a2adc07fe417018c7345135a7a1bf7fe5307f1bd2c5881badc0613f6e1808ccf1a17151be55de7bbae5b206f15adba3de0b17f5fe7
data/CHANGELOG.md CHANGED
@@ -1,8 +1,27 @@
1
1
  # Changelog
2
- All notable changes to this project will be documented in this file.
3
- The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4
- and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
-
2
+ All notable changes to this project will be documented in this file.
3
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
+
6
+ ## 0.3.0
7
+ ### Changed
8
+ - Human-readable timestamp for the change files
9
+ - Altered setup to print message instead of aborting when creating files
10
+ - Changelog header is now configurable through 'changelogs/header.txt'
11
+ - Insulated abort messages within Codelog::Messages
12
+ - Blocked attempt to release a changelog with no changes
13
+ - Blocked attempt to release repeated versions from a changelog
14
+
15
+ ### Added
16
+ - Configurable filename
17
+ - Configurable input and output date formats
18
+ - Enable/Disable 'datestamps' within version tag
19
+ - Version prefix, version suffix and date prefix within version tag
20
+ - Previous existing changelog can now be merged upon 'codelog setup'
21
+ - Message after the release command
22
+ - Datestamps along with version tag (synthax codelog release [x.y.z] <DATE>)
23
+
24
+ ---
6
25
  ## 0.2.3
7
26
  ### Changed
8
27
  - Setup command now creates a .gitkeep file on /changelogs/releases folder
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  ![CodeLog logo](https://raw.githubusercontent.com/codus/codelog/master/codelog.png)
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/codelog.svg)](https://badge.fury.io/rb/codelog)
3
4
  [![Build Status](https://travis-ci.org/codus/codelog.svg?branch=master)](https://travis-ci.org/codus/codelog)
4
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/6f5885536c6b5c82f304/maintainability)](https://codeclimate.com/github/codus/codelog/maintainability)
5
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/6f5885536c6b5c82f304/test_coverage)](https://codeclimate.com/github/codus/codelog/test_coverage)
6
7
 
7
- This gem provides a simple way to manage changelogs, avoiding conflicts and missplaced informations. Changes are handled as if they were "migrations" and built when releasing a version, allowing a more precise knowledge of what changes were made to what version.
8
+ A gem to help big teams to manage their chagelogs.
9
+
10
+ When many people are developing changes to compose one product release, there can be some conflicts on merging the changes added to the Changelog. These conflicts can be badly resolved by git, which could cause lost of important release notes.
11
+
12
+ This gem provides a simple way to manage changelogs, avoiding these conflicts and missplaced informations. Changes are handled as if they were "migrations" and built when releasing a version, allowing a more precise knowledge of what changes were made to what version.
8
13
 
9
14
  ## Installation
10
15
 
@@ -63,7 +68,7 @@ The template can be as the following example:
63
68
 
64
69
  ## Usage
65
70
 
66
- After the initial setup every time a change is made, the user should run the following command in the project root path:
71
+ After the initial setup every time a change is made, the developer should run the following command in the project root path:
67
72
 
68
73
  ``` bash
69
74
  $ codelog new
@@ -73,11 +78,12 @@ This will generate a change file on `changelogs/unreleased/` from the `template.
73
78
 
74
79
  The new change file should be filled with informations about the implemented change, all unused topics should be erased and the file committed.
75
80
 
76
- When closing a version you should run the following command:
81
+ Once all changes were merged and the release is ready to be packed, all that must be done is to run the following command:
77
82
 
78
83
  ``` bash
79
84
  $ codelog release {x.y.z}
80
85
  ```
86
+ No conflicts to resolve. All changes documented.
81
87
 
82
88
  It will execute 3 steps:
83
89
 
@@ -85,6 +91,21 @@ It will execute 3 steps:
85
91
  - Deletes the change files at `changelogs/unreleased/` because they now compose the new release. If it was not deleted, the change would appear repeated in the next release.
86
92
  - Updates the `CHANGELOG.md` file by merging all the releases at `changelogs/releases/`.
87
93
 
94
+ ## Configuring
95
+
96
+ Since version 0.3.0, there are a few configurations that are possible. You can choose:
97
+ - The name of the Changelog file.
98
+ - The header of the Changelog file.
99
+ - The format of the version and date on the releases.
100
+ - Whether to show the release date or not.
101
+ - The enter format for the release date.
102
+
103
+ In case you were using version 0.2.0, you will have to run:
104
+
105
+ ```bash
106
+ $ codelog setup
107
+ ```
108
+
88
109
  ## Contributing
89
110
 
90
111
  Issue reports and pull requests are welcome on GitHub at https://github.com/codus/codelog. Read our [Contributing guide] for instructions on how to do it.
data/lib/codelog.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'codelog/version'
2
1
  require 'codelog/cli'
2
+ require 'codelog/config'
3
+ require 'codelog/message'
4
+ require 'codelog/version'
3
5
  require 'codelog/command/setup'
4
6
  require 'codelog/command/new'
5
7
  require 'codelog/command/release'
data/lib/codelog/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'date'
2
3
 
3
4
  module Codelog
4
5
  class CLI < Thor
@@ -8,14 +9,13 @@ module Codelog
8
9
  end
9
10
 
10
11
  desc 'new', 'Generate a file from the template for the unreleased changes'
11
- method_option :change, aliases: '-c', default: true, desc: 'Create a change file'
12
12
  def new
13
13
  Codelog::Command::New.run
14
14
  end
15
15
 
16
- desc 'release [VERSION]', 'Generate new release updating changelog'
17
- def release(version_number)
18
- Codelog::Command::Release.run version_number
16
+ desc 'release [VERSION] <RELEASE_DATE>', 'Generate new release updating changelog'
17
+ def release(version_number, release_date = Date.today.to_s)
18
+ Codelog::Command::Release.run version_number, release_date
19
19
  end
20
20
  end
21
21
  end
@@ -13,7 +13,7 @@ module Codelog
13
13
  chdir Dir.pwd do
14
14
  # This script create a change file for the changelog documentation.
15
15
 
16
- full_file_name = "changelogs/unreleased/#{Time.now.to_i}_change.yml"
16
+ full_file_name = "changelogs/unreleased/#{Time.now.strftime('%Y%m%d%H%M%S%L')}_change.yml"
17
17
 
18
18
  puts "== Creating #{full_file_name} change file based on example =="
19
19
  system! "cp changelogs/template.yml #{full_file_name}"
@@ -1,14 +1,15 @@
1
1
  module Codelog
2
2
  module Command
3
3
  class Release
4
- def self.run(version_number)
5
- Codelog::Command::Release.new.run version_number
4
+ def self.run(version_number, release_date)
5
+ Codelog::Command::Release.new.run version_number, release_date
6
6
  end
7
7
 
8
- def run(version_number)
9
- Codelog::Command::Step::Version.run version_number
8
+ def run(version_number, release_date)
9
+ Codelog::Command::Step::Version.run version_number, release_date
10
10
  Codelog::Command::Step::Delete.run
11
11
  Codelog::Command::Step::Changelog.run
12
+ puts "\n== Changelog updated to version #{version_number} =="
12
13
  end
13
14
  end
14
15
  end
@@ -5,7 +5,12 @@ module Codelog
5
5
  class Setup
6
6
  include FileUtils
7
7
 
8
- TEMPLATE_FILE_PATH = File.dirname(__FILE__) + '/../../fixtures/template.yml'
8
+ TEMPLATE_FILE_PATH = File.dirname(__FILE__).concat('/../../fixtures/template.yml')
9
+ CONFIG_FILE_PATH = File.dirname(__FILE__).concat('/../../fixtures/codelog.yml')
10
+ HEADER_FILE_PATH = File.dirname(__FILE__).concat('/../../fixtures/header.txt')
11
+
12
+ CHANGELOG_DEFAULT_PATH = 'CHANGELOG.md'.freeze
13
+ CHANGELOG_DESTINATION_PATH = 'changelogs/releases/0.0.0.md'.freeze
9
14
 
10
15
  def self.run
11
16
  Codelog::Command::Setup.new.run
@@ -14,21 +19,65 @@ module Codelog
14
19
  def run
15
20
  chdir Dir.pwd do
16
21
  # This script provides the initial setup for the gem usage.
17
-
18
22
  puts '== Creating folder structure and template =='
19
- system! 'mkdir changelogs/'
20
- system! 'mkdir changelogs/unreleased'
21
- system! 'mkdir changelogs/releases'
22
- system! "cp #{TEMPLATE_FILE_PATH} changelogs/template.yml"
23
- system! 'touch changelogs/unreleased/.gitkeep'
24
- system! 'touch changelogs/releases/.gitkeep'
23
+ create_folder_structure
24
+ puts '== Copying fixtures =='
25
+ copy_fixtures
26
+ handle_existing_changelog
25
27
  end
26
28
  end
27
29
 
28
30
  private
29
31
 
32
+ def create_folder_structure
33
+ system! 'mkdir changelogs/'
34
+ system! 'mkdir changelogs/unreleased'
35
+ system! 'mkdir changelogs/releases'
36
+ system! 'touch changelogs/unreleased/.gitkeep'
37
+ system! 'touch changelogs/releases/.gitkeep'
38
+ end
39
+
40
+ def copy_fixtures
41
+ system! "cp #{TEMPLATE_FILE_PATH} changelogs/template.yml"
42
+ system! "cp #{CONFIG_FILE_PATH} changelogs/codelog.yml"
43
+ system! "cp #{HEADER_FILE_PATH} changelogs/header.txt"
44
+ end
45
+
46
+ def handle_existing_changelog
47
+ return unless old_changelog_exists?
48
+ if yes? Codelog::Message::Warning.mantain_versioning_of_existing_changelog?
49
+ puts '== Copying existing changelog to releases folder =='
50
+ copy_and_mark_changelog
51
+ elsif yes? Codelog::Message::Warning.delete_existing_changelog?
52
+ puts '== Deleting existing changelog =='
53
+ system! "rm #{CHANGELOG_DEFAULT_PATH}"
54
+ end
55
+ end
56
+
57
+ def old_changelog_exists?
58
+ File.file?(CHANGELOG_DEFAULT_PATH)
59
+ end
60
+
61
+ def copy_and_mark_changelog
62
+ File.open(CHANGELOG_DEFAULT_PATH, 'rb') do |orig|
63
+ File.open(CHANGELOG_DESTINATION_PATH, 'wb') do |dest|
64
+ dest.write("<!-- Old changelog starts here -->\n\n")
65
+ dest.write(orig.read)
66
+ end
67
+ end
68
+ end
69
+
30
70
  def system!(*args)
31
- system(*args) || abort("\n== Command #{args} failed ==")
71
+ system(*args) || puts("\n== Command #{args} was skipped ==")
72
+ end
73
+
74
+ def yes?(args)
75
+ puts(args)
76
+ receive
77
+ end
78
+
79
+ def receive(stdin: $stdin)
80
+ stdin.gets.chomp.casecmp('y').zero?
32
81
  end
33
82
  end
34
83
  end
@@ -30,12 +30,9 @@ module Codelog
30
30
  end
31
31
 
32
32
  def create_file_from(changes)
33
- File.open('CHANGELOG.md', 'w+') do |f|
34
- f.puts %(# Changelog
35
- All notable changes to this project will be documented in this file.
36
- The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
37
- and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
38
- )
33
+ File.open(Codelog::Config.filename, 'w+') do |f|
34
+ f.puts '# Changelog'
35
+ f.puts Codelog::Config.header
39
36
  f.puts(changes)
40
37
  end
41
38
  end
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  require 'yaml'
2
3
  require 'fileutils'
3
4
 
@@ -7,16 +8,26 @@ module Codelog
7
8
  class Version
8
9
  include FileUtils
9
10
 
10
- def initialize(version)
11
+ RELEASES_PATH = 'changelogs/releases'.freeze
12
+ UNRELEASED_LOGS_PATH = 'changelogs/unreleased'.freeze
13
+ CONFIG_FILE_PATH = 'changelogs/codelog.yml'.freeze
14
+
15
+ def initialize(version, release_date)
16
+ abort(Codelog::Message::Error.missing_config_file) unless config_file_exists?
11
17
  @version = version
18
+ @release_date = Date.strptime(release_date, Codelog::Config.date_input_format).to_s
19
+ rescue ArgumentError
20
+ abort(Codelog::Message::Error.invalid_date_format)
12
21
  end
13
22
 
14
- def self.run(version)
15
- Codelog::Command::Step::Version.new(version).run
23
+ def self.run(version, release_date)
24
+ Codelog::Command::Step::Version.new(version, release_date).run
16
25
  end
17
26
 
18
27
  def run
19
- abort('ERROR: Please enter a version number') if @version.nil?
28
+ abort(Codelog::Message::Error.missing_version_number) if @version.nil?
29
+ abort(Codelog::Message::Error.already_existing_version(@version)) if version_exists?
30
+ abort(Codelog::Message::Error.no_detected_changes(@version)) unless unreleased_changes?
20
31
  chdir Dir.pwd do
21
32
  create_version_changelog_from changes_hash
22
33
  end
@@ -25,7 +36,7 @@ module Codelog
25
36
  private
26
37
 
27
38
  def changes_hash
28
- change_files_paths = Dir['changelogs/unreleased/*.yml']
39
+ change_files_paths = Dir["#{UNRELEASED_LOGS_PATH}/*.yml"]
29
40
  change_files_paths.inject({}) do |all_changes, change_file|
30
41
  changes_per_category = YAML.load_file(change_file)
31
42
  all_changes.merge!(changes_per_category) do |category, changes, changes_to_be_added|
@@ -35,8 +46,8 @@ module Codelog
35
46
  end
36
47
 
37
48
  def create_version_changelog_from(changes_hash)
38
- File.open("changelogs/releases/#{@version}.md", 'a') do |line|
39
- line.puts "## #{@version}"
49
+ File.open("#{RELEASES_PATH}/#{@version}.md", 'a') do |line|
50
+ line.puts "## #{Codelog::Config.version_tag(@version, @release_date)}"
40
51
  changes_hash.each do |category, changes|
41
52
  line.puts "### #{category}"
42
53
  changes.each { |change| line.puts "- #{change}" }
@@ -45,6 +56,18 @@ module Codelog
45
56
  line.puts "---\n"
46
57
  end
47
58
  end
59
+
60
+ def version_exists?
61
+ File.file?("#{RELEASES_PATH}/#{@version}.md")
62
+ end
63
+
64
+ def unreleased_changes?
65
+ Dir["#{UNRELEASED_LOGS_PATH}/*.yml"].any?
66
+ end
67
+
68
+ def config_file_exists?
69
+ File.file?(CONFIG_FILE_PATH)
70
+ end
48
71
  end
49
72
  end
50
73
  end
@@ -0,0 +1,58 @@
1
+ require 'date'
2
+
3
+ module Codelog
4
+ class Config
5
+ CONFIG_FILE_PATH = 'changelogs/codelog.yml'.freeze
6
+
7
+ class << self
8
+ def filename
9
+ settings['default_changelog_filename'] || 'CHANGELOG.md'
10
+ end
11
+
12
+ def header
13
+ File.open(settings['header_textfile'], 'r').read || ''
14
+ end
15
+
16
+ def date_input_format
17
+ settings['date_input_format'] || '%Y-%m-%d'
18
+ end
19
+
20
+ def version_tag(version, release_date)
21
+ date_suffix =
22
+ if show_date?
23
+ parsed_date = Date.strptime(release_date, '%Y-%m-%d').strftime(date_output_format)
24
+ " - #{date_prefix}#{parsed_date}"
25
+ else
26
+ ''
27
+ end
28
+ "#{version_prefix}#{version}#{version_suffix}#{date_suffix}"
29
+ end
30
+
31
+ private
32
+
33
+ def date_output_format
34
+ settings['date_output_format'] || '%Y-%m-%d'
35
+ end
36
+
37
+ def version_prefix
38
+ settings['version_prefix'] || ''
39
+ end
40
+
41
+ def version_suffix
42
+ settings['version_suffix'] || ''
43
+ end
44
+
45
+ def date_prefix
46
+ settings['date_prefix'] || ''
47
+ end
48
+
49
+ def show_date?
50
+ settings['show_date']
51
+ end
52
+
53
+ def settings
54
+ @settings ||= YAML.load_file(CONFIG_FILE_PATH)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,56 @@
1
+ module Codelog
2
+ class Message
3
+ class Error
4
+ class << self
5
+ def prefix
6
+ 'ERROR'
7
+ end
8
+
9
+ def missing_version_number
10
+ "#{prefix}: Please enter a version number"
11
+ end
12
+
13
+ def invalid_date_format
14
+ "#{prefix}: Invalid date format. Check the input date format on:\n\n" \
15
+ 'changelogs/codelog.yml'
16
+ end
17
+
18
+ def already_existing_version(version)
19
+ "#{prefix}: Could not create release #{version}. Release #{version} already exists"
20
+ end
21
+
22
+ def no_detected_changes(version)
23
+ "#{prefix}: Could not create release #{version}. You must create a change first.\n" \
24
+ "Run the following command to create a new change file:\n\n" \
25
+ "codelog new\n\n" \
26
+ "Then describe your changes on the file generated at:\n\n" \
27
+ 'changelog/unreleased'
28
+ end
29
+
30
+ def missing_config_file
31
+ "#{prefix}: Could not find a config file.\n" \
32
+ "Run the following command to create the missing file:\n\n" \
33
+ 'codelog setup'
34
+ end
35
+ end
36
+ end
37
+
38
+ class Warning
39
+ class << self
40
+ def prefix
41
+ 'WARNING'
42
+ end
43
+
44
+ def mantain_versioning_of_existing_changelog?
45
+ "#{prefix}: There is already a file named CHANGELOG.md within " \
46
+ 'your project. Do you wish to mantain its versioning? (Y/N)'
47
+ end
48
+
49
+ def delete_existing_changelog?
50
+ "#{prefix}: When generating a release for the first " \
51
+ 'time, CHANGELOG.md will be erased. Do you wish to erase it now? (Y/N)'
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Codelog
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -0,0 +1,16 @@
1
+ # Changelog Header -------------------------------------------------
2
+
3
+ header_textfile: changelogs/header.txt
4
+ default_changelog_filename: CHANGELOG.md
5
+
6
+ # Tag formatting ---------------------------------------------------
7
+
8
+ version_prefix: ""
9
+ version_suffix: ""
10
+ date_prefix: ""
11
+
12
+ # Date formatting --------------------------------------------------
13
+
14
+ show_date: true
15
+ date_input_format: "%Y-%m-%d"
16
+ date_output_format: "%Y-%m-%d"
@@ -0,0 +1,4 @@
1
+ All notable changes to this project will be documented in this file.
2
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
3
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luís Bevilacqua
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-01-12 00:00:00.000000000 Z
15
+ date: 2018-01-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: thor
@@ -123,7 +123,11 @@ files:
123
123
  - lib/codelog/command/step/changelog.rb
124
124
  - lib/codelog/command/step/delete.rb
125
125
  - lib/codelog/command/step/version.rb
126
+ - lib/codelog/config.rb
127
+ - lib/codelog/message.rb
126
128
  - lib/codelog/version.rb
129
+ - lib/fixtures/codelog.yml
130
+ - lib/fixtures/header.txt
127
131
  - lib/fixtures/template.yml
128
132
  homepage: https://github.com/codus/codelog
129
133
  licenses:
@@ -138,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
142
  requirements:
139
143
  - - ">="
140
144
  - !ruby/object:Gem::Version
141
- version: '0'
145
+ version: 2.1.10
142
146
  required_rubygems_version: !ruby/object:Gem::Requirement
143
147
  requirements:
144
148
  - - ">="
@@ -146,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
150
  version: '0'
147
151
  requirements: []
148
152
  rubyforge_project:
149
- rubygems_version: 2.6.13
153
+ rubygems_version: 2.6.14
150
154
  signing_key:
151
155
  specification_version: 4
152
156
  summary: A gem to help with changelog management