changelogerator 0.0.3 → 0.0.10

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 +51 -14
  3. metadata +19 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b916cdb658f760af9794c4f947c54839f8b19b596b3a0fe9e20f674c8898f31d
4
- data.tar.gz: efa45a9492704d76197ccb4b3d15d227a6c4a01d35bfe8fe6ff81b7b84049532
3
+ metadata.gz: 6061881a5234a97b447b594f942e78a3bd4fcad68ed910265d12ed711eda8b64
4
+ data.tar.gz: f575aa00e5d4abbab3adaf529e309889f5261ced0e40da74186ab144563dcbe6
5
5
  SHA512:
6
- metadata.gz: 298138ad4d9d52615de65931e3a96d7b5aee928bc71732a7142dfe2b8d97008d0dc090c2ef9ce81060b375288e3c5d9a4a3a375dafbca0b056d4b0b525ddcdc7
7
- data.tar.gz: 70897f7bf61f7721a9d7097479e7c39c4be18c1781d970908b0620aadb2bf106d31ba81d0bc8e0e0eed988e38e0fda49a7f6549c38d511d0f8dd5e48db2fc93f
6
+ metadata.gz: d3f92505939fb6858ad0ce76f1e037973c07f7177034b3fc96c0189c55fcc4a109c34427306fffb7d8ebcb816551517065c0e3bc12651dc990aafacd0280b579
7
+ data.tar.gz: 6fae7c8942409d782ff606d67b3963a7869513529fd7f61caea8f7198f0c416b02196e0d08865b602e8d9c3c2ed8a35eb3d1cfe57359d147d7a147f318446efc
@@ -8,6 +8,7 @@
8
8
  # Probably not tremendously useful to other projects.
9
9
  class Changelog
10
10
  require 'octokit'
11
+ require 'git_diff_parser'
11
12
 
12
13
  attr_accessor :changes
13
14
  attr_reader :priority
@@ -51,10 +52,19 @@ class Changelog
51
52
 
52
53
  def self.changes_with_label(changes, label)
53
54
  changes.select do |change|
54
- change.labels.any? { |c| c[:name] == label } == true
55
+ change[:labels].any? { |c| c[:name] == label } == true
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'
@@ -70,7 +80,8 @@ class Changelog
70
80
  @gh = Octokit::Client.new(
71
81
  access_token: token
72
82
  )
73
- @changes = prs_from_ids(pr_ids_from_git_diff(from, to), prefix)
83
+ @prefix = prefix
84
+ @changes = prs_from_ids(pr_ids_from_git_diff(from, to)).map(&:to_hash)
74
85
  # add priority to each change
75
86
  @changes.map { |c| apply_priority_to_change(c) }
76
87
  end
@@ -79,35 +90,61 @@ class Changelog
79
90
  self.class.changes_with_label(@changes, label)
80
91
  end
81
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
+
82
106
  private
83
107
 
84
108
  def apply_priority_to_change(change)
85
109
  @priorities.each do |p|
86
- change[:priority] = p if change.labels.any? { |l| l[:name] == p[:label] }
110
+ change[:priority] = p if change[:labels].any? { |l| l[:name] == p[:label] }
87
111
  end
112
+ # Failsafe: add lowest priority if none detected
113
+ change[:priority] ||= @priorities[0]
88
114
  change
89
115
  end
90
116
 
117
+ def prettify_title(pull)
118
+ pull[:pretty_title] = if @prefix
119
+ "#{pull[:title]} (#{@repo}##{pull[:number]})"
120
+ else
121
+ "#{pull[:title]} (##{pull[:number]})"
122
+ end
123
+ pull
124
+ end
125
+
91
126
  def pr_ids_from_git_diff(from, to)
92
127
  @gh.compare(@repo, from, to).commits.map do |c|
93
128
  title = c.commit.message.split("\n\n").first
94
129
  next unless title =~ /\(#[0-9]+\)$/
95
130
 
96
131
  title.gsub(/.*#([0-9]+)\)$/, '\1')
97
- end.compact
132
+ end.compact.map(&:to_i)
98
133
  end
99
134
 
100
- def prs_from_ids(ids, prefix)
135
+ def prs_from_ids(ids)
136
+ batch_size = 100
101
137
  prs = []
102
- ids.each do |pr|
103
- pull = @gh.pull_request(@repo, pr)
104
- pull[:pretty_title] = if prefix
105
- "#{pull[:title]} (#{@repo}##{pull[:number]})"
106
- else
107
- "#{pull[:title]} (##{pull[:number]})"
108
- end
109
- prs.push pull
138
+ @gh.pulls(@repo, state: 'closed', per_page: batch_size)
139
+ cur_batch = @gh.last_response
140
+ until ids.empty?
141
+ prs += cur_batch.data.select { |pr| ids.include? pr.number }
142
+ ids -= cur_batch.data.map(&:number)
143
+ break if cur_batch.rels[:last].nil?
144
+
145
+ cur_batch = cur_batch.rels[:next].get
110
146
  end
111
- prs
147
+ prs.flatten
148
+ prs.map { |pr| prettify_title(pr) }
112
149
  end
113
150
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: changelogerator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.10
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-09-02 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: github_api
14
+ name: git_diff_parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.19'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.19'
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'
27
41
  description: Simple helper class for paritytech/polkadot changelogs
28
42
  email:
29
43
  executables: []