changelogerator 0.0.1 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/changelogerator.rb +54 -22
  3. metadata +31 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 168c71f208452944f40001c41d2902d879c19b2f01e9a0a523d9d9a5b37def22
4
- data.tar.gz: bd5d94e6d95e19eab2cb6b115ad286c6f8dd7e343f72646b79f6936e454978ef
3
+ metadata.gz: 400a2661d78f9c51ff0a2c4dacc852d464a9997f29c8017df1f5d585318504ff
4
+ data.tar.gz: 1c32b784170d2eb50a1edea3aaee8e2b3d30321c5539209606913ea788ece2a3
5
5
  SHA512:
6
- metadata.gz: 6b2ab20548258e78d78ac99deed1bc509f5bbf8bbbd062b141a92f86990d6e7d8261d108bc4a51091b9998808aefbed7388eb21b4da0045d3ecea430b7508865
7
- data.tar.gz: 360a16cd39c8e224a3c0e66d6ad1d9b1d454cc1605b576acc91dd30c941ea2a23adbe4c653f70e3b02a58d73b4ba8d83891f30d5f5db20e6de2d74b6b95bc520
6
+ metadata.gz: 538053876b3075cf839b80812a108854ff54a172683bd4c155cc7f4e17d52b6036746817742c0b956744a91861af870466a9873bba11db11866bacfb2086810f
7
+ data.tar.gz: 79dd9b05c967834aa77b76ef08a83f0eccaaae33364743eb1512c2992ef49ab128dacae9c3303c85e647ed5126a62818ed66d633338eaedb889d5a424f51675c
@@ -7,7 +7,8 @@
7
7
  # on how we classify the importance of PRs in the paritytech/polkadot project.
8
8
  # Probably not tremendously useful to other projects.
9
9
  class Changelog
10
- require 'github_api'
10
+ require 'octokit'
11
+ require 'git_diff_parser'
11
12
 
12
13
  attr_accessor :changes
13
14
  attr_reader :priority
@@ -55,6 +56,15 @@ class Changelog
55
56
  end
56
57
  end
57
58
 
59
+ def self.changes_files_in_paths?(change, paths)
60
+ changed_files = GitDiffParser.parse(Octokit.get(change.diff_url)).files
61
+ paths = [paths] unless paths.is_a? Array
62
+ paths.each do |path|
63
+ return true if changed_files.find { |l| l.match path }
64
+ end
65
+ nil
66
+ end
67
+
58
68
  ## End of class methods
59
69
 
60
70
  # github_repo: 'paritytech/polkadot'
@@ -65,15 +75,13 @@ class Changelog
65
75
  # token: a Github personal access token
66
76
  # prefix: whether or not to prefix PR numbers with their repo in the changelog
67
77
  def initialize(github_repo, from, to, token: '', prefix: nil)
68
- org, repo = github_repo.split('/')
69
- @ghr = github_repo
78
+ @repo = github_repo
70
79
  @priorities = self.class.priorities
71
- @gh = Github.new do |c|
72
- c.oauth_token = token
73
- c.org = org
74
- c.repo = repo
75
- end
76
- @changes = prs_from_ids(pr_ids_from_git_diff(from, to), prefix)
80
+ @gh = Octokit::Client.new(
81
+ access_token: token
82
+ )
83
+ @prefix = prefix
84
+ @changes = prs_from_ids(pr_ids_from_git_diff(from, to))
77
85
  # add priority to each change
78
86
  @changes.map { |c| apply_priority_to_change(c) }
79
87
  end
@@ -82,6 +90,19 @@ class Changelog
82
90
  self.class.changes_with_label(@changes, label)
83
91
  end
84
92
 
93
+ def runtime_changes?
94
+ nil
95
+ end
96
+
97
+ def add(change)
98
+ changes.prepend(apply_priority_to_change(change))
99
+ end
100
+
101
+ def add_from_id(id)
102
+ pull = @gh.pull_request(@repo, id)
103
+ add(prettify_title(pull))
104
+ end
105
+
85
106
  private
86
107
 
87
108
  def apply_priority_to_change(change)
@@ -91,26 +112,37 @@ class Changelog
91
112
  change
92
113
  end
93
114
 
115
+ def prettify_title(pull)
116
+ pull[:pretty_title] = if @prefix
117
+ "#{pull[:title]} (#{@repo}##{pull[:number]})"
118
+ else
119
+ "#{pull[:title]} (##{pull[:number]})"
120
+ end
121
+ pull
122
+ end
123
+
94
124
  def pr_ids_from_git_diff(from, to)
95
- @gh.repos.commits.compare(@gh.org, @gh.repo, from, to).body.commits.map do |l|
96
- title = l.commit.message.split("\n\n").first
125
+ @gh.compare(@repo, from, to).commits.map do |c|
126
+ title = c.commit.message.split("\n\n").first
97
127
  next unless title =~ /\(#[0-9]+\)$/
98
128
 
99
129
  title.gsub(/.*#([0-9]+)\)$/, '\1')
100
- end.compact
130
+ end.compact.map(&:to_i)
101
131
  end
102
132
 
103
- def prs_from_ids(ids, prefix)
133
+ def prs_from_ids(ids)
134
+ batch_size = 100
104
135
  prs = []
105
- ids.each do |pr|
106
- pull = @gh.pull_requests.get(@gh.org, @gh.repo, pr).body
107
- pull[:pretty_title] = if prefix
108
- "#{pull[:title]} (#{@ghr}##{pull[:number]})"
109
- else
110
- "#{pull[:title]} (##{pull[:number]})"
111
- end
112
- prs.push pull
136
+ @gh.pulls(@repo, state: 'closed', per_page: batch_size)
137
+ cur_batch = @gh.last_response
138
+ until ids.empty?
139
+ prs += cur_batch.data.select { |pr| ids.include? pr.number }
140
+ ids -= cur_batch.data.map(&:number)
141
+ break if cur_batch.rels[:last].nil?
142
+
143
+ cur_batch = cur_batch.rels[:next].get
113
144
  end
114
- prs
145
+ prs.flatten
146
+ prs.map { |pr| prettify_title(pr) }
115
147
  end
116
148
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: changelogerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Pugh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git_diff_parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
13
41
  description: Simple helper class for paritytech/polkadot changelogs
14
42
  email:
15
43
  executables: []