From 06a8fe816953b0186e965138d41bda648e1c813a Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Wed, 18 Nov 2015 16:56:27 +1100 Subject: [PATCH 01/10] Add release-branch option to filter the Pull Requests by those applied on a partcular release branch --- lib/github_changelog_generator/fetcher.rb | 7 ++++++- .../generator/generator_processor.rb | 6 ++++-- lib/github_changelog_generator/parser.rb | 3 +++ lib/github_changelog_generator/task.rb | 3 ++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index fa81112..f203b8b 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -22,6 +22,7 @@ module GitHubChangelogGenerator github_options[:oauth_token] = @github_token unless @github_token.nil? github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil? + @release_branch = @options[:release_branch] unless @options[:release_branch].nil? @github = check_github_response { Github.new github_options } end @@ -123,7 +124,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow def fetch_closed_pull_requests pull_requests = [] begin - response = @github.pull_requests.list @options[:user], @options[:project], state: "closed" + if @options[:release_branch].nil? + response = @github.pull_requests.list @options[:user], @options[:project], state: "closed" + else + response = @github.pull_requests.list @options[:user], @options[:project], state: "closed", base: @options[:release_branch] + end page_i = 0 count_pages = response.count_pages response.each_page do |page| diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index e264a90..ee9d560 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -178,8 +178,10 @@ module GitHubChangelogGenerator fetched_pr = closed_pull_requests.find do |fpr| fpr.number == pr.number end - pr[:merged_at] = fetched_pr[:merged_at] - closed_pull_requests.delete(fetched_pr) + unless fetched_pr.nil? + pr[:merged_at] = fetched_pr[:merged_at] + closed_pull_requests.delete(fetched_pr) + end end pull_requests.select! do |pr| diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 46ffdef..7918c3a 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -143,6 +143,9 @@ module GitHubChangelogGenerator opts.on("--future-release [RELEASE-VERSION]", "Put the unreleased changes in the specified release number.") do |future_release| options[:future_release] = future_release end + opts.on("--release-branch [RELEASE-BRANCH]", "Limit pull requests to the release branch, such as master or release") do |release_branch| + options[:release_branch] = release_branch + end opts.on("--[no-]verbose", "Run verbosely. Default is true") do |v| options[:verbose] = v end diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index e87f7f2..0dadbf4 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -16,7 +16,8 @@ module GitHubChangelogGenerator bug_labels enhancement_labels between_tags exclude_tags since_tag max_issues github_site github_endpoint simple_list - future_release verbose release_url base ) + future_release release_branch verbose release_url + base ) OPTIONS.each do |o| attr_accessor o.to_sym From 1d1965e7fbb537fa10333dbd2d524d5e4e62486e Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Thu, 19 Nov 2015 20:14:04 +1100 Subject: [PATCH 02/10] Swap unless nil? to if --- lib/github_changelog_generator/generator/generator_processor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/generator/generator_processor.rb b/lib/github_changelog_generator/generator/generator_processor.rb index ee9d560..ae745e6 100644 --- a/lib/github_changelog_generator/generator/generator_processor.rb +++ b/lib/github_changelog_generator/generator/generator_processor.rb @@ -178,7 +178,7 @@ module GitHubChangelogGenerator fetched_pr = closed_pull_requests.find do |fpr| fpr.number == pr.number end - unless fetched_pr.nil? + if fetched_pr pr[:merged_at] = fetched_pr[:merged_at] closed_pull_requests.delete(fetched_pr) end From afbb47ecf384ca00b9e6ca3f3295132efaab4f9d Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Fri, 20 Nov 2015 22:12:06 +1100 Subject: [PATCH 03/10] Remove repeated user and repo params Used the github_options setting to add user and repo values --- lib/github_changelog_generator/fetcher.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index f203b8b..1261a78 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -15,14 +15,13 @@ module GitHubChangelogGenerator def initialize(options = {}) @options = options || {} - @user = @options[:user] - @project = @options[:project] @github_token = fetch_github_token github_options = { per_page: PER_PAGE_NUMBER } + github_options[:user] = @options[:user] + github_options[:repo] = @options[:project] github_options[:oauth_token] = @github_token unless @github_token.nil? github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil? - @release_branch = @options[:release_branch] unless @options[:release_branch].nil? @github = check_github_response { Github.new github_options } end @@ -66,7 +65,7 @@ module GitHubChangelogGenerator # @return [Array] array of tags in repo def github_fetch_tags tags = [] - response = @github.repos.tags @options[:user], @options[:project] + response = @github.repos.tags page_i = 0 count_pages = response.count_pages response.each_page do |page| @@ -125,7 +124,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow pull_requests = [] begin if @options[:release_branch].nil? - response = @github.pull_requests.list @options[:user], @options[:project], state: "closed" + response = @github.pull_requests.list @options[:user], + @options[:project], + state: "closed" else response = @github.pull_requests.list @options[:user], @options[:project], state: "closed", base: @options[:release_branch] end From 29fd202ed01a67b875ee72c86e91a438d7b1ec96 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Fri, 20 Nov 2015 22:17:10 +1100 Subject: [PATCH 04/10] Clean up user and project from all api calls --- lib/github_changelog_generator/fetcher.rb | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 1261a78..6c51ded 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -92,9 +92,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow issues = [] begin - response = @github.issues.list user: @options[:user], - repo: @options[:project], - state: "closed", + response = @github.issues.list state: "closed", filter: "all", labels: nil page_i = 0 @@ -124,11 +122,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow pull_requests = [] begin if @options[:release_branch].nil? - response = @github.pull_requests.list @options[:user], - @options[:project], - state: "closed" + response = @github.pull_requests.list state: "closed" else - response = @github.pull_requests.list @options[:user], @options[:project], state: "closed", base: @options[:release_branch] + response = @github.pull_requests.list state: "closed", + base: @options[:release_branch] end page_i = 0 count_pages = response.count_pages @@ -169,9 +166,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow issues_slice.each do |issue| threads << Thread.new do begin - response = @github.issues.events.list user: @options[:user], - repo: @options[:project], - issue_number: issue["number"] + response = @github.issues.events.list issue_number: issue["number"] issue[:events] = [] response.each_page do |page| issue[:events].concat(page) @@ -199,9 +194,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # @return [Time] time of specified tag def fetch_date_of_tag(tag) begin - commit_data = @github.git_data.commits.get @options[:user], - @options[:project], - tag["commit"]["sha"] + commit_data = @github.git_data.commits.get tag["commit"]["sha"] rescue Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow end @@ -212,7 +205,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # Fetch commit for specified event # @return [Hash] def fetch_commit(event) - @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id] + @github.git_data.commits.get event[:commit_id] end end end From 35b581240fbdc77c9f3400f2f264467c9b959245 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Sun, 3 Jan 2016 07:02:19 +1100 Subject: [PATCH 05/10] Reinstate User and Repo options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trying to use github options to hold repo and user didn’t seem to work for all commands. Reverting those changes --- lib/github_changelog_generator/fetcher.rb | 39 +++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 6c51ded..6f79615 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -16,14 +16,14 @@ module GitHubChangelogGenerator def initialize(options = {}) @options = options || {} @github_token = fetch_github_token - github_options = { per_page: PER_PAGE_NUMBER } - github_options[:user] = @options[:user] - github_options[:repo] = @options[:project] - github_options[:oauth_token] = @github_token unless @github_token.nil? - github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? - github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil? + @github_options = { per_page: PER_PAGE_NUMBER } + @github_options[:user] = @options[:user] + @github_options[:repo] = @options[:project] + @github_options[:oauth_token] = @github_token unless @github_token.nil? + @github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? + @github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil? - @github = check_github_response { Github.new github_options } + @github = check_github_response { Github.new @github_options } end # Returns GitHub token. First try to use variable, provided by --token option, @@ -65,7 +65,7 @@ module GitHubChangelogGenerator # @return [Array] array of tags in repo def github_fetch_tags tags = [] - response = @github.repos.tags + response = @github.repos.tags @options[:user], @options[:project] page_i = 0 count_pages = response.count_pages response.each_page do |page| @@ -92,7 +92,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow issues = [] begin - response = @github.issues.list state: "closed", + response = @github.issues.list user: @options[:user], + repo: @options[:project], + state: "closed", filter: "all", labels: nil page_i = 0 @@ -122,9 +124,13 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow pull_requests = [] begin if @options[:release_branch].nil? - response = @github.pull_requests.list state: "closed" + response = @github.pull_requests.list @options[:user], + @options[:project], + state: "closed" else - response = @github.pull_requests.list state: "closed", + response = @github.pull_requests.list @options[:user], + @options[:project], + state: "closed", base: @options[:release_branch] end page_i = 0 @@ -166,7 +172,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow issues_slice.each do |issue| threads << Thread.new do begin - response = @github.issues.events.list issue_number: issue["number"] + response = @github.issues.events.list user: @options[:user], + repo: @options[:project], + issue_number: issue["number"] issue[:events] = [] response.each_page do |page| issue[:events].concat(page) @@ -193,8 +201,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # @param [Hash] tag # @return [Time] time of specified tag def fetch_date_of_tag(tag) + puts @github_options begin - commit_data = @github.git_data.commits.get tag["commit"]["sha"] + commit_data = @github.git_data.commits.get @options[:user], + @options[:project], + tag["commit"]["sha"] rescue Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow end @@ -205,7 +216,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # Fetch commit for specified event # @return [Hash] def fetch_commit(event) - @github.git_data.commits.get event[:commit_id] + @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id] end end end From 5d5a48e00ee4127c9449ea25b6f687becb537626 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Sun, 3 Jan 2016 07:06:25 +1100 Subject: [PATCH 06/10] Remove debug code --- lib/github_changelog_generator/fetcher.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 6f79615..1565a01 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -201,7 +201,6 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow # @param [Hash] tag # @return [Time] time of specified tag def fetch_date_of_tag(tag) - puts @github_options begin commit_data = @github.git_data.commits.get @options[:user], @options[:project], From 12bc3550e17f762fd087fefc62b4b87c38044ee1 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Sun, 3 Jan 2016 07:11:49 +1100 Subject: [PATCH 07/10] Fix Trailing Whitespace error Rubocop was stopping this from building on Travis. --- lib/github_changelog_generator/task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/task.rb b/lib/github_changelog_generator/task.rb index 0dadbf4..035d6d5 100644 --- a/lib/github_changelog_generator/task.rb +++ b/lib/github_changelog_generator/task.rb @@ -16,7 +16,7 @@ module GitHubChangelogGenerator bug_labels enhancement_labels between_tags exclude_tags since_tag max_issues github_site github_endpoint simple_list - future_release release_branch verbose release_url + future_release release_branch verbose release_url base ) OPTIONS.each do |o| From 9832dce93cc56596ee7f3b89f6c91086ef2e20cd Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 5 Jan 2016 11:18:04 +0200 Subject: [PATCH 08/10] works! --- lib/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 4f3fe78..83dc711 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -22,7 +22,6 @@ **Merged pull requests:** -- Merged PR to Develop [\#19](https://github.com/skywinder/changelog_test/pull/19) ([skywinder](https://github.com/skywinder)) - This a PR with a lot of comments and events [\#17](https://github.com/skywinder/changelog_test/pull/17) ([skywinder](https://github.com/skywinder)) - This PR closes 14 from commit [\#15](https://github.com/skywinder/changelog_test/pull/15) ([skywinder](https://github.com/skywinder)) - This PR to close \#12 from body [\#13](https://github.com/skywinder/changelog_test/pull/13) ([skywinder](https://github.com/skywinder)) From bffe7cd9ffe669bca38385e556c5f58eb51284e6 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 5 Jan 2016 11:28:44 +0200 Subject: [PATCH 09/10] issue 20 in test repo didn't appear in change log. --- lib/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 83dc711..cf00dfb 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -22,6 +22,7 @@ **Merged pull requests:** +- Merged br \(should appear in change log also\) [\#21](https://github.com/skywinder/changelog_test/pull/21) ([skywinder](https://github.com/skywinder)) - This a PR with a lot of comments and events [\#17](https://github.com/skywinder/changelog_test/pull/17) ([skywinder](https://github.com/skywinder)) - This PR closes 14 from commit [\#15](https://github.com/skywinder/changelog_test/pull/15) ([skywinder](https://github.com/skywinder)) - This PR to close \#12 from body [\#13](https://github.com/skywinder/changelog_test/pull/13) ([skywinder](https://github.com/skywinder)) From 0e4c775ce444c7fbc4a0da129f31d84e005eec18 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Tue, 5 Jan 2016 21:28:22 +1100 Subject: [PATCH 10/10] Revert changes made for trying to use github_options Reverting other changes made that I missed. --- lib/github_changelog_generator/fetcher.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/fetcher.rb b/lib/github_changelog_generator/fetcher.rb index 1565a01..eef3e6d 100644 --- a/lib/github_changelog_generator/fetcher.rb +++ b/lib/github_changelog_generator/fetcher.rb @@ -15,10 +15,10 @@ module GitHubChangelogGenerator def initialize(options = {}) @options = options || {} + @user = @options[:user] + @project = @options[:project] @github_token = fetch_github_token @github_options = { per_page: PER_PAGE_NUMBER } - @github_options[:user] = @options[:user] - @github_options[:repo] = @options[:project] @github_options[:oauth_token] = @github_token unless @github_token.nil? @github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil? @github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil?