Class: Changelog
- Inherits:
-
Object
- Object
- Changelog
- Defined in:
- lib/changelogerator.rb
Overview
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 for filtering by label, and the importance of that change (priorities), based on how we classify the importance of PRs in the paritytech/polkadot project. Probably not tremendously useful to other projects.
Class Attribute Summary collapse
-
.priorities ⇒ Object
readonly
Returns the value of attribute priorities.
Instance Attribute Summary collapse
-
#changes ⇒ Object
Returns the value of attribute changes.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Class Method Summary collapse
- .changes_files_in_paths?(change, paths) ⇒ Boolean
- .changes_with_label(changes, label) ⇒ Object
-
.highest_priority_for_changes(changes) ⇒ Object
Return highest priority from an array of changes (NOT the actual Changelog object).
Instance Method Summary collapse
- #add(change) ⇒ Object
- #add_from_id(id) ⇒ Object
- #changes_with_label(label) ⇒ Object
-
#initialize(github_repo, from, to, token: '', prefix: nil) ⇒ Changelog
constructor
github_repo: ‘paritytech/polkadot’ from: some git ref e.g., 7e30258, v1.2.3 to: some git ref e.g., 7e30258, v1.2.3.
- #runtime_changes? ⇒ Boolean
Constructor Details
#initialize(github_repo, from, to, token: '', prefix: nil) ⇒ Changelog
github_repo: ‘paritytech/polkadot’ from: some git ref e.g., 7e30258, v1.2.3 to: some git ref e.g., 7e30258, v1.2.3
Optional named parameters: token: a Github personal access token prefix: whether or not to prefix PR numbers with their repo in the changelog
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/changelogerator.rb', line 77 def initialize(github_repo, from, to, token: '', prefix: nil) @repo = github_repo @priorities = self.class.priorities @gh = Octokit::Client.new( access_token: token ) @prefix = prefix @changes = prs_from_ids(pr_ids_from_git_diff(from, to)).map(&:to_hash) # add priority to each change @changes.map { |c| apply_priority_to_change(c) } end |
Class Attribute Details
.priorities ⇒ Object (readonly)
Returns the value of attribute priorities.
40 41 42 |
# File 'lib/changelogerator.rb', line 40 def priorities @priorities end |
Instance Attribute Details
#changes ⇒ Object
Returns the value of attribute changes.
13 14 15 |
# File 'lib/changelogerator.rb', line 13 def changes @changes end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
14 15 16 |
# File 'lib/changelogerator.rb', line 14 def priority @priority end |
Class Method Details
.changes_files_in_paths?(change, paths) ⇒ Boolean
59 60 61 62 63 64 65 66 |
# File 'lib/changelogerator.rb', line 59 def self.changes_files_in_paths?(change, paths) changed_files = GitDiffParser.parse(Octokit.get(change.diff_url)).files paths = [paths] unless paths.is_a? Array paths.each do |path| return true if changed_files.find { |l| l.match path } end nil end |
.changes_with_label(changes, label) ⇒ Object
53 54 55 56 57 |
# File 'lib/changelogerator.rb', line 53 def self.changes_with_label(changes, label) changes.select do |change| change[:labels].any? { |c| c[:name] == label } == true end end |
.highest_priority_for_changes(changes) ⇒ Object
Return highest priority from an array of changes (NOT the actual Changelog object)
45 46 47 48 49 50 51 |
# File 'lib/changelogerator.rb', line 45 def self.highest_priority_for_changes(changes) @priorities.find do |p| p[:priority] == changes.map do |change| change[:priority][:priority] end.max end end |
Instance Method Details
#add(change) ⇒ Object
97 98 99 |
# File 'lib/changelogerator.rb', line 97 def add(change) changes.prepend(prettify_title(apply_priority_to_change(change))) end |
#add_from_id(id) ⇒ Object
101 102 103 104 |
# File 'lib/changelogerator.rb', line 101 def add_from_id(id) pull = @gh.pull_request(@repo, id) add pull end |
#changes_with_label(label) ⇒ Object
89 90 91 |
# File 'lib/changelogerator.rb', line 89 def changes_with_label(label) self.class.changes_with_label(@changes, label) end |
#runtime_changes? ⇒ Boolean
93 94 95 |
# File 'lib/changelogerator.rb', line 93 def runtime_changes? nil end |