changelogerator 0.0.4 → 0.0.11

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 +37 -15
  3. metadata +19 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89077503cda4df3c6d813044075fa0591afa42168fd67d39f6f7eebd96517bd9
4
- data.tar.gz: 4c30ade3d3add13f89d2e58caa0e969419dbbbd3e791474c3a0312c7187e2517
3
+ metadata.gz: f6e69ae4588f7fdcf5680a5de00b6bfcb26158dbd1b8c9239bced677cb66b605
4
+ data.tar.gz: 93404021377582944fe36f609d7d9a370b6f6c599b5187b71c91c30c4f101f98
5
5
  SHA512:
6
- metadata.gz: 2d3abb976ce5d2535e124e21bf08c659cd1871b3abb2b07c7689a2a9be5caac12e1c5da8804dafc4bec39dc43a4cc500bb438cb053cd53771ddfac61c1df22a4
7
- data.tar.gz: a98c41f206459175f095530fddff50ca9aaead1e4b627d56f670550ede19c62840ad263dbbd341e4951856e26f7e60e437253ba65906672e2d25ef2245222c8c
6
+ metadata.gz: 93f92c7b4591aae298482b46aad71ccac5c7849022b4ab4d8cdc8e9c142e5facd1f730916ef7a2b37948abcf86eb9573ff7e0199fa9bb233817e4eb7d87eadf0
7
+ data.tar.gz: 68502af494c7807aefd88c36c3a625814bc6d981c1bd846806536d24f2b0b616565324b8da817a02d8b3e1a045430211b4dd330b001918ca406f7d7ab4718b0b
@@ -52,7 +52,7 @@ class Changelog
52
52
 
53
53
  def self.changes_with_label(changes, label)
54
54
  changes.select do |change|
55
- change.labels.any? { |c| c[:name] == label } == true
55
+ change[:labels].any? { |c| c[:name] == label } == true
56
56
  end
57
57
  end
58
58
 
@@ -80,7 +80,8 @@ class Changelog
80
80
  @gh = Octokit::Client.new(
81
81
  access_token: token
82
82
  )
83
- @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)
84
85
  # add priority to each change
85
86
  @changes.map { |c| apply_priority_to_change(c) }
86
87
  end
@@ -90,39 +91,60 @@ class Changelog
90
91
  end
91
92
 
92
93
  def runtime_changes?
93
-
94
94
  nil
95
95
  end
96
96
 
97
+ def add(change)
98
+ changes.prepend(prettify_title(apply_priority_to_change(change)))
99
+ end
100
+
101
+ def add_from_id(id)
102
+ pull = @gh.pull_request(@repo, id)
103
+ add pull
104
+ end
105
+
97
106
  private
98
107
 
99
108
  def apply_priority_to_change(change)
100
109
  @priorities.each do |p|
101
- 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] }
102
111
  end
112
+ # Failsafe: add lowest priority if none detected
113
+ change[:priority] ||= @priorities[0]
103
114
  change
104
115
  end
105
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
+
106
126
  def pr_ids_from_git_diff(from, to)
107
127
  @gh.compare(@repo, from, to).commits.map do |c|
108
128
  title = c.commit.message.split("\n\n").first
109
129
  next unless title =~ /\(#[0-9]+\)$/
110
130
 
111
131
  title.gsub(/.*#([0-9]+)\)$/, '\1')
112
- end.compact
132
+ end.compact.map(&:to_i)
113
133
  end
114
134
 
115
- def prs_from_ids(ids, prefix)
135
+ def prs_from_ids(ids)
136
+ batch_size = 100
116
137
  prs = []
117
- ids.each do |pr|
118
- pull = @gh.pull_request(@repo, pr)
119
- pull[:pretty_title] = if prefix
120
- "#{pull[:title]} (#{@repo}##{pull[:number]})"
121
- else
122
- "#{pull[:title]} (##{pull[:number]})"
123
- end
124
- 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
125
146
  end
126
- prs
147
+ prs.flatten
148
+ prs.map { |pr| prettify_title(pr) }
127
149
  end
128
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.4
4
+ version: 0.0.11
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: []