github_changelog_generator 1.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/README.md +14 -12
- data/lib/github_changelog_generator.rb +85 -72
- data/lib/github_changelog_generator/parser.rb +15 -2
- data/lib/github_changelog_generator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d90423721767edc0514ae6301fb296e3dacca8
|
4
|
+
data.tar.gz: 2ab86b4d1d8fc0ab004eafc26ffede1a6bd0e08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc94ae00a530a5202704fc94ed76b8118234d1b1a45b6a78f928470bdb49e3f6cd9d38dc6af6e2a4cc5d63cc92df4041fcf769c6febc8f306d23036d1b50381
|
7
|
+
data.tar.gz: e5a2346e221265eb2e620d2a3224f3a6a584c80d49392711b8ee3aebafdec166bdeda33d5ae19efdefd0d9ec19fafbb226784788cad82f67f4da53a2b5b5c38e
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [1.1.
|
3
|
+
## [1.1.4] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4)
|
4
4
|
#### 18/11/14
|
5
5
|
- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23)
|
6
6
|
|
7
|
-
- *Implemented enhancement:* Implement ability to retrieve GitHub token from
|
7
|
+
- *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable (to not put it to script directly) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19)
|
8
8
|
|
9
9
|
- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20)
|
10
10
|
|
data/README.md
CHANGED
@@ -27,18 +27,20 @@ As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* chan
|
|
27
27
|
Type `github_changelog_generator --help` for detailed usage.
|
28
28
|
|
29
29
|
Usage: changelog_generator [options]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
-u, --user [USER] Username of the owner of target GitHub repo
|
31
|
+
-p, --project [PROJECT] Name of project on GitHub
|
32
|
+
-t, --token [TOKEN] To make more than 50 requests this script required your OAuth token for GitHub. You can generate here: https://github.com/settings/tokens/new
|
33
|
+
-h, --help Displays Help
|
34
|
+
--[no-]verbose Run verbosely. Default is true
|
35
|
+
--[no-]issues Include closed issues to changelog. Default is true
|
36
|
+
--[no-]issues-without-labels Include closed issues without any labels to changelog. Default is true
|
37
|
+
--[no-]pull-requests Include pull-requests to changelog. Default is true
|
38
|
+
-l, --last-changes Generate log between last 2 tags only
|
39
|
+
--[no-]author Add author of pull-request in the end. Default is true
|
40
|
+
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y
|
41
|
+
-o, --output [NAME] Output file. Default is CHANGELOG.md
|
42
|
+
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement'
|
43
|
+
-v, --version Print version number
|
42
44
|
|
43
45
|
## Examples:
|
44
46
|
|
@@ -25,7 +25,11 @@ module GitHubChangelogGenerator
|
|
25
25
|
|
26
26
|
@all_tags = self.get_all_tags
|
27
27
|
@pull_requests = self.get_all_closed_pull_requests
|
28
|
-
@issues
|
28
|
+
if @options[:issues]
|
29
|
+
@issues = self.get_all_issues
|
30
|
+
else
|
31
|
+
@issues = []
|
32
|
+
end
|
29
33
|
|
30
34
|
@tag_times_hash = {}
|
31
35
|
end
|
@@ -41,6 +45,11 @@ module GitHubChangelogGenerator
|
|
41
45
|
|
42
46
|
|
43
47
|
def get_all_closed_pull_requests
|
48
|
+
|
49
|
+
if @options[:verbose]
|
50
|
+
puts 'Fetching pull requests..'
|
51
|
+
end
|
52
|
+
|
44
53
|
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
45
54
|
|
46
55
|
pull_requests = []
|
@@ -49,9 +58,39 @@ module GitHubChangelogGenerator
|
|
49
58
|
end
|
50
59
|
|
51
60
|
if @options[:verbose]
|
52
|
-
puts "
|
61
|
+
puts "Received all closed pull requests: #{pull_requests.count}"
|
53
62
|
end
|
54
63
|
|
64
|
+
unless @options[:pull_request_labels].nil?
|
65
|
+
|
66
|
+
if @options[:verbose]
|
67
|
+
puts 'Filter all pull requests by labels.'
|
68
|
+
end
|
69
|
+
|
70
|
+
filtered_pull_requests = pull_requests.select { |pull_request|
|
71
|
+
#We need issue to fetch labels
|
72
|
+
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
|
73
|
+
#compare is there any labels from @options[:labels] array
|
74
|
+
select_no_label = !issue.labels.map { |label| label.name }.any?
|
75
|
+
|
76
|
+
if @options[:verbose]
|
77
|
+
puts "Filter request \##{issue.number}."
|
78
|
+
end
|
79
|
+
|
80
|
+
if @options[:pull_request_labels].any?
|
81
|
+
select_by_label = (issue.labels.map { |label| label.name } & @options[:pull_request_labels]).any?
|
82
|
+
else
|
83
|
+
select_by_label = false
|
84
|
+
end
|
85
|
+
|
86
|
+
select_by_label | select_no_label
|
87
|
+
}
|
88
|
+
|
89
|
+
if @options[:verbose]
|
90
|
+
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
|
91
|
+
end
|
92
|
+
return filtered_pull_requests
|
93
|
+
end
|
55
94
|
pull_requests
|
56
95
|
end
|
57
96
|
|
@@ -128,11 +167,8 @@ module GitHubChangelogGenerator
|
|
128
167
|
|
129
168
|
def get_all_tags
|
130
169
|
|
131
|
-
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
|
132
|
-
|
133
170
|
if @options[:verbose]
|
134
|
-
|
135
|
-
puts "Receive tags for repo #{url}"
|
171
|
+
puts 'Fetching all tags..'
|
136
172
|
end
|
137
173
|
|
138
174
|
response = @github.repos.tags @options[:user], @options[:project]
|
@@ -167,83 +203,47 @@ module GitHubChangelogGenerator
|
|
167
203
|
|
168
204
|
|
169
205
|
def generate_log_between_tags(older_tag, newer_tag)
|
170
|
-
older_tag_time = self.get_time_of_tag(older_tag)
|
171
|
-
newer_tag_time = self.get_time_of_tag(newer_tag)
|
172
|
-
|
173
|
-
# if we mix up tags order - lits fix it!
|
174
|
-
# if older_tag_time < newer_tag_time
|
175
|
-
# older_tag, newer_tag = newer_tag, older_tag
|
176
|
-
# older_tag_time, newer_tag_time = newer_tag_time, older_tag_time
|
177
|
-
# puts "Swap tags!"
|
178
|
-
# end
|
179
206
|
|
207
|
+
newer_tag_time = self.get_time_of_tag(newer_tag)
|
180
208
|
newer_tag_name = newer_tag['name']
|
181
209
|
|
182
|
-
|
210
|
+
if older_tag.nil?
|
211
|
+
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
|
212
|
+
issues = delete_by_time(@issues, :closed_at, newer_tag_time)
|
213
|
+
else
|
214
|
+
older_tag_time = self.get_time_of_tag(older_tag)
|
215
|
+
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time)
|
216
|
+
issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
|
217
|
+
end
|
183
218
|
|
184
|
-
|
185
|
-
if req[:merged_at]
|
186
|
-
t = Time.parse(req[:merged_at]).utc
|
187
|
-
tag_is_older_of_older = t > older_tag_time
|
188
|
-
tag_is_newer_than_new = t <= newer_tag_time
|
219
|
+
self.create_log(filtered_pull_requests, issues, newer_tag_name, newer_tag_time)
|
189
220
|
|
190
|
-
|
191
|
-
!tag_not_in_range
|
192
|
-
else
|
193
|
-
true
|
194
|
-
end
|
221
|
+
end
|
195
222
|
|
196
|
-
|
223
|
+
def delete_by_time(array, hash_key, newer_tag_time, older_tag_time = nil)
|
224
|
+
array_new = Array.new(array)
|
225
|
+
array_new.delete_if { |req|
|
226
|
+
if req[hash_key]
|
227
|
+
t = Time.parse(req[hash_key]).utc
|
197
228
|
|
198
|
-
|
229
|
+
if older_tag_time.nil?
|
230
|
+
tag_is_older_of_older = false
|
231
|
+
else
|
232
|
+
tag_is_older_of_older = t > older_tag_time
|
233
|
+
end
|
199
234
|
|
200
|
-
|
201
|
-
if issue[:closed_at]
|
202
|
-
t = Time.parse(issue[:closed_at]).utc
|
203
|
-
tag_is_later_since = t > older_tag_time
|
204
|
-
tag_is_before_till = t <= newer_tag_time
|
235
|
+
tag_is_newer_than_new = t <= newer_tag_time
|
205
236
|
|
206
|
-
|
207
|
-
!
|
237
|
+
tag_not_in_range = (tag_is_older_of_older) && (tag_is_newer_than_new)
|
238
|
+
!tag_not_in_range
|
208
239
|
else
|
209
240
|
true
|
210
241
|
end
|
211
|
-
|
212
242
|
}
|
213
|
-
|
214
|
-
self.create_log(pull_requests, issues, newer_tag_name, newer_tag_time)
|
215
|
-
|
216
243
|
end
|
217
244
|
|
218
245
|
def generate_log_before_tag(tag)
|
219
|
-
|
220
|
-
tag_name = tag['name']
|
221
|
-
|
222
|
-
pull_requests = Array.new(@pull_requests)
|
223
|
-
|
224
|
-
pull_requests.delete_if { |req|
|
225
|
-
if req[:merged_at]
|
226
|
-
t = Time.parse(req[:merged_at]).utc
|
227
|
-
t > tag_time
|
228
|
-
else
|
229
|
-
true
|
230
|
-
end
|
231
|
-
|
232
|
-
}
|
233
|
-
|
234
|
-
issues = Array.new(@issues)
|
235
|
-
|
236
|
-
issues.delete_if { |issue|
|
237
|
-
if issue[:closed_at]
|
238
|
-
t = Time.parse(issue[:closed_at]).utc
|
239
|
-
t > tag_time
|
240
|
-
else
|
241
|
-
true
|
242
|
-
end
|
243
|
-
}
|
244
|
-
|
245
|
-
self.create_log(pull_requests, issues, tag_name, tag_time)
|
246
|
-
|
246
|
+
generate_log_between_tags(nil, tag)
|
247
247
|
end
|
248
248
|
|
249
249
|
def create_log(pull_requests, issues, tag_name, tag_time)
|
@@ -259,10 +259,18 @@ module GitHubChangelogGenerator
|
|
259
259
|
if @options[:pulls]
|
260
260
|
# Generate pull requests:
|
261
261
|
if pull_requests
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
262
|
+
if @options[:author]
|
263
|
+
pull_requests.each { |dict|
|
264
|
+
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url}) ([#{dict.user.login}](#{dict.user.html_url}))\n\n"
|
265
|
+
log += "- #{merge}"
|
266
|
+
}
|
267
|
+
else
|
268
|
+
pull_requests.each { |dict|
|
269
|
+
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
270
|
+
log += "- #{merge}"
|
271
|
+
}
|
272
|
+
end
|
273
|
+
|
266
274
|
end
|
267
275
|
end
|
268
276
|
|
@@ -330,6 +338,11 @@ module GitHubChangelogGenerator
|
|
330
338
|
end
|
331
339
|
|
332
340
|
def get_all_issues
|
341
|
+
|
342
|
+
if @options[:verbose]
|
343
|
+
puts 'Fetching closed issues..'
|
344
|
+
end
|
345
|
+
|
333
346
|
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
334
347
|
|
335
348
|
|
@@ -344,7 +357,7 @@ module GitHubChangelogGenerator
|
|
344
357
|
}
|
345
358
|
|
346
359
|
if @options[:verbose]
|
347
|
-
puts "
|
360
|
+
puts "Received closed issues: #{issues.count}"
|
348
361
|
end
|
349
362
|
|
350
363
|
filtered_issues = issues.select { |issue|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
|
+
require 'PP'
|
3
4
|
require_relative 'version'
|
4
5
|
|
5
6
|
module GitHubChangelogGenerator
|
6
7
|
class Parser
|
7
8
|
def self.parse_options
|
8
|
-
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* '}
|
9
|
+
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :pull_request_labels => %w(bug enhancement)}
|
9
10
|
|
10
11
|
parser = OptionParser.new { |opts|
|
11
12
|
opts.banner = 'Usage: changelog_generator [options]'
|
@@ -37,15 +38,21 @@ module GitHubChangelogGenerator
|
|
37
38
|
opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
|
38
39
|
options[:last] = last
|
39
40
|
end
|
41
|
+
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
|
42
|
+
options[:last] = author
|
43
|
+
end
|
40
44
|
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
41
45
|
options[:format] = last
|
42
46
|
end
|
43
47
|
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
44
48
|
options[:output] = last
|
45
49
|
end
|
46
|
-
opts.on('--labels x,y,z', Array, '
|
50
|
+
opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
|
47
51
|
options[:labels] = list
|
48
52
|
end
|
53
|
+
opts.on('--filter-pull-requests x,y,z', Array, 'Pull requests with that labels will be included to changelog. pull requests w\o labels will be included anyway. Default is \'bug,enhancement\'') do |list|
|
54
|
+
options[:pull_request_labels] = list
|
55
|
+
end
|
49
56
|
opts.on('-v', '--version', 'Print version number') do |v|
|
50
57
|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
51
58
|
exit
|
@@ -54,6 +61,12 @@ module GitHubChangelogGenerator
|
|
54
61
|
|
55
62
|
parser.parse!
|
56
63
|
|
64
|
+
if options[:verbose]
|
65
|
+
puts 'Input options:'
|
66
|
+
pp options
|
67
|
+
puts ''
|
68
|
+
end
|
69
|
+
|
57
70
|
#udefined case with 1 parameter:
|
58
71
|
if ARGV[0] && !ARGV[1]
|
59
72
|
puts parser.banner
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_changelog_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Korolev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|