github_changelog_generator 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac3da4dd2dcab64819ab088aa8ed3acfa8ed79df
4
- data.tar.gz: d15971ed4ac80d7bd2f58c43e055a1182b35be05
3
+ metadata.gz: 708023de08c4a6c9a5a1852acf35440cd35078dd
4
+ data.tar.gz: 5668160299fea03daa27c4796b6fbdbab6c2fdf8
5
5
  SHA512:
6
- metadata.gz: 5da1acfbda00a6d208375507d3303f717f96b83d48e9d57dc844619a2bcc0ab992849b0e6d84802a69cc31c79121487bce72fc5e557070542d2c5f053a5e3dac
7
- data.tar.gz: ab9881fadfe743ed99a13d795dbdf0b6f663d695fd74c6347f673cc194bebbfae913d1f40d591ed9308e861a33fcd71c3e5d577126d958cf15e528d63b8e6885
6
+ metadata.gz: eeabccae5d7fdefb70e28c15db9acdd5844c83fe368ebe60cc19176378e65950678ace5009aa9045542689a5854169c2e27d07ee128c9d1609d845e626fc0885
7
+ data.tar.gz: 7f2628acfe95887086dcc8df2516626df59bb85788759da3e253e47406ad25cc71fe4c51d7c353ebad6b23008fb17a551c570e3ec27bd354199d04cc7b912d03
@@ -8,7 +8,7 @@ require_relative 'github_changelog_generator/parser'
8
8
 
9
9
  class ChangelogGenerator
10
10
 
11
- attr_accessor :options, :all_tags
11
+ attr_accessor :options, :all_tags, :github
12
12
 
13
13
  def initialize()
14
14
 
@@ -20,6 +20,7 @@ class ChangelogGenerator
20
20
  end
21
21
  @all_tags = self.get_all_tags
22
22
  @pull_requests = self.get_all_closed_pull_requests
23
+ @issues = self.get_all_issues
23
24
 
24
25
  @tag_times_hash = {}
25
26
  end
@@ -35,17 +36,14 @@ class ChangelogGenerator
35
36
 
36
37
 
37
38
  def get_all_closed_pull_requests
38
-
39
-
40
- issues = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
41
- json = issues.body
39
+ request = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
40
+ pull_requests = request.body
42
41
 
43
42
  if @options[:verbose]
44
43
  puts 'Receive all pull requests'
45
44
  end
46
45
 
47
- json
48
-
46
+ pull_requests
49
47
  end
50
48
 
51
49
  def compund_changelog
@@ -87,7 +85,7 @@ class ChangelogGenerator
87
85
  puts log
88
86
  end
89
87
 
90
- log += "\n\n*This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
88
+ log += "\n\n**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
91
89
 
92
90
  output_filename = "#{@options[:output]}"
93
91
  File.open(output_filename, 'w') { |file| file.write(log) }
@@ -111,19 +109,6 @@ class ChangelogGenerator
111
109
  @github.pull_requests.merged? @options[:user], @options[:project], number
112
110
  end
113
111
 
114
- def get_all_merged_pull_requests
115
- json = self.get_all_closed_pull_requests
116
- puts 'Check if the requests is merged... (it can take a while)'
117
-
118
- json.delete_if { |req|
119
- merged = self.is_megred(req[:number])
120
- if @options[:verbose]
121
- puts "##{req[:number]} #{merged ? 'merged' : 'not merged'}"
122
- end
123
- !merged
124
- }
125
- end
126
-
127
112
  def get_all_tags
128
113
 
129
114
  url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
@@ -133,7 +118,7 @@ class ChangelogGenerator
133
118
  end
134
119
 
135
120
  response = HTTParty.get(url,
136
- :headers => {'Authorization' => 'token 8587bb22f6bf125454768a4a19dbcc774ea68d48',
121
+ :headers => {'Authorization' => "token #{@options[:token]}",
137
122
  'User-Agent' => 'Changelog-Generator'})
138
123
 
139
124
  json_parse = JSON.parse(response.body)
@@ -160,15 +145,37 @@ class ChangelogGenerator
160
145
  pull_requests = Array.new(@pull_requests)
161
146
 
162
147
  pull_requests.delete_if { |req|
163
- t = Time.parse(req[:merged_at]).utc
164
- tag_is_later_since = t > since_tag_time
165
- tag_is_before_till = t <= till_tag_time
148
+ if req[:merged_at]
149
+ t = Time.parse(req[:merged_at]).utc
150
+ tag_is_later_since = t > since_tag_time
151
+ tag_is_before_till = t <= till_tag_time
152
+
153
+ in_range = (tag_is_later_since) && (tag_is_before_till)
154
+ !in_range
155
+ else
156
+ true
157
+ end
166
158
 
167
- in_range = (tag_is_later_since) && (tag_is_before_till)
168
- !in_range
169
159
  }
170
160
 
171
- self.create_log(pull_requests, till_tag_name, till_tag_time)
161
+ issues = Array.new(@issues)
162
+
163
+ issues.delete_if{ |issue|
164
+ if issue[:closed_at]
165
+ t = Time.parse(issue[:closed_at]).utc
166
+ tag_is_later_since = t > since_tag_time
167
+ tag_is_before_till = t <= till_tag_time
168
+
169
+ in_range = (tag_is_later_since) && (tag_is_before_till)
170
+ !in_range
171
+ else
172
+ true
173
+ end
174
+
175
+ }
176
+
177
+ self.create_log(pull_requests, issues, till_tag_name, till_tag_time)
178
+
172
179
  end
173
180
 
174
181
  def generate_log_before_tag(tag)
@@ -178,26 +185,81 @@ class ChangelogGenerator
178
185
  pull_requests = Array.new(@pull_requests)
179
186
 
180
187
  pull_requests.delete_if { |req|
181
- t = Time.parse(req[:closed_at]).utc
182
- t > tag_time
188
+ if req[:merged_at]
189
+ t = Time.parse(req[:merged_at]).utc
190
+ t > tag_time
191
+ else
192
+ true
193
+ end
194
+
195
+ }
196
+
197
+ issues = Array.new(@issues)
198
+
199
+ issues.delete_if{ |issue|
200
+ if issue[:closed_at]
201
+ t = Time.parse(issue[:closed_at]).utc
202
+ t > tag_time
203
+ else
204
+ true
205
+ end
183
206
  }
184
207
 
185
- self.create_log(pull_requests, tag_name, tag_time)
208
+ self.create_log(pull_requests, issues, tag_name, tag_time)
186
209
 
187
210
  end
188
211
 
189
- def create_log(pull_requests, tag_name, tag_time)
212
+ def create_log(pull_requests, issues, tag_name, tag_time)
190
213
 
214
+ # Generate tag name and link
191
215
  trimmed_tag = tag_name.tr('v', '')
192
216
  log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
193
217
 
218
+ #Generate date string:
194
219
  time_string = tag_time.strftime @options[:format]
195
220
  log += "#### #{time_string}\n"
196
221
 
197
- pull_requests.each { |dict|
198
- merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n"
199
- log += "- #{merge}"
200
- }
222
+ if @options[:pulls]
223
+ # Generate pull requests:
224
+ if pull_requests
225
+ pull_requests.each { |dict|
226
+ merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n"
227
+ log += "- #{merge}"
228
+ }
229
+ end
230
+ end
231
+
232
+ if @options[:issues]
233
+ # Generate issues:
234
+ if issues
235
+ issues.each { |dict|
236
+ is_bug = false
237
+ is_enhancement = false
238
+ dict.labels.each { |label|
239
+ if label.name == 'bug'
240
+ is_bug = true
241
+ end
242
+ if label.name == 'enhancement'
243
+ is_enhancement = true
244
+ end
245
+ }
246
+
247
+ intro = 'Closed issue'
248
+ if is_bug
249
+ intro = 'Fixed bug'
250
+ end
251
+
252
+ if is_enhancement
253
+ intro = 'Implemented enhancement'
254
+ end
255
+
256
+ merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n"
257
+ log += "- #{merge}"
258
+ }
259
+ end
260
+
261
+ end
262
+
201
263
  log
202
264
  end
203
265
 
@@ -217,8 +279,23 @@ class ChangelogGenerator
217
279
  @tag_times_hash[prev_tag['name']] = Time.parse(time_string)
218
280
  end
219
281
 
282
+ def get_all_issues
283
+ all_issues = []
284
+ @options[:labels].each { |label|
285
+ issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label
286
+ all_issues = all_issues.concat(issues.body)
287
+ }
288
+ if @options[:verbose]
289
+ puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues"
290
+ end
291
+
292
+ all_issues
293
+
294
+ end
295
+
220
296
  end
221
297
 
222
298
  if __FILE__ == $0
223
- ChangelogGenerator.new.compund_changelog
299
+ changelog_generator = ChangelogGenerator.new
300
+ changelog_generator.compund_changelog
224
301
  end
@@ -3,7 +3,7 @@ require 'optparse'
3
3
 
4
4
  class Parser
5
5
  def self.parse_options
6
- options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md'}
6
+ options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true }
7
7
 
8
8
  parser = OptionParser.new { |opts|
9
9
  opts.banner = 'Usage: changelog_generator --user username --project project_name [options]'
@@ -23,15 +23,24 @@ class Parser
23
23
  opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
24
24
  options[:verbose] = v
25
25
  end
26
- opts.on('-l', '--last-changes', 'Generate log between only last 2 tags') do |last|
26
+ opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
27
+ options[:issues] = v
28
+ end
29
+ opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
30
+ options[:pulls] = v
31
+ end
32
+ opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
27
33
  options[:last] = last
28
34
  end
29
35
  opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
30
36
  options[:format] = last
31
37
  end
32
- opts.on('-o', '--output [FORMAT]', 'Output file. Default is CHANGELOG.md') do |last|
38
+ opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
33
39
  options[:output] = last
34
40
  end
41
+ opts.on('--labels x,y,z', Array, 'List of labels. Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
42
+ options[:labels] = list
43
+ end
35
44
  }
36
45
 
37
46
  parser.parse!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_changelog_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Korolev