Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78605c4
allow for multiple items with the same starting letter on meta
joao-paulo-parity Feb 10, 2023
8589e5b
remove unnecessary print
joao-paulo-parity Feb 10, 2023
6bfabdf
bump version for breaking change
joao-paulo-parity Feb 10, 2023
5cec100
fix global meta usage
joao-paulo-parity Feb 10, 2023
ec417e3
fix global meta assignments
joao-paulo-parity Feb 10, 2023
7f95009
re-add comment on compute_change_meta
joao-paulo-parity Feb 14, 2023
fcbd198
refactor $GITHUB_TOKEN checks
joao-paulo-parity Feb 14, 2023
9341786
refactor $GITHUB_TOKEN checks
joao-paulo-parity Feb 14, 2023
a066bd7
bump version to 3.0.5 and add MFA
chevdor Feb 14, 2023
1439f0d
Extract a Label class and add some tests
chevdor Feb 14, 2023
879d391
Add error handling
chevdor Feb 14, 2023
7934dbf
Avoid skipping tests that could run
chevdor Feb 14, 2023
c5942aa
set GITHUB_TOKEN=disabled for pull requests on CI
joao-paulo-parity Feb 14, 2023
a3c3567
Merge branch 'jp/meta' of github.com:paritytech/changelogerator into …
joao-paulo-parity Feb 14, 2023
1577956
fix if expression
joao-paulo-parity Feb 14, 2023
ec43e6a
fix if expression
joao-paulo-parity Feb 14, 2023
0906060
Fix readme
chevdor Feb 14, 2023
54770bd
Remove some polkadot/srtool specifics
chevdor Feb 14, 2023
140602d
update README example
joao-paulo-parity Feb 14, 2023
ecc0826
Merge branch 'jp/meta' of github.com:paritytech/changelogerator into …
joao-paulo-parity Feb 14, 2023
4cbf9d6
improve comments
joao-paulo-parity Feb 14, 2023
27d21e2
Add new test
chevdor Feb 14, 2023
d3be4b3
Refactoring for better irb support
chevdor Feb 15, 2023
85a1710
Fix so both local and online tests work
chevdor Feb 15, 2023
c905262
Add new flag to return the version
chevdor Feb 15, 2023
0de7e51
Fix packaging
chevdor Feb 15, 2023
fb98671
disable lint
joao-paulo-parity Feb 15, 2023
9315a1c
Fix location of the gemspec
chevdor Feb 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Metrics/AbcSize:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
AllCops:
TargetRubyVersion: 2.7
NewCops: enable
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.2
3.0.5
110 changes: 77 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,86 @@
# 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):

`<letter><number(s)>-<arbitrary text>`
`<letter><number(s)>[-<arbitrary text>]`

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:
```

```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": 3,
"count": 2
},
"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#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#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": { // parsed from C1-needs_audit
"value": 1,
"text": "needs_audit"
},
"C3": { // parsed from C3-urgent
"value": 3,
"text": "urgent"
},
"agg": {
"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": { "value": 8 }
},
... Github information ...
"number": 1234,
... way more information about the commit
... coming from Github
"D": {
"D2": { // parsed from D2-runtime
"value": 2,
"text": "runtime"
},
"agg": {
"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)
}
}
}
// ... other fields from the REST API
}
]
}
Expand All @@ -56,6 +89,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:
Expand All @@ -81,15 +120,20 @@ 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
```

## 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)
- run single test: `ruby -I test test/test_with_token.rb -n test_polkadot_1_commit`
- linting/formatting: `rubocop`
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions bin/changelogerator
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ of the changes between 2 references on your Github project.
puts opts
exit
end

opts.on('-V', '--version', 'Show the version') do
gemspec = "#{__dir__}/../changelogerator.gemspec"
gem = Gem::Specification.load(gemspec)
puts format('%<n>s v%<v>s', { v: gem.version, n: gem.name })
exit
end
end.parse!

@options[:repo] = ARGV[0]
Expand Down
Empty file added build/.gitkeep
Empty file.
7 changes: 5 additions & 2 deletions changelogerator.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'rake'

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']
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.'
Expand All @@ -15,4 +17,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
40 changes: 40 additions & 0 deletions lib/change.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'label'

### A class describe one change that can potentially have several labels
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|
if label.respond_to?(:name)
from_octokit(label)
else
from_str(label)
end
end

@extra = {}
end

def []=(key, value)
@extra[key] = value
end

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
Loading