changelog-madness 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.vscode/settings.json +5 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +63 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/changelog-madness.gemspec +38 -0
- data/exe/changelog +18 -0
- data/lib/changelog/bundler.rb +91 -0
- data/lib/changelog/cli.rb +66 -0
- data/lib/changelog/entry.rb +80 -0
- data/lib/changelog/generator.rb +148 -0
- data/lib/changelog/helper.rb +21 -0
- data/lib/changelog/markdown_generator.rb +79 -0
- data/lib/changelog/semantic_version.rb +77 -0
- data/lib/changelog/updater.rb +71 -0
- data/lib/changelog/version.rb +3 -0
- data/lib/changelog.rb +9 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 499823ae899128b36e1aa820e3a3e7a0bc4598df748bc6901e589ecd47de977e
|
4
|
+
data.tar.gz: d048453e0b4b0509567aa9b81f2c00150b86094390e832b775c399bd9b13203f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59c981d0070aaf230511d23426becd73fc13b9dbd350c2c7cc0ce1c40a75a648eaa978b4c35737b023fd4b7e79d75cf6b2e8c7fb104ea1026a6c6870791a7f5e
|
7
|
+
data.tar.gz: 36cc28b38c16b2aa7cf625d631524b274f83651c3dbbd64baf05c38b27234dc4e09a0088bd08d988f86c309dcde88061df3ce16aab0ba8f7db831e8aa34173be
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alexandre.joly@kilokilo.ch. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Alexandre Joly
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
_Stop the changelog merge conflict madness!_
|
4
|
+
|
5
|
+
This tool helps you maintaining a CHANGELOG by creating one file per entry and
|
6
|
+
bundling them together before you release a new version of your application.
|
7
|
+
|
8
|
+
This tool was inspired by the article '[How we solved GitLab's CHANGELOG conflict crisis](https://about.gitlab.com/2018/07/03/solving-gitlabs-changelog-conflict-crisis/)' from Gitlab. And yeah well I used some of their code too... At this point, I want to say thank you to the Gitlab team for the great work you guys are doing. 👏👏👏
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install _changelog_ using
|
13
|
+
|
14
|
+
```shell
|
15
|
+
gem install changelog-madness
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
### New Entry
|
21
|
+
|
22
|
+
Create a new entry by running
|
23
|
+
|
24
|
+
```shell
|
25
|
+
changelog
|
26
|
+
|
27
|
+
#this is an alias for `changelog gen`
|
28
|
+
```
|
29
|
+
|
30
|
+
this will create a new file in the `changelogs/unreleased/` folder.
|
31
|
+
|
32
|
+
Run `changelog help gen` to see all available options
|
33
|
+
|
34
|
+
### Bundling
|
35
|
+
|
36
|
+
Bundle all the unreleased entries by running
|
37
|
+
|
38
|
+
```shell
|
39
|
+
# changelog bundle <VERSION>
|
40
|
+
changelog bundle 2.3.1
|
41
|
+
```
|
42
|
+
|
43
|
+
this will create or update the `CHANGELOG.md`
|
44
|
+
|
45
|
+
Run `changelog help bundle` to see all available options
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/KiloKilo/changelog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
60
|
+
|
61
|
+
## Code of Conduct
|
62
|
+
|
63
|
+
Everyone interacting in the Changelog project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/KiloKilo/changelog/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "changelog"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "changelog/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "changelog-madness"
|
8
|
+
spec.version = Changelog::VERSION
|
9
|
+
spec.authors = ["Alexandre Joly"]
|
10
|
+
spec.email = ["alexandre.joly@kilokilo.ch"]
|
11
|
+
|
12
|
+
spec.summary = %q{Stop the changelog merge conflict madness}
|
13
|
+
spec.description = %q{A tool to create changelog entries and bind them together}
|
14
|
+
spec.homepage = "https://github.com/KiloKilo/changelog"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
|
28
|
+
# add dependencies
|
29
|
+
spec.add_dependency 'thor', '~> 0'
|
30
|
+
spec.add_dependency 'colorize', '~> 0.8'
|
31
|
+
spec.add_dependency 'activesupport', '~> 4.2'
|
32
|
+
|
33
|
+
# add dependencies specially for development needs
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "irb", "~> 1.0.0"
|
37
|
+
|
38
|
+
end
|
data/exe/changelog
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'changelog/cli'
|
3
|
+
require 'changelog/helper'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Changelog::CLI.start
|
8
|
+
rescue Changelog::Helper::Abort => ex
|
9
|
+
$stderr.puts ex.message
|
10
|
+
exit 1
|
11
|
+
rescue Changelog::Helper::Done
|
12
|
+
exit
|
13
|
+
rescue Interrupt
|
14
|
+
$stderr.puts "\nAbort mission! I repeat! Abort mission!".red
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'changelog/markdown_generator'
|
3
|
+
require 'changelog/updater'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
module Changelog
|
7
|
+
|
8
|
+
class Bundler
|
9
|
+
include Changelog::Helper
|
10
|
+
|
11
|
+
def initialize(version, changelog_file, include_date = false, no_commit = false, dry_run = false, force = false)
|
12
|
+
@version = version
|
13
|
+
@changelog_file = changelog_file || 'CHANGELOG.md'
|
14
|
+
@include_date = include_date
|
15
|
+
@unreleased_entries = nil
|
16
|
+
@no_commit = no_commit
|
17
|
+
@dry_run = dry_run
|
18
|
+
@force = force
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
assert_entries!
|
23
|
+
|
24
|
+
update_changelog
|
25
|
+
|
26
|
+
delete_file_entries
|
27
|
+
|
28
|
+
commit_changes unless @no_commit || @dry_run
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def update_changelog
|
34
|
+
markdown = Changelog::MarkdownGenerator.new(@version, unreleased_entries, include_date: @include_date).to_s
|
35
|
+
|
36
|
+
updater = Updater.new(@changelog_file, @dry_run)
|
37
|
+
updater.insert(@version, markdown)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def commit_changes
|
42
|
+
success = Kernel.system("git add #{@changelog_file} #{unreleased_path}")
|
43
|
+
success &&= Kernel.system("git commit -m \"🧾 Update #{@changelog_file} for v#{@version.to_patch}\n\n[ci skip]\"")
|
44
|
+
|
45
|
+
fail_with "Files could not be commited" unless success
|
46
|
+
end
|
47
|
+
|
48
|
+
def unreleased_entries
|
49
|
+
return @unreleased_entries if @unreleased_entries
|
50
|
+
|
51
|
+
@unreleased_entries = []
|
52
|
+
|
53
|
+
unreleased_paths.each do |fname|
|
54
|
+
@unreleased_entries << Entry.from_yml(fname)
|
55
|
+
end
|
56
|
+
|
57
|
+
@unreleased_entries
|
58
|
+
end
|
59
|
+
|
60
|
+
def unreleased_path
|
61
|
+
File.join('changelogs', 'unreleased')
|
62
|
+
end
|
63
|
+
|
64
|
+
def unreleased_paths
|
65
|
+
Dir.glob(File.join(unreleased_path, '*.yml'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_file_entries
|
69
|
+
unreleased_paths.each do |path|
|
70
|
+
if @dry_run
|
71
|
+
$stdout.puts "#{'delete'.red} #{path}"
|
72
|
+
next
|
73
|
+
end
|
74
|
+
|
75
|
+
File.delete(path) if File.exist?(path)
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def assert_entries!
|
81
|
+
return if unreleased_entries.length > 0
|
82
|
+
return if @force
|
83
|
+
|
84
|
+
fail_with "No entries in '#{unreleased_path}' available! Use `--force` to write an empty version."
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# vim: ft=ruby
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'changelog'
|
3
|
+
require 'changelog/entry'
|
4
|
+
require 'changelog/generator'
|
5
|
+
require 'changelog/bundler'
|
6
|
+
require 'colorize'
|
7
|
+
|
8
|
+
module Changelog
|
9
|
+
class CLI < Thor
|
10
|
+
default_task :gen_entry
|
11
|
+
|
12
|
+
method_option :ammend, :type => :boolean, :default => false, :desc => 'Amend the previous commit'
|
13
|
+
method_option :force, :type => :string, :aliases => "-f", :desc => 'Overwrite an existing entry'
|
14
|
+
method_option "merge-request", :type => :numeric, :aliases => "-m", :desc => 'Merge Request ID'
|
15
|
+
method_option "issue", :type => :numeric, :aliases => "-i", :desc => 'Issue ID'
|
16
|
+
method_option "dry-run", :type => :boolean, :aliases => "-n", :desc => "Don't actually write anything, just print"
|
17
|
+
method_option :author, :type => :string, :aliases => "-u", :desc => 'Overwrite the author of the change'
|
18
|
+
method_option :type, :type => :string, :aliases => "-t", :desc => "The category of the change", :enum => Changelog::Entry::TYPES.map(&:name)
|
19
|
+
desc 'gen [TITLE]', 'Generate a new changelog entry'
|
20
|
+
def gen_entry(title="")
|
21
|
+
type = options.type || read_type
|
22
|
+
|
23
|
+
generator = Changelog::Generator.new(title, type, options.author, options.issue, options["merge-request"], options.amend, options.force)
|
24
|
+
generator.execute(options["dry-run"])
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
method_option "changelog-file", :type => :string, :aliases => "-c", :desc => 'The name of the changelog file'
|
29
|
+
method_option "include-date", :type => :boolean, :aliases => "-d", :desc => 'Include the date in the release'
|
30
|
+
method_option "dry-run", :type => :boolean, :aliases => "-n", :desc => "Don't actually write anything, just print"
|
31
|
+
method_option "no-commit", :type => :boolean, :default => false, :desc => 'Do not commit the changelog'
|
32
|
+
method_option :force, :type => :string, :aliases => "-f", :desc => 'Write an empty version if there is no entries'
|
33
|
+
desc 'bundle VERSION', 'Bundle the changelogs entry to a new version'
|
34
|
+
def bundle_entries(version)
|
35
|
+
semver = Changelog::SemanticVersion::new(version)
|
36
|
+
|
37
|
+
bundler = Changelog::Bundler.new(semver, options['changelog-file'], options['include-date'], options['no-commit'], options["dry-run"], options["force"])
|
38
|
+
bundler.execute
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def read_type
|
44
|
+
read_type_message
|
45
|
+
|
46
|
+
type = Changelog::Entry::TYPES[$stdin.getc.to_i - 1]
|
47
|
+
assert_valid_type!(type)
|
48
|
+
|
49
|
+
type.name
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_type_message
|
53
|
+
$stdout.puts "\n>> Please specify the index for the category of your change:"
|
54
|
+
Changelog::Entry::TYPES.each_with_index do |type, index|
|
55
|
+
$stdout.puts "#{index + 1}. #{type.description}"
|
56
|
+
end
|
57
|
+
$stdout.print "\n?> "
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_valid_type!(type)
|
61
|
+
unless type
|
62
|
+
raise Abort, "Invalid category index, please select an index between 1 and #{Changelog::Entry::TYPES.length}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'changelog'
|
3
|
+
|
4
|
+
module Changelog
|
5
|
+
class Entry
|
6
|
+
attr_reader :title, :type, :issue, :merge_request, :author
|
7
|
+
|
8
|
+
Type = Struct.new(:name, :description)
|
9
|
+
TYPES = [
|
10
|
+
Type.new('added', 'New feature'),
|
11
|
+
Type.new('fixed', 'Bug fix'),
|
12
|
+
Type.new('changed', 'Feature change'),
|
13
|
+
Type.new('deprecated', 'New deprecation'),
|
14
|
+
Type.new('removed', 'Feature removal'),
|
15
|
+
Type.new('security', 'Security fix'),
|
16
|
+
Type.new('performance', 'Performance improvement'),
|
17
|
+
Type.new('other', 'Other')
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
class << self
|
21
|
+
|
22
|
+
def from_yml(path)
|
23
|
+
parse_blob(File.read(path))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def parse_blob(content)
|
29
|
+
yaml = YAML.safe_load(content)
|
30
|
+
|
31
|
+
Entry.new(yaml['title'], yaml['type'], yaml['author'], yaml['issue'], yaml['merge_request'])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def initialize(title, type, author, issue, merge_request)
|
37
|
+
@title = title
|
38
|
+
@type = parse_type(type)
|
39
|
+
@author = author
|
40
|
+
@issue = issue
|
41
|
+
@merge_request = merge_request
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
str = +""
|
46
|
+
str << "#{title}".gsub(/\.{2,}$/, '.')
|
47
|
+
str << " ##{issue}" if !issue.nil?
|
48
|
+
str << " !#{merge_request}" if !merge_request.nil?
|
49
|
+
str << " (#{author})" if !author.nil?
|
50
|
+
|
51
|
+
str
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid?
|
55
|
+
!@title.nil?
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_yml
|
59
|
+
yaml_content = YAML.dump(
|
60
|
+
'title' => @title,
|
61
|
+
'type' => @type,
|
62
|
+
'issue' => @issue,
|
63
|
+
'merge_request' => @merge_request,
|
64
|
+
'author' => @author,
|
65
|
+
)
|
66
|
+
remove_trailing_whitespace(yaml_content)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def parse_type(type)
|
72
|
+
TYPES.map(&:name).include?(type) ? type : 'other'
|
73
|
+
end
|
74
|
+
|
75
|
+
def remove_trailing_whitespace(yaml_content)
|
76
|
+
yaml_content.gsub(/ +$/, '')
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'colorize'
|
5
|
+
require 'changelog/helper'
|
6
|
+
|
7
|
+
|
8
|
+
INVALID_TYPE = -1
|
9
|
+
|
10
|
+
module Changelog
|
11
|
+
|
12
|
+
class Generator
|
13
|
+
include Changelog::Helper
|
14
|
+
|
15
|
+
def initialize(title, type, author, issue, merge_request, amend, force = false)
|
16
|
+
@entry = Changelog::Entry.new(
|
17
|
+
parse_title(title),
|
18
|
+
type,
|
19
|
+
parse_author(author),
|
20
|
+
parse_issue(issue),
|
21
|
+
merge_request
|
22
|
+
)
|
23
|
+
|
24
|
+
@amend = amend
|
25
|
+
@force = force
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute(dry_run=false)
|
29
|
+
assert_feature_branch!
|
30
|
+
assert_title! unless editor
|
31
|
+
assert_new_file!
|
32
|
+
|
33
|
+
$stdout.puts "#{'create'.green} #{file_path}"
|
34
|
+
$stdout.puts contents
|
35
|
+
|
36
|
+
unless dry_run
|
37
|
+
write
|
38
|
+
amend_commit if @amend
|
39
|
+
end
|
40
|
+
|
41
|
+
if editor
|
42
|
+
system("#{editor} '#{file_path}'")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def contents
|
49
|
+
@entry.to_yml
|
50
|
+
end
|
51
|
+
|
52
|
+
def write
|
53
|
+
dirname = File.dirname(file_path)
|
54
|
+
unless File.directory?(dirname)
|
55
|
+
FileUtils.mkdir_p(dirname)
|
56
|
+
end
|
57
|
+
|
58
|
+
File.write(file_path, contents)
|
59
|
+
end
|
60
|
+
|
61
|
+
def editor
|
62
|
+
ENV['EDITOR']
|
63
|
+
end
|
64
|
+
|
65
|
+
def amend_commit
|
66
|
+
fail_with "git add failed" unless system(*%W[git add #{file_path}])
|
67
|
+
|
68
|
+
Kernel.exec(*%w[git commit --amend])
|
69
|
+
end
|
70
|
+
|
71
|
+
def assert_feature_branch!
|
72
|
+
return unless branch_name == 'master' and not @force
|
73
|
+
|
74
|
+
fail_with "Create a branch first!"
|
75
|
+
end
|
76
|
+
|
77
|
+
def assert_new_file!
|
78
|
+
return unless File.exist?(file_path)
|
79
|
+
return if @force
|
80
|
+
|
81
|
+
fail_with "#{file_path} already exists! Use `--force` to overwrite."
|
82
|
+
end
|
83
|
+
|
84
|
+
def assert_title!
|
85
|
+
return if @entry.title.length > 0 || @amend
|
86
|
+
|
87
|
+
fail_with "Provide a title for the changelog entry or use `--amend`" \
|
88
|
+
" to use the title from the previous commit."
|
89
|
+
end
|
90
|
+
|
91
|
+
def assert_valid_type!
|
92
|
+
return unless @entry.type && @entry.type == INVALID_TYPE
|
93
|
+
|
94
|
+
fail_with 'Invalid category given!'
|
95
|
+
end
|
96
|
+
|
97
|
+
def parse_title(title)
|
98
|
+
return title unless title.empty?
|
99
|
+
|
100
|
+
last_commit_subject
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_author(author)
|
104
|
+
return author unless author.nil?
|
105
|
+
|
106
|
+
git_user_name
|
107
|
+
end
|
108
|
+
|
109
|
+
def parse_issue(issue)
|
110
|
+
return issue unless issue.nil?
|
111
|
+
|
112
|
+
issue_nr_from_branch
|
113
|
+
end
|
114
|
+
|
115
|
+
def git_user_name
|
116
|
+
capture_stdout(%w[git config user.name]).strip
|
117
|
+
end
|
118
|
+
|
119
|
+
def last_commit_subject
|
120
|
+
capture_stdout(%w[git log --format=%s -1]).strip
|
121
|
+
end
|
122
|
+
|
123
|
+
def issue_nr_from_branch
|
124
|
+
found = branch_name.scan(/\/?(\d+)-/).first
|
125
|
+
found.first unless found.nil?
|
126
|
+
end
|
127
|
+
|
128
|
+
def file_path
|
129
|
+
base_path = File.join(
|
130
|
+
unreleased_path,
|
131
|
+
branch_name.gsub(/[^\w-]/, '-'))
|
132
|
+
|
133
|
+
# Add padding for .yml extension
|
134
|
+
base_path[0..MAX_FILENAME_LENGTH - 5] + '.yml'
|
135
|
+
end
|
136
|
+
|
137
|
+
def unreleased_path
|
138
|
+
File.join('changelogs', 'unreleased')
|
139
|
+
end
|
140
|
+
|
141
|
+
def branch_name
|
142
|
+
@branch_name ||= capture_stdout(%w[git symbolic-ref --short HEAD]).strip
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# vim: ft=ruby
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'changelog'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
module Changelog
|
5
|
+
module Helper
|
6
|
+
Abort = Class.new(StandardError)
|
7
|
+
Done = Class.new(StandardError)
|
8
|
+
|
9
|
+
MAX_FILENAME_LENGTH = 140 # ecryptfs has a limit of 140 characters
|
10
|
+
|
11
|
+
def capture_stdout(cmd)
|
12
|
+
output = IO.popen(cmd, &:read)
|
13
|
+
fail_with "command failed: #{cmd.join(' ')}" unless $?.success?
|
14
|
+
output
|
15
|
+
end
|
16
|
+
|
17
|
+
def fail_with(message)
|
18
|
+
raise Abort, "#{'error'.red} #{message}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'changelog/semantic_version'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
|
4
|
+
module Changelog
|
5
|
+
|
6
|
+
class MarkdownGenerator
|
7
|
+
attr_reader :version, :entries
|
8
|
+
|
9
|
+
def initialize(version, entries, include_date: false)
|
10
|
+
@version = version
|
11
|
+
@entries = entries.select(&:valid?)
|
12
|
+
@include_date = include_date
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
markdown = StringIO.new
|
17
|
+
markdown.puts header
|
18
|
+
markdown.puts
|
19
|
+
|
20
|
+
if entries.empty?
|
21
|
+
markdown.puts "- No changes.\n\n"
|
22
|
+
else
|
23
|
+
markdown.puts formatted_entries
|
24
|
+
end
|
25
|
+
|
26
|
+
markdown.puts
|
27
|
+
|
28
|
+
markdown.string
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def header
|
34
|
+
head = "## #{version.to_patch}"
|
35
|
+
head += " (#{date})" if @include_date
|
36
|
+
head
|
37
|
+
end
|
38
|
+
|
39
|
+
def date
|
40
|
+
Date.today.strftime("%Y-%m-%d")
|
41
|
+
end
|
42
|
+
|
43
|
+
def entries_grouped_by_type(type)
|
44
|
+
entries.select { |entry| entry.type == type }
|
45
|
+
end
|
46
|
+
|
47
|
+
# Group entries by type found in the `Changelog::Entry::TYPES`.
|
48
|
+
# Output example:
|
49
|
+
#
|
50
|
+
# ### Fixed (52 changes)
|
51
|
+
# - Fix 404 errors in API caused when the branch name had a dot. #42 !14462 (ajoly)
|
52
|
+
def formatted_entries
|
53
|
+
result = +''
|
54
|
+
|
55
|
+
Changelog::Entry::TYPES.map(&:name).each do |type|
|
56
|
+
grouped_entries = entries_grouped_by_type(type)
|
57
|
+
changes_count = grouped_entries.size
|
58
|
+
|
59
|
+
# Do nothing if no changes are presented for the current type.
|
60
|
+
next unless changes_count.positive?
|
61
|
+
|
62
|
+
# Prepare the group header.
|
63
|
+
# Example:
|
64
|
+
# ### Added (54 changes)
|
65
|
+
changes = [changes_count, 'change'.pluralize(changes_count)].join("\s")
|
66
|
+
|
67
|
+
result << "### #{type.capitalize} (#{changes})\n\n"
|
68
|
+
|
69
|
+
# Add entries to the group.
|
70
|
+
grouped_entries.each { |entry| result << "- #{entry}\n" }
|
71
|
+
|
72
|
+
result << "\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
result
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Changelog
|
2
|
+
class SemanticVersion < String
|
3
|
+
|
4
|
+
VERSION_REGEX = %r{
|
5
|
+
\A(?<major>\d+)
|
6
|
+
\.(?<minor>\d+)
|
7
|
+
(\.(?<patch>\d+))?
|
8
|
+
\z
|
9
|
+
}x.freeze
|
10
|
+
|
11
|
+
def initialize(version_string)
|
12
|
+
super(version_string)
|
13
|
+
|
14
|
+
if valid? && extract_from_version(:patch, fallback: nil).nil?
|
15
|
+
super(to_patch)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
if other.respond_to?(:to_patch)
|
21
|
+
to_patch.eql?(other.to_patch)
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def <=>(other)
|
28
|
+
return nil unless other.is_a?(SemanticVersion)
|
29
|
+
return 0 if self == other
|
30
|
+
|
31
|
+
if major > other.major ||
|
32
|
+
(major >= other.major && minor > other.minor) ||
|
33
|
+
(major >= other.major && minor >= other.minor && patch > other.patch)
|
34
|
+
1
|
35
|
+
else
|
36
|
+
-1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def major
|
41
|
+
@major ||= extract_from_version(:major).to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def minor
|
45
|
+
@minor ||= extract_from_version(:minor).to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def patch
|
49
|
+
@patch ||= extract_from_version(:patch).to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_minor
|
53
|
+
"#{major}.#{minor}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_patch
|
57
|
+
"#{major}.#{minor}.#{patch}"
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def valid?
|
62
|
+
self.class::VERSION_REGEX.match?(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def extract_from_version(part, fallback: 0)
|
68
|
+
match_data = self.class::VERSION_REGEX.match(self)
|
69
|
+
if match_data && match_data.names.include?(part.to_s) && match_data[part]
|
70
|
+
String.new(match_data[part])
|
71
|
+
else
|
72
|
+
fallback
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'changelog/semantic_version'
|
2
|
+
|
3
|
+
module Changelog
|
4
|
+
class Updater
|
5
|
+
|
6
|
+
def initialize(path, dry_run = false)
|
7
|
+
@path = path
|
8
|
+
@dry_run = dry_run
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert(version, markdown)
|
12
|
+
|
13
|
+
create_file unless File.file?(@path)
|
14
|
+
|
15
|
+
versions_found = false
|
16
|
+
|
17
|
+
contents = File.read(@path).lines if File.exist?(@path)
|
18
|
+
contents ||= []
|
19
|
+
contents.each_with_index do |line, index|
|
20
|
+
|
21
|
+
if line =~ /\A## v?(\d+\.\d+\.\d+)/
|
22
|
+
header = Changelog::SemanticVersion.new($1)
|
23
|
+
|
24
|
+
if version == header
|
25
|
+
entries = markdown.lines
|
26
|
+
entries.shift(2) # Remove the header and the blank line
|
27
|
+
entries.pop # Remove the trailing blank line
|
28
|
+
|
29
|
+
# Insert the entries below the existing header and its blank line
|
30
|
+
contents.insert(index + 2, entries)
|
31
|
+
versions_found = true
|
32
|
+
|
33
|
+
break
|
34
|
+
elsif version >= header
|
35
|
+
contents.insert(index, *markdown.lines)
|
36
|
+
versions_found = true
|
37
|
+
|
38
|
+
break
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
contents.push(*markdown.lines) unless versions_found
|
46
|
+
|
47
|
+
contents
|
48
|
+
.flatten
|
49
|
+
.map { |line| line.force_encoding(Encoding::UTF_8) }
|
50
|
+
.join
|
51
|
+
|
52
|
+
File.open(@path, "w") { |f| f.puts contents } unless @dry_run
|
53
|
+
$stdout.puts "#{'CHANGELOG:'.green}\n\n #{contents.join('')}\n" if @dry_run
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def create_file
|
60
|
+
File.open(@path, "w") { |f| f.write header } unless @dry_run
|
61
|
+
$stdout.puts "#{'create'.green} #{@path}" if @dry_run
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def header
|
66
|
+
str = +""
|
67
|
+
str << "**Note:** This file is automatically generated.\n\n"
|
68
|
+
str << "# Changelog\n\n"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/changelog.rb
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: changelog-madness
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandre Joly
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: irb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.0
|
97
|
+
description: A tool to create changelog entries and bind them together
|
98
|
+
email:
|
99
|
+
- alexandre.joly@kilokilo.ch
|
100
|
+
executables:
|
101
|
+
- changelog
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".vscode/settings.json"
|
107
|
+
- CHANGELOG.md
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- changelog-madness.gemspec
|
116
|
+
- exe/changelog
|
117
|
+
- lib/changelog.rb
|
118
|
+
- lib/changelog/bundler.rb
|
119
|
+
- lib/changelog/cli.rb
|
120
|
+
- lib/changelog/entry.rb
|
121
|
+
- lib/changelog/generator.rb
|
122
|
+
- lib/changelog/helper.rb
|
123
|
+
- lib/changelog/markdown_generator.rb
|
124
|
+
- lib/changelog/semantic_version.rb
|
125
|
+
- lib/changelog/updater.rb
|
126
|
+
- lib/changelog/version.rb
|
127
|
+
homepage: https://github.com/KiloKilo/changelog
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.7.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Stop the changelog merge conflict madness
|
151
|
+
test_files: []
|