From 78605c4f1c18a82b4478f74d24ea994be1d4c906 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 10 Feb 2023 15:30:28 -0300 Subject: [PATCH 01/26] allow for multiple items with the same starting letter on meta --- lib/changelogerator.rb | 73 +++++++++++++++++++++++++----------------- test/test_basic.rb | 6 ++++ test/test_helpers.rb | 10 +++--- test/test_meta.rb | 62 +++++++++++++++++++++++++++-------- test/utils.rb | 28 ++++++++++++++++ 5 files changed, 131 insertions(+), 48 deletions(-) create mode 100644 test/utils.rb diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index 0b828a3..2aedc27 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -1,5 +1,49 @@ # frozen_string_literal: true +# Return the label code for a change +# if the label name matches the expected pattern. +# nil otherwise. +def parse_change_label(name) + m = match = name.match(/^([a-z])(\d+)-(.*)$/i) + return nil unless m + + letter, digits, text = match.captures + number = digits.to_i + [letter, number, text] +end + +def compute_change_meta(change) + meta = {} + + change.labels.each do |label| + letter, number, text = parse_change_label(label.name) + + next unless letter && number + + if meta.key?(letter) + aggregate = meta[letter]['agg'] + aggregate['max'] = number if number > aggregate['max'] + aggregate['min'] = number if number < aggregate['min'] + aggregate['count'] += 1 + else + meta[letter] = { + 'agg' => { + 'count' => 1, + 'max' => number, + 'min' => number + } + } + end + + meta[letter]["#{letter}#{number}"] = { + 'value' => number, + 'text' => text + } + end + + change['meta'] = meta +end + # A small wrapper class for more easily generating and manipulating Github/Git # changelogs. Given two different git objects (sha, tag, whatever), it will # find all PRs that made up that diff and store them as a list. Also allows @@ -54,18 +98,6 @@ def self.changes_files_in_paths?(change, paths) nil end - # Return the label code for a change - # if the label name matches the expected pattern. - # nil otherwise. - def self.get_label_code(name) - m = match = name.match(/^([a-z])(\d+)-(.*)$/i) - if m - letter, number, text = match.captures - return [letter, number, text] - end - nil - end - ## End of class methods # github_repo: 'paritytech/polkadot' @@ -125,23 +157,6 @@ def to_json(*_args) private - # Compute and attach metadata about one change - def compute_change_meta(change) - meta = {} - - change.labels.each do |label| - letter, number, text = self.class.get_label_code(label.name) - next unless letter && number - - meta[letter] = { - value: number.to_i, - text: text - } - end - - change['meta'] = meta - end - # Prepend the repo if @prefix is true def prettify_title(pull) pull[:pretty_title] = if @prefix diff --git a/test/test_basic.rb b/test/test_basic.rb index 460ae0f..107bc73 100644 --- a/test/test_basic.rb +++ b/test/test_basic.rb @@ -6,6 +6,8 @@ class TestChangelogerator < Test::Unit::TestCase def test_polkadot_1_commit + return unless ENV['GITHUB_TOKEN'] + ref1 = '2ebabcec7fcbb3d13a965a852df0559a4aa12a5e' ref2 = '9c05f9753b2f939ccf5ba18c08dd4c83c3ab9e0b' cl = Changelog.new( @@ -22,6 +24,8 @@ def test_polkadot_1_commit end def test_polkadot_many_commits + return unless ENV['GITHUB_TOKEN'] + ref1 = 'v0.9.8' ref2 = 'v0.9.11' cl = Changelog.new( @@ -39,6 +43,8 @@ def test_polkadot_many_commits end def test_cumulus_many_commits + return unless ENV['GITHUB_TOKEN'] + ref1 = 'statemine-v1.0.0' ref2 = 'statemine_v4' cl = Changelog.new( diff --git a/test/test_helpers.rb b/test/test_helpers.rb index 520d8c4..d83a177 100644 --- a/test/test_helpers.rb +++ b/test/test_helpers.rb @@ -6,17 +6,17 @@ class TestChangelogerator < Test::Unit::TestCase def test_helpers - letter, number, text = Changelog.get_label_code('B2-test') + letter, number, text = parse_change_label('B2-test') assert_equal('B', letter) - assert_equal('2', number) + assert_equal(2, number) assert_equal('test', text) - letter, number, text = Changelog.get_label_code('Z44-test 😁') + letter, number, text = parse_change_label('Z44-test 😁') assert_equal('Z', letter) - assert_equal('44', number) + assert_equal(44, number) assert_equal('test 😁', text) - letter, number, text = Changelog.get_label_code('123-foo') + letter, number, text = parse_change_label('123-foo') assert_equal(nil, letter) assert_equal(nil, number) assert_equal(nil, text) diff --git a/test/test_meta.rb b/test/test_meta.rb index 6a9cfdc..0aa6f47 100644 --- a/test/test_meta.rb +++ b/test/test_meta.rb @@ -2,27 +2,61 @@ require 'json' require_relative '../lib/changelogerator' +require_relative './utils' require 'test/unit' class TestChangelogerator < Test::Unit::TestCase def test_meta_1_commit - ref1 = '2ebabcec7fcbb3d13a965a852df0559a4aa12a5e' - ref2 = '9c05f9753b2f939ccf5ba18c08dd4c83c3ab9e0b' + change = Change.new(%w[A1-foo A2-foo B0-foo B1-foo B2-foo]) + compute_change_meta(change) - cl = Changelog.new( - 'paritytech/polkadot', ref1, ref2, - token: ENV['GITHUB_TOKEN'], - prefix: true - ) + p change.meta.to_json - j = cl.to_json - assert_equal(1, cl.changes.length) - assert_equal(%w[A B C], cl.changes[0].meta.keys) # A2 + B0 + C1 + assert_equal(%w[A B], change.meta.keys) - p cl.meta + assert_equal(change.meta['A']['agg']['min'], 1) # A(1) + assert_equal(change.meta['A']['agg']['max'], 2) # A(2) + assert_equal(change.meta['A']['agg']['count'], 2) # A1 + A2 - puts format('JSON Length: %d', j.length) - assert(j.length > 11_000) - assert(j.length < 13_000) + assert_equal(change.meta['B']['agg']['min'], 0) # B(0) + assert_equal(change.meta['B']['agg']['max'], 2) # B(2) + assert_equal(change.meta['B']['agg']['count'], 3) # B0 + B1 + B2 + + assert_equal(JSON.pretty_generate(change.meta), '{ + "A": { + "agg": { + "count": 2, + "max": 2, + "min": 1 + }, + "A1": { + "value": 1, + "text": "foo" + }, + "A2": { + "value": 2, + "text": "foo" + } + }, + "B": { + "agg": { + "count": 3, + "max": 2, + "min": 0 + }, + "B0": { + "value": 0, + "text": "foo" + }, + "B1": { + "value": 1, + "text": "foo" + }, + "B2": { + "value": 2, + "text": "foo" + } + } +}') end end diff --git a/test/utils.rb b/test/utils.rb new file mode 100644 index 0000000..7c82f3c --- /dev/null +++ b/test/utils.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class Change + attr_reader :labels + + class Label + attr_reader :name + + def initialize(name) + @name = name + end + end + + def initialize(labels) + @labels = labels.map do |label| + Label.new(label) + end + @extra = {} + end + + def []=(key, value) + @extra[key] = value + end + + def meta + @extra['meta'] + end +end From 8589e5bb1aca9768d1ee704c426812e17c4aefc2 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 10 Feb 2023 15:36:23 -0300 Subject: [PATCH 02/26] remove unnecessary print --- test/test_meta.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_meta.rb b/test/test_meta.rb index 0aa6f47..69ebe5e 100644 --- a/test/test_meta.rb +++ b/test/test_meta.rb @@ -10,8 +10,6 @@ def test_meta_1_commit change = Change.new(%w[A1-foo A2-foo B0-foo B1-foo B2-foo]) compute_change_meta(change) - p change.meta.to_json - assert_equal(%w[A B], change.meta.keys) assert_equal(change.meta['A']['agg']['min'], 1) # A(1) From 6bfabdf4ac582c6dd06fd32a328e5a0932a08b93 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 10 Feb 2023 15:51:13 -0300 Subject: [PATCH 03/26] bump version for breaking change --- changelogerator.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogerator.gemspec b/changelogerator.gemspec index ccdcee0..dc840d1 100644 --- a/changelogerator.gemspec +++ b/changelogerator.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'changelogerator' - s.version = '0.9.1' + s.version = '0.10.0' s.summary = 'Changelog generation/management' s.authors = ['Martin Pugh', 'Wilfried Kopp'] s.files = ['lib/changelogerator.rb', 'bin/changelogerator'] From 5cec1001181fde55695df81e2cc732a1f67ecfe1 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 10 Feb 2023 16:43:47 -0300 Subject: [PATCH 04/26] fix global meta usage --- lib/changelogerator.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index 2aedc27..c6894f8 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -76,13 +76,12 @@ def compute_global_meta change._links = nil change[:meta].each_key do |meta_key| - current = change[:meta][meta_key] + aggregate = change[:meta][meta_key]['agg'] meta[meta_key] = {} unless meta[meta_key] - meta[meta_key][:min] = current[:value] if !meta[meta_key][:min] || current[:value] < meta[meta_key][:min] - meta[meta_key][:max] = current[:value] if !meta[meta_key][:max] || current[:value] > meta[meta_key][:max] - meta[meta_key][:count] = 0 unless meta[meta_key][:count] - meta[meta_key][:count] += 1 + meta[meta_key][:min] = aggregate['min'] if !meta[meta_key][:min] || aggregate[:min] < meta[meta_key]['min'] + meta[meta_key][:max] = aggregate['max'] if !meta[meta_key][:max] || aggregate[:max] > meta[meta_key]['max'] + meta[meta_key][:count] += aggregate['count'] end end end From ec417e3222f9e34bccdb093a831f2b6cc23adb84 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Fri, 10 Feb 2023 16:53:15 -0300 Subject: [PATCH 05/26] fix global meta assignments --- lib/changelogerator.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index c6894f8..1ddd7b1 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -78,10 +78,17 @@ def compute_global_meta change[:meta].each_key do |meta_key| aggregate = change[:meta][meta_key]['agg'] - meta[meta_key] = {} unless meta[meta_key] - meta[meta_key][:min] = aggregate['min'] if !meta[meta_key][:min] || aggregate[:min] < meta[meta_key]['min'] - meta[meta_key][:max] = aggregate['max'] if !meta[meta_key][:max] || aggregate[:max] > meta[meta_key]['max'] - meta[meta_key][:count] += aggregate['count'] + if meta[meta_key] + meta[meta_key][:min] = aggregate['min'] if aggregate['min'] < meta[meta_key][:min] + meta[meta_key][:max] = aggregate['max'] if aggregate['max'] > meta[meta_key][:max] + meta[meta_key][:count] += aggregate['count'] + else + meta[meta_key] = { + min: aggregate['min'], + max: aggregate['max'], + count: aggregate['count'] + } + end end end end From 7f950094beaf2903bb32d70d9281c2067435431c Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 07:33:34 -0300 Subject: [PATCH 06/26] re-add comment on compute_change_meta --- lib/changelogerator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index 1ddd7b1..5f5d6f0 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -12,6 +12,7 @@ def parse_change_label(name) [letter, number, text] end +# Compute and attach metadata about one change def compute_change_meta(change) meta = {} From fcbd1982327416c15574839ffd2f418ac3162195 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 08:17:26 -0300 Subject: [PATCH 07/26] refactor $GITHUB_TOKEN checks --- README.md | 6 ++++++ test/test_basic.rb | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 580bd07..c13a89a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,12 @@ The produce json will be formatted as: The produced json output can then easily reprocessed into a beautiful changelog using tools such as [`tera`](https://github.com/chevdor/tera-cli). +## Testing + +Some of the tests fetch data from GitHub. In case you do not have a +`$GITHUB_TOKEN` or simply do not wish to run them, set `GITHUB_TOKEN=disabled` +in your environment variables. + ## Usage You can check out the [tests](./test) to see it in action or query the help: diff --git a/test/test_basic.rb b/test/test_basic.rb index 107bc73..30c934a 100644 --- a/test/test_basic.rb +++ b/test/test_basic.rb @@ -5,9 +5,12 @@ require 'test/unit' class TestChangelogerator < Test::Unit::TestCase - def test_polkadot_1_commit - return unless ENV['GITHUB_TOKEN'] + def setup + omit("Skipping because $GITHUB_TOKEN=#{ENV['GITHUB_TOKEN']}") if ENV['GITHUB_TOKEN'] == 'disabled' + raise 'Missing $GITHUB_TOKEN token' if (ENV['GITHUB_TOKEN']).empty? + end + def test_polkadot_1_commit ref1 = '2ebabcec7fcbb3d13a965a852df0559a4aa12a5e' ref2 = '9c05f9753b2f939ccf5ba18c08dd4c83c3ab9e0b' cl = Changelog.new( @@ -24,8 +27,6 @@ def test_polkadot_1_commit end def test_polkadot_many_commits - return unless ENV['GITHUB_TOKEN'] - ref1 = 'v0.9.8' ref2 = 'v0.9.11' cl = Changelog.new( @@ -43,8 +44,6 @@ def test_polkadot_many_commits end def test_cumulus_many_commits - return unless ENV['GITHUB_TOKEN'] - ref1 = 'statemine-v1.0.0' ref2 = 'statemine_v4' cl = Changelog.new( From 93417864d0f22b55ea59be66d0985bbe7fc58f47 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 08:20:47 -0300 Subject: [PATCH 08/26] refactor $GITHUB_TOKEN checks --- test/test_basic.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_basic.rb b/test/test_basic.rb index 30c934a..cc0cba1 100644 --- a/test/test_basic.rb +++ b/test/test_basic.rb @@ -6,8 +6,9 @@ class TestChangelogerator < Test::Unit::TestCase def setup - omit("Skipping because $GITHUB_TOKEN=#{ENV['GITHUB_TOKEN']}") if ENV['GITHUB_TOKEN'] == 'disabled' - raise 'Missing $GITHUB_TOKEN token' if (ENV['GITHUB_TOKEN']).empty? + gh_token = ENV['GITHUB_TOKEN'] + omit("Skipping because $GITHUB_TOKEN=#{gh_token}") if gh_token == 'disabled' + raise 'Missing $GITHUB_TOKEN token' if gh_token.nil? || gh_token.empty? end def test_polkadot_1_commit From a066bd7b5871b352cbe8ec652cf9b1483848756f Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 11:10:29 +0100 Subject: [PATCH 09/26] bump version to 3.0.5 and add MFA --- .ruby-version | 2 +- changelogerator.gemspec | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index b502146..eca690e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.2 +3.0.5 diff --git a/changelogerator.gemspec b/changelogerator.gemspec index dc840d1..fe717d5 100644 --- a/changelogerator.gemspec +++ b/changelogerator.gemspec @@ -15,4 +15,5 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'git_diff_parser', '~> 3' s.add_runtime_dependency 'octokit', '~> 4' s.required_ruby_version = '>= 2.7' + s.metadata = { 'rubygems_mfa_required' => 'true' } end From 1439f0de97bf6e7dbae9930041ab80764d6c4d76 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 12:25:08 +0100 Subject: [PATCH 10/26] Extract a Label class and add some tests --- lib/label.rb | 25 ++++++++++++++ test/test_parser.rb | 83 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 lib/label.rb create mode 100644 test/test_parser.rb diff --git a/lib/label.rb b/lib/label.rb new file mode 100644 index 0000000..d39850b --- /dev/null +++ b/lib/label.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +### Label = Code + Number + description +class Label + attr_accessor :code, :number, :description + + # Return the label code for a change if the label name matches the expected pattern. + # nil otherwise. + def parse(label) + m = match = label.match(/^([a-z])(\d+)\s*-?\s*(.*)$/i) + return nil unless m + + letter, digits, text = match.captures + number = digits.to_i + [letter, number, text] + end + + def initialize(input) + p = parse(input) + + @code = p[0].upcase + @number = p[1] + @description = p[2] unless p[2].empty? + end +end diff --git a/test/test_parser.rb b/test/test_parser.rb new file mode 100644 index 0000000..a1b354d --- /dev/null +++ b/test/test_parser.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require_relative '../lib/label' +require 'test/unit' + +class TestParser < Test::Unit::TestCase + def test1 + lbl = Label.new('B2-foo') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo', lbl.description) + end + + def test_no_desc + lbl = Label.new('B2-') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal(nil, lbl.description) + end + + def test_no_dash + lbl = Label.new('B2') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal(nil, lbl.description) + end + + def test_double_digits + lbl = Label.new('B12-foo') + assert_equal('B', lbl.code) + assert_equal(12, lbl.number) + assert_equal('foo', lbl.description) + end + + def test_spacing1 + lbl = Label.new('B2 -foo') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo', lbl.description) + end + + def test_spacing2 + lbl = Label.new('B2- foo') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo', lbl.description) + end + + def test_spacing3 + lbl = Label.new('B2 - foo') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo', lbl.description) + end + + def test_description_with_spaces1 + lbl = Label.new('B2-foo bar') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo bar', lbl.description) + end + + def test_description_with_spaces2 + lbl = Label.new('B2- foo bar') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo bar', lbl.description) + end + + def test_description_with_emojis + lbl = Label.new('B2-foo bar 😄😄😄') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo bar 😄😄😄', lbl.description) + end + + def test_case1 + lbl = Label.new('b2-foo Bar') + assert_equal('B', lbl.code) + assert_equal(2, lbl.number) + assert_equal('foo Bar', lbl.description) + end +end From 879d391e01147d277dab5297f99f2cf52892fb0f Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 12:39:10 +0100 Subject: [PATCH 11/26] Add error handling --- lib/label.rb | 3 +++ test/test_helpers.rb | 24 ------------------------ test/test_parser.rb | 6 ++++++ 3 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 test/test_helpers.rb diff --git a/lib/label.rb b/lib/label.rb index d39850b..d993d69 100644 --- a/lib/label.rb +++ b/lib/label.rb @@ -17,9 +17,12 @@ def parse(label) def initialize(input) p = parse(input) + raise InvalidLabel, 'Invalid label' unless p @code = p[0].upcase @number = p[1] @description = p[2] unless p[2].empty? end end + +class InvalidLabel < StandardError; end diff --git a/test/test_helpers.rb b/test/test_helpers.rb deleted file mode 100644 index d83a177..0000000 --- a/test/test_helpers.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -require 'json' -require_relative '../lib/changelogerator' -require 'test/unit' - -class TestChangelogerator < Test::Unit::TestCase - def test_helpers - letter, number, text = parse_change_label('B2-test') - assert_equal('B', letter) - assert_equal(2, number) - assert_equal('test', text) - - letter, number, text = parse_change_label('Z44-test 😁') - assert_equal('Z', letter) - assert_equal(44, number) - assert_equal('test 😁', text) - - letter, number, text = parse_change_label('123-foo') - assert_equal(nil, letter) - assert_equal(nil, number) - assert_equal(nil, text) - end -end diff --git a/test/test_parser.rb b/test/test_parser.rb index a1b354d..8267882 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -80,4 +80,10 @@ def test_case1 assert_equal(2, lbl.number) assert_equal('foo Bar', lbl.description) end + + def test_case_no_label + assert_raises InvalidLabel, 'xxx' do + Label.new('123-foo') + end + end end From 7934dbfacde8dd5bacfc879df50ea46d1e694def Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 12:51:14 +0100 Subject: [PATCH 12/26] Avoid skipping tests that could run --- test/test_meta.rb | 2 +- test/{test_basic.rb => test_with_token.rb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/{test_basic.rb => test_with_token.rb} (100%) diff --git a/test/test_meta.rb b/test/test_meta.rb index 69ebe5e..2b7872f 100644 --- a/test/test_meta.rb +++ b/test/test_meta.rb @@ -5,7 +5,7 @@ require_relative './utils' require 'test/unit' -class TestChangelogerator < Test::Unit::TestCase +class TestMeta < Test::Unit::TestCase def test_meta_1_commit change = Change.new(%w[A1-foo A2-foo B0-foo B1-foo B2-foo]) compute_change_meta(change) diff --git a/test/test_basic.rb b/test/test_with_token.rb similarity index 100% rename from test/test_basic.rb rename to test/test_with_token.rb From c5942aae2187f80ec370e59704c580e3b4b8cc4a Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 08:56:53 -0300 Subject: [PATCH 13/26] set GITHUB_TOKEN=disabled for pull requests on CI --- .github/workflows/check.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1c0f786..c992230 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,6 +29,10 @@ jobs: - name: Lint check run: rubocop + - name: Set up tests + if: ${{ github.event_name == "pull_request" }} + run: echo "GITHUB_TOKEN=disabled" >> "$GITHUB_ENV" + - name: Run tests run: bundle exec rake test From 1577956ef37b794b48afaa77735d2498302fc02d Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 09:00:09 -0300 Subject: [PATCH 14/26] fix if expression --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c992230..39bd97c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -30,7 +30,7 @@ jobs: run: rubocop - name: Set up tests - if: ${{ github.event_name == "pull_request" }} + if: github.event_name == "pull_request" run: echo "GITHUB_TOKEN=disabled" >> "$GITHUB_ENV" - name: Run tests From ec43e6a0416281cca7d6fa2cc5605b3665bd5b42 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 09:01:28 -0300 Subject: [PATCH 15/26] fix if expression --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 39bd97c..04c5bfb 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -30,7 +30,7 @@ jobs: run: rubocop - name: Set up tests - if: github.event_name == "pull_request" + if: ${{ github.event_name == 'pull_request' }} run: echo "GITHUB_TOKEN=disabled" >> "$GITHUB_ENV" - name: Run tests From 0906060544989d0337ca55f067ce1f4242f72090 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 14:41:49 +0100 Subject: [PATCH 16/26] Fix readme --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c13a89a..acdaa94 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,24 @@ # Changelog-erator :) -This utility is written in Ruby. It uses the Octokit gem to connect to: +This utility is written in Ruby. It uses the [Octokit](https://github.com/octokit) gem to: - connect to Github - retrieve the list of changes between 2 references -While 0.x versions were rather specific to the [Polkadot](https://github.com/paritytech/polkadot) repository, those limitations have been removed starting with 0.9.x versions. +While `0.x` versions were rather specific to the [Polkadot](https://github.com/paritytech/polkadot) repository, those limitations have been removed starting with `0.9.x` versions. The only requirement if you want to benefit from filtering labels in a better way that just comparing label names if to name your labels using the following generic pattern as see [here](https://github.com/paritytech/polkadot/labels): -`-` +`[-]` For instance: - `B0-Silent 😎` - `C1-Important ❗️` +- `Z12` -Each of your issues or PR can have any number of labels but you should avoid having multiple labels of the same category. For instance, you do not want to have both `B0` and `B7`. +Each of your issues or PR can have any number of labels. Advanced rules for labels can be defined and enforced using [ruled_labels](https://github.com/chevdor/ruled_labels). -Running the `changelogerator` will fetch all your changes from Github. You should set a value for the ENV `GITHUB_TOKEN` if you want to avoid being rate limited. +Running `changelogerator` will fetch all the changes for a given repository from Github. You should set a value for the ENV `GITHUB_TOKEN` if you want to avoid being rate limited. The produce json will be formatted as: ``` @@ -99,3 +100,9 @@ jq \ { name: "polkadot", data: $srtool_polkadot[0] } ] }' | tee context.json ``` + +## Dev notes + +- install: `bundle install` +- test: `rake test` (some of the test appear to be UN responding for a good minute, see how to set `GITHUB_TOKEN` above to speed things up) +- linting/formatting: `rubocop` From 54770bdabb70c4c7b9e0db413b96874d75a26875 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 14:44:13 +0100 Subject: [PATCH 17/26] Remove some polkadot/srtool specifics --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index acdaa94..8f0952f 100644 --- a/README.md +++ b/README.md @@ -88,16 +88,14 @@ Here is an example: ``` jq \ - --slurpfile srtool_kusama kusama-srtool-digest.json \ - --slurpfile srtool_polkadot polkadot-srtool-digest.json \ - --slurpfile polkadot polkadot.json \ - --slurpfile substrate substrate.json \ + --slurpfile foo.json \ + --slurpfile bar.json \ -n '{ - polkadot: $polkadot[0], - substrate: $substrate[0], - srtool: [ - { name: "kusama", data: $srtool_kusama[0] }, - { name: "polkadot", data: $srtool_polkadot[0] } + foo: $foo[0], + bar: $bar[0], + foobar: [ + { age: 12 }, + { name: "bob" } ] }' | tee context.json ``` From 140602d8856db34bc0660f2b2ea111e353805c3a Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 11:10:55 -0300 Subject: [PATCH 18/26] update README example --- README.md | 65 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index c13a89a..0c51240 100644 --- a/README.md +++ b/README.md @@ -20,34 +20,61 @@ Each of your issues or PR can have any number of labels but you should avoid hav Running the `changelogerator` will fetch all your changes from Github. You should set a value for the ENV `GITHUB_TOKEN` if you want to avoid being rate limited. The produce json will be formatted as: -``` + +```jsonc { - "cl": { - "meta": { + "polkadot": { + "meta": { // top-level metadata which aggregates the info for .changes[].meta "C": { - "min": 3, - "max": 9, - "count": 3 - }, ... + "min": 1, + "max": 1, + "count": 1 + }, + "D": { + "min": 2, + "max": 2, + "count": 1 + } }, - "repository" : { - "id" : 42, - "node_id" : "...", - "name" : "polkadot", - ... + "repository": { + /* + Includes the fields from the GitHub Repositories REST API + See https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository + */ }, "changes": [ + /* + Each entry corresponds to a pull request with the fields from the GitHub PR Rest API + See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request + In addition to the API fields, each entry has a "meta" field with + information computed from its labels. + */ { "meta": { "C": { - "value": 7 + "C1": { + "value": 1, + "text": "needs-audit" + }, + "agg": { + "min": 1, + "max": 1, + "count": 1 + } }, - "D": { "value": 8 } - }, - ... Github information ... - "number": 1234, - ... way more information about the commit - ... coming from Github + "D": { + "D2": { + "value": 2, + "text": "runtime" + }, + "agg": { + "min": 2, + "max": 2, + "count": 1 + } + } + } + // ... other fields from the REST API } ] } From 4cbf9d6ea68ebd724bb370723bd10bb091870471 Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Tue, 14 Feb 2023 11:19:51 -0300 Subject: [PATCH 19/26] improve comments --- README.md | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 280d277..3444546 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ The produce json will be formatted as: "meta": { // top-level metadata which aggregates the info for .changes[].meta "C": { "min": 1, - "max": 1, - "count": 1 + "max": 3, + "count": 2 }, "D": { "min": 2, @@ -39,39 +39,44 @@ The produce json will be formatted as: }, "repository": { /* - Includes the fields from the GitHub Repositories REST API - See https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository + Includes the fields from the GitHub Repositories REST API. + See: https://docs.github.com/en/rest/repos/repos#get-a-repository */ }, "changes": [ /* - Each entry corresponds to a pull request with the fields from the GitHub PR Rest API - See https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request + Each entry corresponds to a pull request with the fields from the + GitHub PR Rest API. + See: https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request In addition to the API fields, each entry has a "meta" field with information computed from its labels. */ { "meta": { "C": { - "C1": { + "C1": { // parsed from C1-needs_audit "value": 1, - "text": "needs-audit" + "text": "needs_audit" + }, + "C3": { // parsed from C3-urgent + "value": 3, + "text": "urgent" }, "agg": { - "min": 1, - "max": 1, - "count": 1 + "min": 1, // related to the value 1 of C1 + "max": 3, // related to the value 3 of C3 + "count": 2 // two C-labels were parsed (C1 and C3) } }, "D": { - "D2": { + "D2": { // parsed from D2-runtime "value": 2, "text": "runtime" }, "agg": { - "min": 2, - "max": 2, - "count": 1 + "min": 2, // related to the value 2 of D2 + "max": 2, // related to the value 2 of D2 + "count": 1 // one D-label was parsed (D2) } } } From 27d21e237ab9bf6ad767858907edbfa68cb0eab2 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Tue, 14 Feb 2023 14:47:32 +0100 Subject: [PATCH 20/26] Add new test --- test/test_parser.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test_parser.rb b/test/test_parser.rb index 8267882..2f444ff 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -86,4 +86,11 @@ def test_case_no_label Label.new('123-foo') end end + + def test_leading_zeroes + lbl = Label.new('A00099-foo') + assert_equal('A', lbl.code) + assert_equal(99, lbl.number) + assert_equal('foo', lbl.description) + end end From d3be4b3784df43dda2f82281bb60a4295cf9b580 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Wed, 15 Feb 2023 09:48:21 +0100 Subject: [PATCH 21/26] Refactoring for better irb support --- README.md | 1 + test/utils.rb => lib/change.rb | 11 +--- lib/changelogerator.rb | 86 +++++++++++++--------------- lib/label.rb | 23 ++++++-- test/{test_meta.rb => test_local.rb} | 6 +- test/test_parser.rb | 24 ++++---- test/test_with_token.rb | 1 + 7 files changed, 78 insertions(+), 74 deletions(-) rename test/utils.rb => lib/change.rb (72%) rename test/{test_meta.rb => test_local.rb} (90%) diff --git a/README.md b/README.md index 3444546..4dd9cd6 100644 --- a/README.md +++ b/README.md @@ -135,4 +135,5 @@ jq \ - install: `bundle install` - test: `rake test` (some of the test appear to be UN responding for a good minute, see how to set `GITHUB_TOKEN` above to speed things up) +- run single test: `ruby -I test test/test_with_token.rb -n test_polkadot_1_commit` - linting/formatting: `rubocop` diff --git a/test/utils.rb b/lib/change.rb similarity index 72% rename from test/utils.rb rename to lib/change.rb index 7c82f3c..be0ed82 100644 --- a/test/utils.rb +++ b/lib/change.rb @@ -1,16 +1,11 @@ # frozen_string_literal: true +require_relative '../lib/label' + +### A class describe one change that can potentially have several labels class Change attr_reader :labels - class Label - attr_reader :name - - def initialize(name) - @name = name - end - end - def initialize(labels) @labels = labels.map do |label| Label.new(label) diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index 5f5d6f0..3f9664f 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -1,49 +1,7 @@ # frozen_string_literal: true -# Return the label code for a change -# if the label name matches the expected pattern. -# nil otherwise. -def parse_change_label(name) - m = match = name.match(/^([a-z])(\d+)-(.*)$/i) - return nil unless m - - letter, digits, text = match.captures - number = digits.to_i - [letter, number, text] -end - -# Compute and attach metadata about one change -def compute_change_meta(change) - meta = {} - - change.labels.each do |label| - letter, number, text = parse_change_label(label.name) - - next unless letter && number - - if meta.key?(letter) - aggregate = meta[letter]['agg'] - aggregate['max'] = number if number > aggregate['max'] - aggregate['min'] = number if number < aggregate['min'] - aggregate['count'] += 1 - else - meta[letter] = { - 'agg' => { - 'count' => 1, - 'max' => number, - 'min' => number - } - } - end - - meta[letter]["#{letter}#{number}"] = { - 'value' => number, - 'text' => text - } - end - - change['meta'] = meta -end +require_relative '../lib/label' +require_relative '../lib/change' # A small wrapper class for more easily generating and manipulating Github/Git # changelogs. Given two different git objects (sha, tag, whatever), it will @@ -122,16 +80,17 @@ def initialize(github_repo, from, to, token: '', prefix: nil) @repository = @gh.repository(@repo) @prefix = prefix ids = pr_ids_from_git_diff(from, to) + # The following takes very long time @changes = prs_from_ids(ids) @changes.map do |c| - compute_change_meta(c) + self.class.compute_change_meta(c) end compute_global_meta end def add(change) - compute_change_meta(change) + self.class.compute_change_meta(change) prettify_title(change) changes.prepend(change) @meta = compute_global_meta @@ -162,6 +121,40 @@ def to_json(*_args) JSON.fast_generate(commits, opts) end + # Compute and attach metadata about one change + def self.compute_change_meta(change) + meta = {} + + change.labels.each do |lbl| + # letter, number, text = parse_change_label(label.name) + label = Label.new(lbl.name) + + next unless label + + if meta.key?(label.letter) + aggregate = meta[label.letter]['agg'] + aggregate['max'] = label.number if label.number > aggregate['max'] + aggregate['min'] = label.number if label.number < aggregate['min'] + aggregate['count'] += 1 + else + meta[label.letter] = { + 'agg' => { + 'count' => 1, + 'max' => label.number, + 'min' => label.number + } + } + end + + meta[label.letter]["#{label.letter}#{label.number}"] = { + 'value' => label.number, + 'text' => label.description + } + end + + change['meta'] = meta + end + private # Prepend the repo if @prefix is true @@ -185,6 +178,7 @@ def pr_ids_from_git_diff(from, to) end.compact.map(&:to_i) end + # TODO: See if we can make this quicker def prs_from_ids(ids) batch_size = 100 prs = [] diff --git a/lib/label.rb b/lib/label.rb index d993d69..b6bf05e 100644 --- a/lib/label.rb +++ b/lib/label.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -### Label = Code + Number + description +### Label = Letter + Number [+ Description] class Label - attr_accessor :code, :number, :description + attr_accessor :letter, :number, :description - # Return the label code for a change if the label name matches the expected pattern. + # Return the label letter for a change if the label name matches the expected pattern. # nil otherwise. def parse(label) m = match = label.match(/^([a-z])(\d+)\s*-?\s*(.*)$/i) @@ -16,13 +16,26 @@ def parse(label) end def initialize(input) + raise InvalidInput, 'Invalid, it must be a non-empty string' unless input + p = parse(input) - raise InvalidLabel, 'Invalid label' unless p + raise InvalidLabel, format('Invalid label "%s"', { input: input }) unless p - @code = p[0].upcase + @letter = p[0].upcase @number = p[1] @description = p[2] unless p[2].empty? end + + ### Implemented for compatibility reasons + def name + puts format('%s%d', { l: @letter, n: @number }) + end + + def to_str + format('%s%d - %s', { l: @letter, n: @number, d: @description }) + end end class InvalidLabel < StandardError; end + +class InvalidInput < StandardError; end diff --git a/test/test_meta.rb b/test/test_local.rb similarity index 90% rename from test/test_meta.rb rename to test/test_local.rb index 2b7872f..bfc0101 100644 --- a/test/test_meta.rb +++ b/test/test_local.rb @@ -2,13 +2,13 @@ require 'json' require_relative '../lib/changelogerator' -require_relative './utils' +require_relative '../lib/change' require 'test/unit' -class TestMeta < Test::Unit::TestCase +class TestLocal < Test::Unit::TestCase def test_meta_1_commit change = Change.new(%w[A1-foo A2-foo B0-foo B1-foo B2-foo]) - compute_change_meta(change) + Changelog.compute_change_meta(change) assert_equal(%w[A B], change.meta.keys) diff --git a/test/test_parser.rb b/test/test_parser.rb index 2f444ff..2607f5d 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -6,77 +6,77 @@ class TestParser < Test::Unit::TestCase def test1 lbl = Label.new('B2-foo') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo', lbl.description) end def test_no_desc lbl = Label.new('B2-') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal(nil, lbl.description) end def test_no_dash lbl = Label.new('B2') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal(nil, lbl.description) end def test_double_digits lbl = Label.new('B12-foo') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(12, lbl.number) assert_equal('foo', lbl.description) end def test_spacing1 lbl = Label.new('B2 -foo') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo', lbl.description) end def test_spacing2 lbl = Label.new('B2- foo') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo', lbl.description) end def test_spacing3 lbl = Label.new('B2 - foo') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo', lbl.description) end def test_description_with_spaces1 lbl = Label.new('B2-foo bar') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo bar', lbl.description) end def test_description_with_spaces2 lbl = Label.new('B2- foo bar') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo bar', lbl.description) end def test_description_with_emojis lbl = Label.new('B2-foo bar 😄😄😄') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo bar 😄😄😄', lbl.description) end def test_case1 lbl = Label.new('b2-foo Bar') - assert_equal('B', lbl.code) + assert_equal('B', lbl.letter) assert_equal(2, lbl.number) assert_equal('foo Bar', lbl.description) end @@ -89,7 +89,7 @@ def test_case_no_label def test_leading_zeroes lbl = Label.new('A00099-foo') - assert_equal('A', lbl.code) + assert_equal('A', lbl.letter) assert_equal(99, lbl.number) assert_equal('foo', lbl.description) end diff --git a/test/test_with_token.rb b/test/test_with_token.rb index cc0cba1..aebf92e 100644 --- a/test/test_with_token.rb +++ b/test/test_with_token.rb @@ -3,6 +3,7 @@ require 'json' require_relative '../lib/changelogerator' require 'test/unit' +require 'pry' class TestChangelogerator < Test::Unit::TestCase def setup From 85a1710a9c3c3e6041a38213e6faf06aa8fb2917 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Wed, 15 Feb 2023 12:56:16 +0100 Subject: [PATCH 22/26] Fix so both local and online tests work --- lib/change.rb | 19 ++++++++++++++++++- lib/changelogerator.rb | 1 - lib/label.rb | 2 +- test/test_with_token.rb | 4 ++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/change.rb b/lib/change.rb index be0ed82..a4279ef 100644 --- a/lib/change.rb +++ b/lib/change.rb @@ -7,9 +7,16 @@ class Change attr_reader :labels def initialize(labels) + # Below we test if we got the full data from Octokit or + # only some fake data (label names only) from our tests. @labels = labels.map do |label| - Label.new(label) + if label.respond_to?(:name) + from_octokit(label) + else + from_str(label) + end end + @extra = {} end @@ -20,4 +27,14 @@ def []=(key, value) def meta @extra['meta'] end + + private + + def from_octokit(label) + Label.new(label.name) + end + + def from_str(label_name) + Label.new(label_name) + end end diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index 3f9664f..b07ed20 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -126,7 +126,6 @@ def self.compute_change_meta(change) meta = {} change.labels.each do |lbl| - # letter, number, text = parse_change_label(label.name) label = Label.new(lbl.name) next unless label diff --git a/lib/label.rb b/lib/label.rb index b6bf05e..65c4e31 100644 --- a/lib/label.rb +++ b/lib/label.rb @@ -28,7 +28,7 @@ def initialize(input) ### Implemented for compatibility reasons def name - puts format('%s%d', { l: @letter, n: @number }) + to_str end def to_str diff --git a/test/test_with_token.rb b/test/test_with_token.rb index aebf92e..51f6be3 100644 --- a/test/test_with_token.rb +++ b/test/test_with_token.rb @@ -3,7 +3,7 @@ require 'json' require_relative '../lib/changelogerator' require 'test/unit' -require 'pry' +# require 'pry' class TestChangelogerator < Test::Unit::TestCase def setup @@ -42,7 +42,7 @@ def test_polkadot_many_commits assert_equal(244, cl.changes.length) puts format('JSON Length: %d', j.length) assert(j.length > 1_600_000) - assert(j.length < 1_700_000) + assert(j.length < 1_750_000) end def test_cumulus_many_commits From c9052627217e7912db614b30a4720821bf59c8a4 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Wed, 15 Feb 2023 16:09:20 +0100 Subject: [PATCH 23/26] Add new flag to return the version --- bin/changelogerator | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/changelogerator b/bin/changelogerator index 7fea340..9c53e38 100755 --- a/bin/changelogerator +++ b/bin/changelogerator @@ -44,6 +44,12 @@ of the changes between 2 references on your Github project. puts opts exit end + + opts.on('-V', '--version', 'Show the version') do + gem = Gem::Specification.load('changelogerator.gemspec') + puts format('%s v%s', { v: gem.version, n: gem.name }) + exit + end end.parse! @options[:repo] = ARGV[0] From 0de7e512c6aafce348df16baf15d2433d4068260 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Wed, 15 Feb 2023 16:40:37 +0100 Subject: [PATCH 24/26] Fix packaging --- Rakefile | 3 ++- build/.gitkeep | 0 changelogerator.gemspec | 4 +++- lib/change.rb | 2 +- lib/changelogerator.rb | 4 ++-- 5 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 build/.gitkeep diff --git a/Rakefile b/Rakefile index b34baa9..37d8018 100644 --- a/Rakefile +++ b/Rakefile @@ -26,11 +26,12 @@ end # Build the gem task :build do sh 'gem build changelogerator.gemspec' + sh 'mv *.gem build/' end # Install the gem task install: :build do - sh format('gem install %s', gem_name) + sh format('gem install build/%s', gem_name) end # Publish the gem diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/changelogerator.gemspec b/changelogerator.gemspec index fe717d5..408dee1 100644 --- a/changelogerator.gemspec +++ b/changelogerator.gemspec @@ -1,11 +1,13 @@ # frozen_string_literal: true +require 'rake' + Gem::Specification.new do |s| s.name = 'changelogerator' s.version = '0.10.0' s.summary = 'Changelog generation/management' s.authors = ['Martin Pugh', 'Wilfried Kopp'] - s.files = ['lib/changelogerator.rb', 'bin/changelogerator'] + s.files = FileList['lib/**/*.rb', 'bin/changelogerator'] s.test_files = s.files.grep(%r{^(test|spec|features)/}) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } s.description = 'A utility to fetch the data required to generate a changelog based on change in Github and formatted labels.' diff --git a/lib/change.rb b/lib/change.rb index a4279ef..7fbbb40 100644 --- a/lib/change.rb +++ b/lib/change.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../lib/label' +require 'label' ### A class describe one change that can potentially have several labels class Change diff --git a/lib/changelogerator.rb b/lib/changelogerator.rb index b07ed20..62f687b 100644 --- a/lib/changelogerator.rb +++ b/lib/changelogerator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require_relative '../lib/label' -require_relative '../lib/change' +require 'label' +require 'change' # A small wrapper class for more easily generating and manipulating Github/Git # changelogs. Given two different git objects (sha, tag, whatever), it will From fb9867169c456e01ef9734b91cc0798ddbb7cffb Mon Sep 17 00:00:00 2001 From: joao-paulo-parity Date: Wed, 15 Feb 2023 12:53:09 -0300 Subject: [PATCH 25/26] disable lint --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 1868b51..27c0ec6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,6 +10,8 @@ Metrics/AbcSize: Enabled: false Metrics/ClassLength: Enabled: false +Metrics/BlockLength: + Enabled: false AllCops: TargetRubyVersion: 2.7 NewCops: enable From 9315a1c84ed13d6ff63d7109b8fac42c04d8b2a1 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Wed, 15 Feb 2023 17:35:43 +0100 Subject: [PATCH 26/26] Fix location of the gemspec --- bin/changelogerator | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/changelogerator b/bin/changelogerator index 9c53e38..74174d3 100755 --- a/bin/changelogerator +++ b/bin/changelogerator @@ -46,7 +46,8 @@ of the changes between 2 references on your Github project. end opts.on('-V', '--version', 'Show the version') do - gem = Gem::Specification.load('changelogerator.gemspec') + gemspec = "#{__dir__}/../changelogerator.gemspec" + gem = Gem::Specification.load(gemspec) puts format('%s v%s', { v: gem.version, n: gem.name }) exit end