keepthechange 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/lib/keepthechange.rb +1 -0
- data/lib/keepthechange/parser.rb +103 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d5c4bf13b78872db6e1dd16909a9b2987dc1f4aa
|
4
|
+
data.tar.gz: a4058b6c35f0f5f3a8d6c5b6e6da04d7a4327d09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a36c78283dc6bd121c8ec99eafa89da7cc4739cc1bb5dc7c5a2288afd80650bc2935c53f66bfa5b656b87ac804d30d25e1babc9533a5027daae0c40fa29ba80
|
7
|
+
data.tar.gz: 7fa9da2fa58e31efc1aa842c115b93c18b68a50d12fab375d2ec5bd5ca8cd4b2ac07a7456440054b5397ba4de1c76597ec5b62000de11bbe27bc9b313fa503b9
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
### Added
|
9
|
+
- Initial release.
|
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 thepegasd@gmail.com. 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/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Eugene Piven
|
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,62 @@
|
|
1
|
+
# KeepTheChange
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/pegasd/keepthechange.svg?branch=master)](https://travis-ci.org/pegasd/keepthechange)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/pegasd/keepthechange/badge.svg)](https://coveralls.io/github/pegasd/keepthechange)
|
5
|
+
|
6
|
+
This gem provides an easy-to-use interface for parsing CHANGELOG files that strictly adhere to
|
7
|
+
[keep a changelog format](http://keepachangelog.com/).
|
8
|
+
|
9
|
+
The idea is loosely based on [vandamme](https://github.com/tech-angels/vandamme) gem, but is supposed to evolve
|
10
|
+
into something more strict (in terms of supported formats), but also more feature-rich.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'keepthechange', '~> 0.1'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ gem install keepthechange
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
changes_hash = KeepTheChange::Parser.new(changelog: File.read('CHANGELOG.md')).parse
|
36
|
+
```
|
37
|
+
|
38
|
+
This will produce a hash where keys are version numbers (e.g. `0.1.0`, `1.0.3`) and values are hashes themselves.
|
39
|
+
Those will have headers as keys (e.g. `Added`, `Fixed`) and changesets as corresponding values.
|
40
|
+
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also
|
45
|
+
run `bin/simple_test` after putting a `CHANGELOG.md` into the repo directory for a basic parsing test.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in
|
48
|
+
`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
|
49
|
+
the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports, feature requests and pull requests are welcome at [KeepTheChange official repo](https://github.com/pegasd/keepthechange).
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
58
|
+
|
59
|
+
## Code of Conduct
|
60
|
+
|
61
|
+
Everyone interacting in the Keepthechange project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the
|
62
|
+
[Code of Conduct](https://github.com/pegasd/keepthechange/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'keepthechange/parser'
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
require 'sem_version'
|
3
|
+
|
4
|
+
# Parse Changelogs
|
5
|
+
module KeepTheChange
|
6
|
+
# Changelog Parser class. Use a separate instance for each Changelog.
|
7
|
+
class Parser
|
8
|
+
# Version header RE (these are searched for in the Changelog to find actual versions)
|
9
|
+
VERSION_HEADER_RE = /^## \[(\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2}).*$/
|
10
|
+
# Section header RE (these are searched inside each version changeset to find sections)
|
11
|
+
SECTION_HEADER_RE = /^### (.*)$/
|
12
|
+
|
13
|
+
# @param [String] changelog Markdown contents of Changelog to be parsed.
|
14
|
+
# @param [Regexp] version_header_re Custom header RE.
|
15
|
+
# @param [Regexp] section_header_re Custom section RE.
|
16
|
+
#
|
17
|
+
# @return [KeepTheChange::Parser] Ready to parse!
|
18
|
+
def initialize(changelog: '', version_header_re: VERSION_HEADER_RE, section_header_re: SECTION_HEADER_RE)
|
19
|
+
@changelog = changelog
|
20
|
+
@version_header_re = version_header_re
|
21
|
+
@section_header_re = section_header_re
|
22
|
+
@changelog_hash = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Parse the Changelog and return a hash of changes.
|
26
|
+
# @changelog_hash = {
|
27
|
+
# '1.0.0' => {
|
28
|
+
# 'Added' => "- Change 1\n- Change 2",
|
29
|
+
# 'Fixed' => "- Bugfix"
|
30
|
+
# }
|
31
|
+
# }
|
32
|
+
#
|
33
|
+
# @return [Hash] Hash of version numbers, headers, and changesets.
|
34
|
+
def parse
|
35
|
+
@changelog.scan(@version_header_re) do |match|
|
36
|
+
version_changes = Regexp.last_match.post_match
|
37
|
+
scanner = StringScanner.new(version_changes)
|
38
|
+
scanner.scan_until(@version_header_re)
|
39
|
+
version_changes = parse_version_changes(scanner.pre_match || version_changes)
|
40
|
+
@changelog_hash[match[0]] = version_changes
|
41
|
+
end
|
42
|
+
@changelog_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
# Combine changes for multiple versions. The `since_version` is your `current` version.
|
46
|
+
# This means that changes will start combining from the next version up.
|
47
|
+
#
|
48
|
+
# @param [String] since_version Version to start parsing from. Changes for this version won't be included.
|
49
|
+
# @param [String] to_version Version to stop parsing at.
|
50
|
+
def combine_changes(since_version, to_version = nil)
|
51
|
+
parse if @changelog_hash.empty?
|
52
|
+
|
53
|
+
combined_changes = {}
|
54
|
+
filtered_changes = @changelog_hash
|
55
|
+
if to_version
|
56
|
+
filtered_changes.delete_if do |key, _|
|
57
|
+
SemVersion.new(key) <= SemVersion.new(since_version) ||
|
58
|
+
SemVersion.new(key) > SemVersion.new(to_version)
|
59
|
+
end
|
60
|
+
else
|
61
|
+
filtered_changes.delete_if { |key, _| SemVersion.new(key) <= SemVersion.new(since_version) }
|
62
|
+
end
|
63
|
+
|
64
|
+
filtered_changes.each do |_, changes|
|
65
|
+
changes.each do |section, changes_list|
|
66
|
+
if combined_changes.key? section
|
67
|
+
combined_changes[section] << "\n" << changes_list
|
68
|
+
else
|
69
|
+
combined_changes[section] = changes_list
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
output = "## Changes since [#{since_version}]"
|
75
|
+
output << " (and up to [#{to_version}])" if to_version
|
76
|
+
|
77
|
+
combined_changes.each do |section, changes_list|
|
78
|
+
output << "\n\n### #{section}"
|
79
|
+
output << "\n#{changes_list}"
|
80
|
+
end
|
81
|
+
|
82
|
+
output << "\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Parse a changeset for a specific version and return a hash of different kinds of changes.
|
88
|
+
#
|
89
|
+
# @param [String] changes Changeset for one version.
|
90
|
+
#
|
91
|
+
# @return [Hash] Hash with headers (`Added`, `Fixed`, etc) as keys and related changesets as values.
|
92
|
+
def parse_version_changes(changes)
|
93
|
+
changes_hash = {}
|
94
|
+
changes.scan(@section_header_re) do |match|
|
95
|
+
block_changes = Regexp.last_match.post_match
|
96
|
+
scanner = StringScanner.new(block_changes)
|
97
|
+
scanner.scan_until(@section_header_re)
|
98
|
+
changes_hash[match[0]] = (scanner.pre_match || block_changes).gsub(/(\A\n+|\n+\z)/, '')
|
99
|
+
end
|
100
|
+
changes_hash
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keepthechange
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Piven
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sem_version
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Changelog parser (strictly follows keepachangelog.com format)
|
70
|
+
email:
|
71
|
+
- thepegasd@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.md
|
77
|
+
- CODE_OF_CONDUCT.md
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- lib/keepthechange.rb
|
81
|
+
- lib/keepthechange/parser.rb
|
82
|
+
homepage: https://github.com/pegasd/keepthechange
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.6.12
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Changelog parser
|
106
|
+
test_files: []
|