From 3c33893606915247ec06f0d6872857d1e26c4afa Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 19:45:11 +0200 Subject: [PATCH 01/12] refactoring --- lib/github_changelog_generator.rb | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 3bb524e..a2c1b76 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -242,17 +242,10 @@ module GitHubChangelogGenerator newer_tag_time = self.get_time_of_tag(newer_tag) newer_tag_name = newer_tag['name'] - if older_tag.nil? - older_tag_name = nil - filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time) - filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time) - else - older_tag_time = self.get_time_of_tag(older_tag) - older_tag_name = older_tag['name'] - filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time) - filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time) - end + filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag) + filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag) + older_tag_name = older_tag.nil? ? nil : older_tag['name'] if @options[:filter_issues_by_milestone] #delete excess irrelevant issues (according milestones) @@ -294,7 +287,10 @@ module GitHubChangelogGenerator end - def delete_by_time(array, hash_key, newer_tag_time, older_tag_time = nil) + def delete_by_time(array, hash_key, newer_tag_time, older_tag = nil) + + older_tag_time = self.get_time_of_tag(older_tag) + array.select { |req| if req[hash_key] t = Time.parse(req[hash_key]).utc - 60 @@ -398,16 +394,20 @@ module GitHubChangelogGenerator log end - def get_time_of_tag(prev_tag) + def get_time_of_tag(tag_name) - if @tag_times_hash[prev_tag['name']] - return @tag_times_hash[prev_tag['name']] + if tag_name.nil? + return nil end - github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], prev_tag['commit']['sha'] + if @tag_times_hash[tag_name['name']] + return @tag_times_hash[tag_name['name']] + end + + github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], tag_name['commit']['sha'] time_string = github_git_data_commits_get['committer']['date'] Time.parse(time_string) - @tag_times_hash[prev_tag['name']] = Time.parse(time_string) + @tag_times_hash[tag_name['name']] = Time.parse(time_string) end def get_all_issues From a6897c6a868b9187acf1d76a6a98ed7394caa82d Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 20:49:32 +0200 Subject: [PATCH 02/12] add test changelog file --- .gitignore | 1 - lib/CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lib/CHANGELOG.md diff --git a/.gitignore b/.gitignore index e9ed99d..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +0,0 @@ -/lib/CHANGELOG.md diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md new file mode 100644 index 0000000..1fef52d --- /dev/null +++ b/lib/CHANGELOG.md @@ -0,0 +1,28 @@ +# Changelog + +## [1.2.0](https://github.com/runar/gittest/tree/1.2.0) +[Full Changelog](https://github.com/runar/gittest/compare/1.1.1...1.2.0) +#### 14/02/15 +- *Merged pull-request:* Add ipsum feature [\#6](https://github.com/runar/gittest/pull/6) ([runar](https://github.com/runar)) + +- *Implemented enhancement:* Enhancement issue [\#5](https://github.com/runar/gittest/issues/5) + +- *Fixed bug:* Bug issue [\#4](https://github.com/runar/gittest/issues/4) + +## [1.1.1](https://github.com/runar/gittest/tree/1.1.1) +[Full Changelog](https://github.com/runar/gittest/compare/1.1.0...1.1.1) +#### 14/02/15 +- *Fixed bug:* Text in lorem should be capitalized [\#3](https://github.com/runar/gittest/issues/3) + +## [1.1.0](https://github.com/runar/gittest/tree/1.1.0) +[Full Changelog](https://github.com/runar/gittest/compare/1.0.0...1.1.0) +#### 14/02/15 +- *Implemented enhancement:* Add lorem file [\#1](https://github.com/runar/gittest/issues/1) + +## [1.0.0](https://github.com/runar/gittest/tree/1.0.0) +#### 14/02/15 +- *Merged pull-request:* Add lorem file [\#2](https://github.com/runar/gittest/pull/2) ([runar](https://github.com/runar)) + + + +\* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 9525cdeba888d2ecceba86a7b87c816c890e0f6b Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 21:18:52 +0200 Subject: [PATCH 03/12] thread saety fix --- lib/github_changelog_generator.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index a2c1b76..53e4b6f 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -161,10 +161,15 @@ module GitHubChangelogGenerator def generate_log_for_all_tags log = '' + if @options[:verbose] + puts "Fetching tags dates.." + end + # Async fetching tags: threads = [] @all_tags.each { |tag| - threads << Thread.new { self.get_time_of_tag(tag) } + # explicit set @tag_times_hash to write data safety. + threads << Thread.new { self.get_time_of_tag(tag, @tag_times_hash) } } threads.each { |thr| thr.join } @@ -394,19 +399,18 @@ module GitHubChangelogGenerator log end - def get_time_of_tag(tag_name) + def get_time_of_tag(tag_name, tag_times_hash = @tag_times_hash) if tag_name.nil? return nil end - if @tag_times_hash[tag_name['name']] + if tag_times_hash[tag_name['name']] return @tag_times_hash[tag_name['name']] end github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], tag_name['commit']['sha'] time_string = github_git_data_commits_get['committer']['date'] - Time.parse(time_string) @tag_times_hash[tag_name['name']] = Time.parse(time_string) end From b5acd63d81fcbc7523c1f9e93930d8b569fe4b37 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 22:41:04 +0200 Subject: [PATCH 04/12] changelog --- lib/CHANGELOG.md | 139 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 122 insertions(+), 17 deletions(-) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 1fef52d..c8a886c 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,28 +1,133 @@ # Changelog -## [1.2.0](https://github.com/runar/gittest/tree/1.2.0) -[Full Changelog](https://github.com/runar/gittest/compare/1.1.1...1.2.0) -#### 14/02/15 -- *Merged pull-request:* Add ipsum feature [\#6](https://github.com/runar/gittest/pull/6) ([runar](https://github.com/runar)) +## [1.2.7](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.7) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.6...1.2.7) +#### 26/01/15 +- *Merged pull-request:* Add compare link between older version and newer version [\#46](https://github.com/skywinder/Github-Changelog-Generator/pull/46) ([sue445](https://github.com/sue445)) -- *Implemented enhancement:* Enhancement issue [\#5](https://github.com/runar/gittest/issues/5) +## [1.2.6](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.6) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.5...1.2.6) +#### 21/01/15 +- *Merged pull-request:* fix link tag format [\#45](https://github.com/skywinder/Github-Changelog-Generator/pull/45) ([sugamasao](https://github.com/sugamasao)) -- *Fixed bug:* Bug issue [\#4](https://github.com/runar/gittest/issues/4) +## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.4...1.2.5) +#### 15/01/15 +- *Merged pull-request:* PrettyPrint class is included using lowercase 'pp' [\#43](https://github.com/skywinder/Github-Changelog-Generator/pull/43) ([schwing](https://github.com/schwing)) -## [1.1.1](https://github.com/runar/gittest/tree/1.1.1) -[Full Changelog](https://github.com/runar/gittest/compare/1.1.0...1.1.1) -#### 14/02/15 -- *Fixed bug:* Text in lorem should be capitalized [\#3](https://github.com/runar/gittest/issues/3) +- *Merged pull-request:* support enterprise github via command line options [\#42](https://github.com/skywinder/Github-Changelog-Generator/pull/42) ([glenlovett](https://github.com/glenlovett)) -## [1.1.0](https://github.com/runar/gittest/tree/1.1.0) -[Full Changelog](https://github.com/runar/gittest/compare/1.0.0...1.1.0) -#### 14/02/15 -- *Implemented enhancement:* Add lorem file [\#1](https://github.com/runar/gittest/issues/1) +- *Implemented enhancement:* Use milestone to specify in which version bug was fixed [\#22](https://github.com/skywinder/Github-Changelog-Generator/issues/22) -## [1.0.0](https://github.com/runar/gittest/tree/1.0.0) -#### 14/02/15 -- *Merged pull-request:* Add lorem file [\#2](https://github.com/runar/gittest/pull/2) ([runar](https://github.com/runar)) +- *Fixed bug:* Error when trying to generate log for repo without tags [\#32](https://github.com/skywinder/Github-Changelog-Generator/issues/32) +## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.3...1.2.4) +#### 16/12/14 +- *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Implement async fetching [\#39](https://github.com/skywinder/Github-Changelog-Generator/pull/39) ([skywinder](https://github.com/skywinder)) + +- *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) + +## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3) +#### 16/12/14 +- *Implemented enhancement:* Add ability to run with one parameter instead -u -p [\#38](https://github.com/skywinder/Github-Changelog-Generator/issues/38) + +- *Implemented enhancement:* Detailed output [\#33](https://github.com/skywinder/Github-Changelog-Generator/issues/33) + +- *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) + +## [1.2.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.1...1.2.2) +#### 10/12/14 +- *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef)) + +- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) + +## [1.2.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.0...1.2.1) +#### 22/11/14 +- *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Disable default --filter-pull-requests option. [\#28](https://github.com/skywinder/Github-Changelog-Generator/pull/28) ([skywinder](https://github.com/skywinder)) + +- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) + +## [1.2.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.4...1.2.0) +#### 19/11/14 +- *Merged pull-request:* Add filter for pull-requests labels. \(option --filter-pull-requests\) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Test Pull-Request SHOULD NOT APPEAR IN LOG! [\#26](https://github.com/skywinder/Github-Changelog-Generator/pull/26) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Add ability to insert authors of pull-requests \(--\[no-\]author option\) [\#25](https://github.com/skywinder/Github-Changelog-Generator/pull/25) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Don't receive issues in case of --no-isses flag specied [\#24](https://github.com/skywinder/Github-Changelog-Generator/pull/24) ([skywinder](https://github.com/skywinder)) + +## [1.1.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.2...1.1.4) +#### 18/11/14 +- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) ([skywinder](https://github.com/skywinder)) + +- *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) + +## [1.1.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.1...1.1.2) +#### 12/11/14 +- *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17) ([skywinder](https://github.com/skywinder)) + +## [1.1.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.0...1.1.1) +#### 10/11/14 +- *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Sort issues by tags [\#14](https://github.com/skywinder/Github-Changelog-Generator/pull/14) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13) ([skywinder](https://github.com/skywinder)) + +## [1.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.1...1.1.0) +#### 10/11/14 +- *Implemented enhancement:* Detect username and project form origin [\#11](https://github.com/skywinder/Github-Changelog-Generator/issues/11) + +- *Fixed bug:* Markdown formating in the last line wrong [\#9](https://github.com/skywinder/Github-Changelog-Generator/issues/9) + +- *Fixed bug:* Bug with wrong credentials in 1.0.1 [\#12](https://github.com/skywinder/Github-Changelog-Generator/issues/12) + +## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.0...1.0.1) +#### 10/11/14 +- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder)) + +## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.1.0...1.0.0) +#### 07/11/14 +- *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3) ([skywinder](https://github.com/skywinder)) + +- *Implemented enhancement:* Implement option to specify output filename [\#4](https://github.com/skywinder/Github-Changelog-Generator/issues/4) + +- *Implemented enhancement:* Add support for fixed issues and implemented enchanments. [\#6](https://github.com/skywinder/Github-Changelog-Generator/issues/6) + +- *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5) + +## [0.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.2...0.1.0) +#### 07/11/14 +- *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) ([skywinder](https://github.com/skywinder)) + +- *Merged pull-request:* Add option \(-o --output\) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) ([skywinder](https://github.com/skywinder)) + +## [0.0.2](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2) +[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.1...0.0.2) +#### 06/11/14 +## [0.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1) +#### 06/11/14 \* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 2b603e8b26608fe78623c46dbefb610b1c3a8366 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 23:30:24 +0200 Subject: [PATCH 05/12] update changelog --- lib/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index c8a886c..e291b16 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -28,13 +28,13 @@ - *Merged pull-request:* Implement async fetching [\#39](https://github.com/skywinder/Github-Changelog-Generator/pull/39) ([skywinder](https://github.com/skywinder)) +- *Implemented enhancement:* Add ability to run with one parameter instead -u -p [\#38](https://github.com/skywinder/Github-Changelog-Generator/issues/38) + - *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) ## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3) #### 16/12/14 -- *Implemented enhancement:* Add ability to run with one parameter instead -u -p [\#38](https://github.com/skywinder/Github-Changelog-Generator/issues/38) - - *Implemented enhancement:* Detailed output [\#33](https://github.com/skywinder/Github-Changelog-Generator/issues/33) - *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) @@ -101,11 +101,11 @@ ## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.0...1.0.1) #### 10/11/14 -- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder)) - ## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0) [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.1.0...1.0.0) #### 07/11/14 +- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder)) + - *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3) ([skywinder](https://github.com/skywinder)) From 205bdfb39b01b1d4e8f1d9da03b952775225fa92 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 19:59:58 +0200 Subject: [PATCH 06/12] Revert "fix #37" This reverts commit cf4692c7b02e969c53f1f362b490f4b9b6d49c63. --- lib/github_changelog_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 53e4b6f..70bbc9c 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -298,7 +298,7 @@ module GitHubChangelogGenerator array.select { |req| if req[hash_key] - t = Time.parse(req[hash_key]).utc - 60 + t = Time.parse(req[hash_key]).utc if older_tag_time.nil? tag_in_range_old = true From c1c6d835afd45fc5a1f31ab466061d3caa00effb Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 21:16:58 +0200 Subject: [PATCH 07/12] Async fetch events --- lib/github_changelog_generator.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 70bbc9c..e6c6e09 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -460,7 +460,22 @@ module GitHubChangelogGenerator end if @options[:verbose] - puts "Filtered issues: #{filtered_issues.count}" + print "Fetching events for issues...\r" + end + + # Async fetching events: + threads = [] + + filtered_issues.each{|issue| + threads << Thread.new{ + obj = @github.issues.events.list user: @options[:user], repo: @options[:project], issue_number: issue['number'] + issue[:events] = obj.body + } + threads.each { |thr| thr.join } + } + + if @options[:verbose] + puts "Fetching events for issues: Done!" end filtered_issues From 1607407ab43cb3dc8c90cf8a204a32a647b01874 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 22:39:37 +0200 Subject: [PATCH 08/12] cm --- lib/github_changelog_generator.rb | 51 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index e6c6e09..d9ddeba 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -41,6 +41,8 @@ module GitHubChangelogGenerator @pull_requests = self.get_filtered_pull_requests if @options[:issues] @issues = self.get_all_issues + fetch_event_for_issues(@issues) + detect_actual_closed_dates else @issues = [] end @@ -48,6 +50,24 @@ module GitHubChangelogGenerator @tag_times_hash = {} end + def detect_actual_closed_dates + @issues.each{|issue| + closed_date = find_closed_date_by_commit(issue) + + } + + end + + def find_closed_date_by_commit(issue) + puts issue[:number] + unless issue['events'].nil? + issue['events'].each{|event| + puts event[:event] + } + end + 0 + end + def print_json(json) puts JSON.pretty_generate(json) end @@ -442,15 +462,12 @@ module GitHubChangelogGenerator x.pull_request == nil } - if @options[:verbose] - puts "Filtering issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}" - end - filtered_issues = issues.select { |issue| #compare is there any labels from @options[:labels] array (issue.labels.map { |label| label.name } & @options[:labels]).any? } + if @options[:add_issues_wo_labels] issues_wo_labels = issues.select { # add issues without any labels @@ -459,27 +476,37 @@ module GitHubChangelogGenerator filtered_issues.concat(issues_wo_labels) end + if @options[:verbose] - print "Fetching events for issues...\r" + puts "Filtered issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}: #{filtered_issues.count}" + end + + filtered_issues + + end + + def fetch_event_for_issues(filtered_issues) + if @options[:verbose] + print "Fetching events for issues: 0/#{filtered_issues.count}\r" end # Async fetching events: threads = [] - filtered_issues.each{|issue| - threads << Thread.new{ - obj = @github.issues.events.list user: @options[:user], repo: @options[:project], issue_number: issue['number'] + i = 0 + filtered_issues.each { |issue| + threads << Thread.new { + obj = @github.issues.events.list user: @options[:user], repo: @options[:project], issue_number: issue['number'] issue[:events] = obj.body + print "Fetching events for issues: #{i+1}/#{filtered_issues.count}\r" + i +=1 } - threads.each { |thr| thr.join } } + threads.each { |thr| thr.join } if @options[:verbose] puts "Fetching events for issues: Done!" end - - filtered_issues - end end From ca27b7c21e626593b03df901fac20d3edc0d1b09 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 23:09:07 +0200 Subject: [PATCH 09/12] put in actual date right closed date --- lib/github_changelog_generator.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index d9ddeba..87c150f 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -59,13 +59,24 @@ module GitHubChangelogGenerator end def find_closed_date_by_commit(issue) + closed_date = nil puts issue[:number] unless issue['events'].nil? - issue['events'].each{|event| - puts event[:event] + # reverse! - to find latest closed event. (event goes in date order) + issue['events'].reverse!.each{|event| + if event[:event].eql? 'closed' + if event[:commit_id].nil? + issue[:actual_date] = issue[:closed_at] + else + commit = @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id] + issue[:actual_date] = commit[:author][:date] + end + + break + end } end - 0 + closed_date end def print_json(json) From a53883ba0e40167a055eab7693714cf64f6a2ec7 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 23:21:19 +0200 Subject: [PATCH 10/12] Make it works async and fast! --- lib/github_changelog_generator.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 87c150f..720b78a 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -51,16 +51,28 @@ module GitHubChangelogGenerator end def detect_actual_closed_dates - @issues.each{|issue| - closed_date = find_closed_date_by_commit(issue) + if @options[:verbose] + print "Fetching close commit date for issues...\r" + end + + threads = [] + @issues.each{|issue| + threads << Thread.new { + find_closed_date_by_commit(issue) + } } + threads.each { |thr| thr.join } + + if @options[:verbose] + puts 'Fetching close commit date for issues: Done!' + end + + return 0 end def find_closed_date_by_commit(issue) - closed_date = nil - puts issue[:number] unless issue['events'].nil? # reverse! - to find latest closed event. (event goes in date order) issue['events'].reverse!.each{|event| @@ -71,12 +83,10 @@ module GitHubChangelogGenerator commit = @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id] issue[:actual_date] = commit[:author][:date] end - break end } end - closed_date end def print_json(json) From 615b38476c450f3020276d9513fdef880dcfe55f Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 23:25:14 +0200 Subject: [PATCH 11/12] add todo reminder --- lib/github_changelog_generator.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 720b78a..99c5c9c 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -67,9 +67,6 @@ module GitHubChangelogGenerator if @options[:verbose] puts 'Fetching close commit date for issues: Done!' end - - return 0 - end def find_closed_date_by_commit(issue) @@ -87,6 +84,7 @@ module GitHubChangelogGenerator end } end + #TODO: assert issues, that remain without 'actual_date' hash for some reason. end def print_json(json) From e8e039934160aeef9552b36c4c753d5725e4f446 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 23:29:08 +0200 Subject: [PATCH 12/12] Finaly fixed! Thanks, @runar ! :) Fix #37. --- lib/github_changelog_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 99c5c9c..49d611b 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -287,7 +287,7 @@ module GitHubChangelogGenerator newer_tag_name = newer_tag['name'] filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag) - filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag) + filtered_issues = delete_by_time(@issues, :actual_date, newer_tag_time, older_tag) older_tag_name = older_tag.nil? ? nil : older_tag['name']