keepachangelog 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43670bf15155e781900c3e2ef0cc4867037d4814
4
+ data.tar.gz: f4060bb3c0ab0ba82a24f73e53c283c47bc9e627
5
+ SHA512:
6
+ metadata.gz: dba49f142c11099ef4eb18e8ee0b68abbc9b6f73b8436df90959e2fc286d0fb5e8bacb00c291651c434015e88b6753bace3e768726393ef3ea10dae18f81c410
7
+ data.tar.gz: 14e98f3e890e8b5d8729660561951241c29e73eaf80f60cde9895ec55171368c563f333c74090445116f6055411044f9a4a688e42e67559f62a4d767ab3f9e77
@@ -0,0 +1,234 @@
1
+
2
+ # Created by https://www.gitignore.io/api/emacs,vim,ruby,node,osx,windows,linux,visualstudiocode
3
+
4
+ ### Emacs ###
5
+ # -*- mode: gitignore; -*-
6
+ *~
7
+ \#*\#
8
+ /.emacs.desktop
9
+ /.emacs.desktop.lock
10
+ *.elc
11
+ auto-save-list
12
+ tramp
13
+ .\#*
14
+
15
+ # Org-mode
16
+ .org-id-locations
17
+ *_archive
18
+
19
+ # flymake-mode
20
+ *_flymake.*
21
+
22
+ # eshell files
23
+ /eshell/history
24
+ /eshell/lastdir
25
+
26
+ # elpa packages
27
+ /elpa/
28
+
29
+ # reftex files
30
+ *.rel
31
+
32
+ # AUCTeX auto folder
33
+ /auto/
34
+
35
+ # cask packages
36
+ .cask/
37
+ dist/
38
+
39
+ # Flycheck
40
+ flycheck_*.el
41
+
42
+ # server auth directory
43
+ /server/
44
+
45
+ # projectiles files
46
+ .projectile
47
+
48
+ # directory configuration
49
+ .dir-locals.el
50
+
51
+
52
+ ### Vim ###
53
+ # swap
54
+ [._]*.s[a-w][a-z]
55
+ [._]s[a-w][a-z]
56
+ # session
57
+ Session.vim
58
+ # temporary
59
+ .netrwhist
60
+ # auto-generated tag files
61
+ tags
62
+
63
+
64
+ ### Ruby ###
65
+ *.gem
66
+ *.rbc
67
+ /.config
68
+ /coverage/
69
+ /InstalledFiles
70
+ /pkg/
71
+ /spec/reports/
72
+ /spec/examples.txt
73
+ /test/tmp/
74
+ /test/version_tmp/
75
+ /tmp/
76
+
77
+ # Used by dotenv library to load environment variables.
78
+ # .env
79
+
80
+ ## Specific to RubyMotion:
81
+ .dat*
82
+ .repl_history
83
+ build/
84
+ *.bridgesupport
85
+ build-iPhoneOS/
86
+ build-iPhoneSimulator/
87
+
88
+ ## Specific to RubyMotion (use of CocoaPods):
89
+ #
90
+ # We recommend against adding the Pods directory to your .gitignore. However
91
+ # you should judge for yourself, the pros and cons are mentioned at:
92
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
93
+ #
94
+ # vendor/Pods/
95
+
96
+ ## Documentation cache and generated files:
97
+ /.yardoc/
98
+ /_yardoc/
99
+ /doc/
100
+ /rdoc/
101
+
102
+ ## Environment normalization:
103
+ /.bundle/
104
+ /vendor/bundle
105
+ /lib/bundler/man/
106
+
107
+ # for a library or gem, you might want to ignore these files since the code is
108
+ # intended to run in multiple environments; otherwise, check them in:
109
+ # Gemfile.lock
110
+ # .ruby-version
111
+ # .ruby-gemset
112
+
113
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
114
+ .rvmrc
115
+
116
+
117
+ ### Node ###
118
+ # Logs
119
+ logs
120
+ *.log
121
+ npm-debug.log*
122
+
123
+ # Runtime data
124
+ pids
125
+ *.pid
126
+ *.seed
127
+ *.pid.lock
128
+
129
+ # Directory for instrumented libs generated by jscoverage/JSCover
130
+ lib-cov
131
+
132
+ # Coverage directory used by tools like istanbul
133
+ coverage
134
+
135
+ # nyc test coverage
136
+ .nyc_output
137
+
138
+ # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
139
+ .grunt
140
+
141
+ # node-waf configuration
142
+ .lock-wscript
143
+
144
+ # Compiled binary addons (http://nodejs.org/api/addons.html)
145
+ build/Release
146
+
147
+ # Dependency directories
148
+ node_modules
149
+ jspm_packages
150
+
151
+ # Optional npm cache directory
152
+ .npm
153
+
154
+ # Optional eslint cache
155
+ .eslintcache
156
+
157
+ # Optional REPL history
158
+ .node_repl_history
159
+
160
+ # Output of 'npm pack'
161
+ *.tgz
162
+
163
+ # Yarn Integrity file
164
+ .yarn-integrity
165
+
166
+
167
+
168
+ ### OSX ###
169
+ *.DS_Store
170
+ .AppleDouble
171
+ .LSOverride
172
+
173
+ # Icon must end with two \r
174
+ Icon
175
+ # Thumbnails
176
+ ._*
177
+ # Files that might appear in the root of a volume
178
+ .DocumentRevisions-V100
179
+ .fseventsd
180
+ .Spotlight-V100
181
+ .TemporaryItems
182
+ .Trashes
183
+ .VolumeIcon.icns
184
+ .com.apple.timemachine.donotpresent
185
+ # Directories potentially created on remote AFP share
186
+ .AppleDB
187
+ .AppleDesktop
188
+ Network Trash Folder
189
+ Temporary Items
190
+ .apdisk
191
+
192
+
193
+ ### Windows ###
194
+ # Windows image file caches
195
+ Thumbs.db
196
+ ehthumbs.db
197
+
198
+ # Folder config file
199
+ Desktop.ini
200
+
201
+ # Recycle Bin used on file shares
202
+ $RECYCLE.BIN/
203
+
204
+ # Windows Installer files
205
+ *.cab
206
+ *.msi
207
+ *.msm
208
+ *.msp
209
+
210
+ # Windows shortcuts
211
+ *.lnk
212
+
213
+
214
+ ### Linux ###
215
+
216
+ # temporary files which can be created if a process still has a handle open of a deleted file
217
+ .fuse_hidden*
218
+
219
+ # KDE directory preferences
220
+ .directory
221
+
222
+ # Linux trash folder which might appear on any partition or disk
223
+ .Trash-*
224
+
225
+ # .nfs files are created when an open file is removed but is still being accessed
226
+ .nfs*
227
+
228
+
229
+ ### VisualStudioCode ###
230
+ .vscode/*
231
+ !.vscode/settings.json
232
+ !.vscode/tasks.json
233
+ !.vscode/launch.json
234
+ !.vscode/extensions.json
@@ -0,0 +1,61 @@
1
+ variables:
2
+ GIT_SSL_NO_VERIFY: "true"
3
+
4
+ image: mwallasch/docker-ruby-node
5
+
6
+ before_script:
7
+ - ruby -v
8
+ - node -v
9
+ - npm -v
10
+ - gem install bundler
11
+ - bin/setup
12
+
13
+ cache:
14
+ paths:
15
+ - vendor/bundle
16
+ - node_modules
17
+
18
+ stages:
19
+ - build
20
+ - test
21
+ - deploy
22
+
23
+ build:
24
+ stage: build
25
+ script:
26
+ - grunt build
27
+ artifacts:
28
+ paths:
29
+ - keepachangelog-*.gem
30
+
31
+ style:
32
+ script:
33
+ - "grunt test:style"
34
+
35
+ spec:
36
+ script:
37
+ - "grunt test:spec"
38
+
39
+ integration:
40
+ script:
41
+ - "grunt test:integration"
42
+
43
+ download.basalt.se:
44
+ stage: deploy
45
+ environment: production
46
+ script:
47
+ - grunt publish
48
+ only:
49
+ - tags
50
+
51
+ rubygems.org:
52
+ stage: deploy
53
+ environment: production
54
+ script:
55
+ - mkdir -p ~/.gem
56
+ - "echo \":rubygems_api_key: $RUBYGEMS_API_KEY\" > ~/.gem/credentials"
57
+ - chmod 0600 /root/.gem/credentials
58
+ - gem build keepachangelog.gemspec
59
+ - gem push keepachangelog-*.gem
60
+ only:
61
+ - tags
@@ -0,0 +1,13 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/ClassAndModuleChildren:
5
+ Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*'
10
+
11
+ Metrics/ModuleLength:
12
+ Exclude:
13
+ - 'spec/**/*'
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+ Alla ändringar till detta projekt dokumenteras i denna fil.
3
+
4
+ Formatet är baserat på [Keep a Changelog](http://keepachangelog.com/)
5
+ och detta projekt följer [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [0.1.0] - 2017-03-27
8
+ ### Nytt
9
+ - Ruby gem som exponerar verktyget via Ruby och CLI.
10
+ - Förmåga att konvertera Changelog till JSON.
11
+ - Förmåga att konvertera Changelog till YAML.
12
+
13
+ [Unreleased]: https://git.basalt.se/chbr/keepachangelog/compare/0.1.0...HEAD
14
+ [0.1.0]: https://git.basalt.se/chbr/keepachangelog/compare/77986bc...0.1.0
@@ -0,0 +1,2 @@
1
+ Se [metodanvisning utveckling](http://doc.basalt.se/docs/beans-metodanvisning-testdriven-utveckling/sv/stable/)
2
+ för detaljer på hur man utvecklar i detta projekt.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in keepachangelog.gemspec
4
+ gemspec
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ keepachangelog (0.1.0)
5
+ json (~> 2.0)
6
+ thor (~> 0.19)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aruba (0.14.2)
12
+ childprocess (~> 0.5.6)
13
+ contracts (~> 0.9)
14
+ cucumber (>= 1.3.19)
15
+ ffi (~> 1.9.10)
16
+ rspec-expectations (>= 2.99)
17
+ thor (~> 0.19)
18
+ ast (2.3.0)
19
+ builder (3.2.3)
20
+ childprocess (0.5.9)
21
+ ffi (~> 1.0, >= 1.0.11)
22
+ contracts (0.15.0)
23
+ cucumber (2.4.0)
24
+ builder (>= 2.1.2)
25
+ cucumber-core (~> 1.5.0)
26
+ cucumber-wire (~> 0.0.1)
27
+ diff-lcs (>= 1.1.3)
28
+ gherkin (~> 4.0)
29
+ multi_json (>= 1.7.5, < 2.0)
30
+ multi_test (>= 0.1.2)
31
+ cucumber-core (1.5.0)
32
+ gherkin (~> 4.0)
33
+ cucumber-wire (0.0.1)
34
+ diff-lcs (1.3)
35
+ docile (1.1.5)
36
+ ffi (1.9.18)
37
+ gherkin (4.1.1)
38
+ json (2.0.3)
39
+ multi_json (1.12.1)
40
+ multi_test (0.1.2)
41
+ parser (2.4.0.0)
42
+ ast (~> 2.2)
43
+ powerpack (0.1.1)
44
+ rainbow (2.2.1)
45
+ rake (12.0.0)
46
+ rspec (3.5.0)
47
+ rspec-core (~> 3.5.0)
48
+ rspec-expectations (~> 3.5.0)
49
+ rspec-mocks (~> 3.5.0)
50
+ rspec-core (3.5.4)
51
+ rspec-support (~> 3.5.0)
52
+ rspec-expectations (3.5.0)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.5.0)
55
+ rspec-mocks (3.5.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.5.0)
58
+ rspec-support (3.5.0)
59
+ rubocop (0.47.1)
60
+ parser (>= 2.3.3.1, < 3.0)
61
+ powerpack (~> 0.1)
62
+ rainbow (>= 1.99.1, < 3.0)
63
+ ruby-progressbar (~> 1.7)
64
+ unicode-display_width (~> 1.0, >= 1.0.1)
65
+ ruby-progressbar (1.8.1)
66
+ simplecov (0.14.0)
67
+ docile (~> 1.1.0)
68
+ json (>= 1.8, < 3)
69
+ simplecov-html (~> 0.10.0)
70
+ simplecov-html (0.10.0)
71
+ thor (0.19.4)
72
+ unicode-display_width (1.1.3)
73
+
74
+ PLATFORMS
75
+ ruby
76
+
77
+ DEPENDENCIES
78
+ aruba (~> 0.14)
79
+ bundler (~> 1.14)
80
+ keepachangelog!
81
+ rake (~> 12.0)
82
+ rspec (~> 3.5)
83
+ rubocop (~> 0.47)
84
+ simplecov (~> 0.14)
85
+
86
+ BUNDLED WITH
87
+ 1.14.3
@@ -0,0 +1,3 @@
1
+ Copyright &copy; 2016 Basalt
2
+
3
+ All rights reserved - Do Not Redistribute
@@ -0,0 +1,40 @@
1
+ # Keepachangelog
2
+
3
+ Ruby gem for parsing Changelogs based on the format described at
4
+ keepachangelog.com. The output can be either JSON or YAML.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'keepachangelog'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ gem install keepachangelog
21
+
22
+ ## Usage
23
+
24
+ To dump a Changelog to JSON run the following command:
25
+
26
+ keepachangelog --path=CHANGELOG.md --format=json
27
+
28
+ If you want to use the API from your own Ruby code:
29
+
30
+ ```ruby
31
+ require 'keepachangelog'
32
+ parser = Keepachangelog::Parser.load('CHANGELOG.md')
33
+ puts parser.to_json
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies.
39
+ Then, run `grunt test` to run the tests. You can also run `bin/console` for an
40
+ interactive prompt that will allow you to experiment.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'keepachangelog'
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__)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install --path vendor/bundle
7
+ npm install
8
+ npm -g install grunt-cli
9
+
10
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'keepachangelog/cli'
3
+ Keepachangelog::CLI.start(ARGV)
@@ -0,0 +1,13 @@
1
+ Feature: Show help
2
+
3
+ You can get general help by running `keepachangelog help`. To get more
4
+ information about a specific command run `keepachangelog help [COMMAND]`.
5
+
6
+ Scenario: Getting general help
7
+ When I successfully run `keepachangelog help`
8
+ Then the output should contain "Keepachangelog commands"
9
+
10
+ Scenario: Getting help about a command
11
+ When I successfully run `keepachangelog help parse`
12
+ Then the output should contain "Options"
13
+ And the output should contain "Usage"
@@ -0,0 +1,43 @@
1
+ Feature: List transformators
2
+
3
+ Parse a changelog by running `keepachangelog parse` or just simply
4
+ `keepachangelog`.
5
+
6
+ Scenario: Running with command
7
+ Given a file "CHANGELOG.md" with:
8
+ """
9
+ ## [Unreleased]
10
+ ### New
11
+ - Feature A
12
+ """
13
+ When I successfully run `keepachangelog parse`
14
+ Then the output should contain:
15
+ """
16
+ [{"version":"Unreleased","url":null,"date":null,"changes":{"New":["Feature A"]}}]
17
+ """
18
+
19
+ Scenario: Running without command
20
+ Given a file "CHANGELOG.md" with:
21
+ """
22
+ ## [Unreleased]
23
+ ### New
24
+ - Feature A
25
+ """
26
+ When I successfully run `keepachangelog`
27
+ Then the output should contain:
28
+ """
29
+ [{"version":"Unreleased","url":null,"date":null,"changes":{"New":["Feature A"]}}]
30
+ """
31
+
32
+ Scenario: Changelog has a non-default filename
33
+ Given a file "HISTORY.md" with:
34
+ """
35
+ ## [Unreleased]
36
+ ### New
37
+ - Feature A
38
+ """
39
+ When I successfully run `keepachangelog --path=HISTORY.md`
40
+ Then the output should contain:
41
+ """
42
+ [{"version":"Unreleased","url":null,"date":null,"changes":{"New":["Feature A"]}}]
43
+ """
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,7 @@
1
+ Feature: Show version
2
+
3
+ To show the version of the gem run `keepachangelog version`.
4
+
5
+ Scenario: Running `keepachangelog version`
6
+ When I successfully run `keepachangelog version`
7
+ Then the output should match /\d+\.\d+\.\d+/
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'keepachangelog/version'
5
+ git_files = `git ls-files -z`.split("\x0")
6
+ gem_files = git_files.reject { |f| f.match(%r{^(spec|features|fixtures)/}) }
7
+ gem_files = git_files.reject { |f| f.match('.gitlab-ci.yml') }
8
+ gem_files = git_files.reject { |f| f.match('.gitignore') }
9
+ gem_files = git_files.reject { |f| f.match('CONTRIBUTING.md') }
10
+ gem_files = git_files.reject { |f| f.match('Gruntfile.js') }
11
+
12
+ Gem::Specification.new do |spec|
13
+ spec.name = 'keepachangelog'
14
+ spec.version = Keepachangelog.version
15
+ spec.authors = ['Basalt AB']
16
+ spec.email = %w(christoffer.brodd-reijer@basalt.se)
17
+ spec.licenses = ['Nonstandard']
18
+ spec.summary = 'Parser for changelogs based on keepachangelog.com'
19
+ spec.description = 'Tool for parsing changelogs that are based on the '\
20
+ 'keepachangelog.com standard. Changelogs can be dumped '\
21
+ 'to JSON or YAML.'
22
+ spec.homepage = 'http://www.basalt.se'
23
+ spec.files = gem_files
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 12.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.5'
30
+ spec.add_development_dependency 'rubocop', '~> 0.47'
31
+ spec.add_development_dependency 'simplecov', '~> 0.14'
32
+ spec.add_development_dependency 'aruba', '~> 0.14'
33
+ spec.add_runtime_dependency 'thor', '~> 0.19'
34
+ spec.add_runtime_dependency 'json', '~> 2.0'
35
+ end
@@ -0,0 +1,6 @@
1
+ # require 'active_support'
2
+ # require 'active_support/core_ext'
3
+ require 'keepachangelog/version'
4
+ require 'keepachangelog/parser'
5
+ require 'json'
6
+ require 'yaml'
@@ -0,0 +1,39 @@
1
+ require 'keepachangelog'
2
+ require 'thor'
3
+
4
+ module Keepachangelog
5
+ class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ def self.shell
9
+ Thor::Base.shell.new
10
+ end
11
+
12
+ package_name 'Keepachangelog'
13
+
14
+ desc 'version', 'Show current version'
15
+ long_desc 'Show the version of the tool'
16
+ def version
17
+ require 'keepachangelog/version'
18
+ shell.say Keepachangelog.version
19
+ end
20
+
21
+ desc '<options> parse', 'Parse a changelog'
22
+ option :format, type: :string,
23
+ desc: 'The output format',
24
+ default: 'json',
25
+ banner: 'json|yaml',
26
+ aliases: '-f'
27
+ option :path, type: :string,
28
+ desc: 'Path to the changelog file',
29
+ default: 'CHANGELOG.md',
30
+ aliases: '-p'
31
+ def parse
32
+ require 'keepachangelog/parser'
33
+ p = Parser.load(options[:path])
34
+ shell.say p.send("to_#{options[:format]}")
35
+ end
36
+
37
+ default_task :parse
38
+ end
39
+ end
@@ -0,0 +1,82 @@
1
+ module Keepachangelog
2
+ class Parser
3
+ attr_accessor :parsed_content
4
+
5
+ def initialize(content = '')
6
+ self.parsed_content = parse(content)
7
+ end
8
+
9
+ def self.load(filename = 'CHANGELOG.md')
10
+ content = File.open(filename, &:read)
11
+ new(content)
12
+ end
13
+
14
+ def self.parse(content)
15
+ new(content)
16
+ end
17
+
18
+ def to_json
19
+ parsed_content.to_json
20
+ end
21
+
22
+ def to_yaml
23
+ parsed_content.to_yaml
24
+ end
25
+
26
+ def to_s
27
+ parsed_content.to_s
28
+ end
29
+
30
+ private
31
+
32
+ def parse(content)
33
+ content = "\n" + clean(content).strip + "\n"
34
+ anchors = extract_anchors! content
35
+ versions = content.split(/\n\s*## /)[1..-1]
36
+ versions.map { |v| parse_version v, anchors }
37
+ end
38
+
39
+ def clean(content)
40
+ content.sub(/^.*?\n\s*## /, '## ')
41
+ end
42
+
43
+ def parse_version(content, anchors)
44
+ header_pattern = /\[(?<name>.*)\]( - (?<date>\d\d\d\d-\d\d-\d\d))?/
45
+ sections = content.split(/\n\s*### /)
46
+ header = sections[0].match header_pattern
47
+ {
48
+ 'version' => header[:name],
49
+ 'url' => get_url(header[:name], anchors),
50
+ 'date' => header[:date],
51
+ 'changes' => sections[1..-1].map { |s| parse_section s }.to_h
52
+ }
53
+ end
54
+
55
+ def get_url(version, anchors)
56
+ anchors.keys.include?(version) ? anchors[version] : nil
57
+ end
58
+
59
+ def parse_section(content)
60
+ lines = content.split("\n")
61
+ bullets = lines[1..-1]
62
+ .select { |s| s.strip.start_with?('- ') }
63
+ .map { |s| clean_bullet(s) }
64
+ [lines[0], bullets]
65
+ end
66
+
67
+ def clean_bullet(string)
68
+ string.strip.gsub(/^\s*- /, '').gsub(/\(.*#\d+\)\.?$/, '').strip
69
+ end
70
+
71
+ def extract_anchors!(content)
72
+ anchor_pattern = /\n\s*\[(.*)\]: (.*)\s*\n/
73
+ anchors = content.scan anchor_pattern
74
+ cleaned_content = ''
75
+ while cleaned_content.to_s != content.to_s
76
+ cleaned_content = content.gsub anchor_pattern, "\n"
77
+ content.replace(cleaned_content)
78
+ end
79
+ anchors.map { |x| [x[0], x[1]] }.to_h
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ module Keepachangelog
4
+ def self.version
5
+ # return '0.1.0'
6
+ path = File.expand_path('../../package.json', File.dirname(__FILE__))
7
+ file = File.read path
8
+ json = JSON.parse file
9
+ json['version']
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "keepachangelog",
3
+ "version": "0.1.0",
4
+ "description": "Parser for changelogs based on keepachangelog.com",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git@git.basalt.se:chbr/keepachangelog.git"
12
+ },
13
+ "author": "Christoffer Reijer",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "grunt": "^1.0.1",
17
+ "grunt-bump": "^0.8.0",
18
+ "grunt-cli": "^1.2.0",
19
+ "grunt-contrib-jshint": "^1.0.0",
20
+ "grunt-contrib-watch": "^1.0.0",
21
+ "grunt-newer": "^1.2.0",
22
+ "grunt-shell": "^1.3.1",
23
+ "grunt-yaml-validator": "^0.10.0",
24
+ "js-yaml": "^3.6.1",
25
+ "load-grunt-tasks": "^3.5.2",
26
+ "time-grunt": "^1.4.0",
27
+ "grunt-ssh-deploy": "^0.4.1",
28
+ "grunt-git-describe": "^2.4.2"
29
+ }
30
+ }
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ module Keepachangelog
4
+ describe Parser do
5
+ describe '#parse' do
6
+ it 'should parse empty content' do
7
+ content = ''
8
+ p = Parser.new(content)
9
+ expect(p.parsed_content).to eq([])
10
+ end
11
+
12
+ it 'should parse single version' do
13
+ content = "
14
+ ## [1.2.3] - 2017-01-01
15
+ ### New
16
+ - Feature A
17
+ ### Fixed
18
+ - Feature B
19
+ [1.2.3]: http://test.io
20
+ "
21
+ p = Parser.new(content)
22
+ expect(p.parsed_content).to eq(
23
+ [
24
+ {
25
+ 'version' => '1.2.3',
26
+ 'url' => 'http://test.io',
27
+ 'date' => '2017-01-01',
28
+ 'changes' => {
29
+ 'New' => ['Feature A'],
30
+ 'Fixed' => ['Feature B']
31
+ }
32
+ }
33
+ ]
34
+ )
35
+ end
36
+
37
+ it 'should parse multiple versions' do
38
+ content = "
39
+ ## [2.0.0] - 2017-01-01
40
+ ### New
41
+ - Feature A
42
+ ## [1.0.0]
43
+ ### Fixed
44
+ - Feature B
45
+ [1.0.0]: http://test.io
46
+ "
47
+ p = Parser.new(content)
48
+ expect(p.parsed_content).to eq(
49
+ [
50
+ {
51
+ 'version' => '2.0.0',
52
+ 'url' => nil,
53
+ 'date' => '2017-01-01',
54
+ 'changes' => { 'New' => ['Feature A'] }
55
+ },
56
+ {
57
+ 'version' => '1.0.0',
58
+ 'url' => 'http://test.io',
59
+ 'date' => nil,
60
+ 'changes' => { 'Fixed' => ['Feature B'] }
61
+ }
62
+ ]
63
+ )
64
+ end
65
+
66
+ it 'should parse version without sections' do
67
+ content = "
68
+ ## [3.0.0]
69
+ ## [2.0.0] - 2017-01-01
70
+ ### New
71
+ - Feature A
72
+ ## [1.0.0]
73
+ "
74
+ p = Parser.new(content)
75
+ expect(p.parsed_content).to eq(
76
+ [
77
+ {
78
+ 'version' => '3.0.0', 'url' => nil, 'date' => nil,
79
+ 'changes' => {}
80
+ },
81
+ {
82
+ 'version' => '2.0.0',
83
+ 'url' => nil,
84
+ 'date' => '2017-01-01',
85
+ 'changes' => { 'New' => ['Feature A'] }
86
+ },
87
+ {
88
+ 'version' => '1.0.0', 'url' => nil, 'date' => nil,
89
+ 'changes' => {}
90
+ }
91
+ ]
92
+ )
93
+ end
94
+ end
95
+
96
+ describe '.load' do
97
+ it 'should parse content of file' do
98
+ content = 'test changelog'
99
+ allow(File).to receive(:open).and_call_original
100
+ expect(File).to receive(:open).with('test.md')
101
+ .and_yield(StringIO.new(content))
102
+ expect(Parser).to receive(:new).with(content)
103
+ Parser.load('test.md')
104
+ end
105
+
106
+ it 'should throw on non-existent file' do
107
+ expect do
108
+ Parser.load('invalid-file')
109
+ end.to raise_exception(
110
+ Errno::ENOENT,
111
+ 'No such file or directory @ rb_sysopen - invalid-file'
112
+ )
113
+ end
114
+ end
115
+
116
+ describe '.parse' do
117
+ it 'should call on .new' do
118
+ expect(Parser).to receive(:new).with('test')
119
+ Parser.parse('test')
120
+ end
121
+ end
122
+
123
+ describe '.to_json' do
124
+ it 'should cast parsed content into json' do
125
+ p = Parser.new
126
+ expect(p.parsed_content).to receive(:to_json)
127
+ p.to_json
128
+ end
129
+ end
130
+
131
+ describe '.to_yaml' do
132
+ it 'should cast parsed content into yaml' do
133
+ p = Parser.new
134
+ expect(p.parsed_content).to receive(:to_yaml)
135
+ p.to_yaml
136
+ end
137
+ end
138
+
139
+ describe '.to_s' do
140
+ it 'should cast parsed content into a string' do
141
+ p = Parser.new
142
+ expect(p.parsed_content).to receive(:to_s)
143
+ p.to_s
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,3 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'keepachangelog'
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keepachangelog do
4
+ describe '.version' do
5
+ it 'returns the version of the gem' do
6
+ expect(Keepachangelog.version).to match(/\d+\.\d+\.\d+.*/)
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keepachangelog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Basalt AB
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.47'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.47'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.14'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.14'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aruba
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.19'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.19'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ description: Tool for parsing changelogs that are based on the keepachangelog.com
126
+ standard. Changelogs can be dumped to JSON or YAML.
127
+ email:
128
+ - christoffer.brodd-reijer@basalt.se
129
+ executables:
130
+ - keepachangelog
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".gitlab-ci.yml"
136
+ - ".rubocop.yml"
137
+ - CHANGELOG.md
138
+ - CONTRIBUTING.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.md
142
+ - README.md
143
+ - bin/console
144
+ - bin/setup
145
+ - exe/keepachangelog
146
+ - features/help.feature
147
+ - features/parse.feature
148
+ - features/support/aruba.rb
149
+ - features/version.feature
150
+ - keepachangelog.gemspec
151
+ - lib/keepachangelog.rb
152
+ - lib/keepachangelog/cli.rb
153
+ - lib/keepachangelog/parser.rb
154
+ - lib/keepachangelog/version.rb
155
+ - package.json
156
+ - spec/parser_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/version_spec.rb
159
+ homepage: http://www.basalt.se
160
+ licenses:
161
+ - Nonstandard
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.6.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Parser for changelogs based on keepachangelog.com
183
+ test_files: []