fixing rubocop and removing original fetcher
This commit is contained in:
committed by
Olle Jonsson
parent
0e948fb125
commit
ef9867c122
@@ -1,13 +1,13 @@
|
||||
class Array
|
||||
def stringify_keys_deep!
|
||||
new_ar = []
|
||||
self.each do |value|
|
||||
each do |value|
|
||||
new_value = value
|
||||
if value.is_a? Hash or value.is_a? Array
|
||||
if value.is_a?(Hash) || value.is_a?(Array)
|
||||
new_value = value.stringify_keys_deep!
|
||||
end
|
||||
new_ar << new_value
|
||||
end
|
||||
new_ar
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
module GitHubChangelogGenerator
|
||||
# A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
|
||||
# (such as filtering, validating, e.t.c)
|
||||
#
|
||||
# Example:
|
||||
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
||||
|
||||
class Fetcher
|
||||
PER_PAGE_NUMBER = 30
|
||||
MAX_SIMULTANEOUS_REQUESTS = 25
|
||||
CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
|
||||
GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, change log may be " \
|
||||
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
|
||||
NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \
|
||||
"This script can make only 50 requests to GitHub API per hour without token!"
|
||||
|
||||
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[: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 }
|
||||
end
|
||||
|
||||
# Returns GitHub token. First try to use variable, provided by --token option,
|
||||
# otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable.
|
||||
#
|
||||
# @return [String]
|
||||
def fetch_github_token
|
||||
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
|
||||
|
||||
Helper.log.warn NO_TOKEN_PROVIDED unless env_var
|
||||
|
||||
env_var
|
||||
end
|
||||
|
||||
# Fetch all tags from repo
|
||||
# @return [Array] array of tags
|
||||
def get_all_tags
|
||||
print "Fetching tags...\r" if @options[:verbose]
|
||||
|
||||
check_github_response { github_fetch_tags }
|
||||
end
|
||||
|
||||
# This is wrapper with rescue block
|
||||
# @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block
|
||||
def check_github_response
|
||||
begin
|
||||
value = yield
|
||||
rescue Github::Error::Unauthorized => e
|
||||
Helper.log.error e.response_message
|
||||
abort "Error: wrong GitHub token"
|
||||
rescue Github::Error::Forbidden => e
|
||||
Helper.log.warn e.response_message
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# Fill input array with tags
|
||||
# @return [Array] array of tags in repo
|
||||
def github_fetch_tags
|
||||
tags = []
|
||||
response = @github.repos.tags @options[:user], @options[:project]
|
||||
page_i = 0
|
||||
count_pages = response.count_pages
|
||||
response.each_page do |page|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
tags.concat(page) unless page.nil?
|
||||
end
|
||||
print_empty_line
|
||||
|
||||
if tags.empty?
|
||||
Helper.log.warn "Warning: Can't find any tags in repo.\
|
||||
Make sure, that you push tags to remote repo via 'git push --tags'"
|
||||
else
|
||||
Helper.log.info "Found #{tags.count} tags"
|
||||
end
|
||||
tags
|
||||
end
|
||||
|
||||
# This method fetch all closed issues and separate them to pull requests and pure issues
|
||||
# (pull request is kind of issue in term of GitHub)
|
||||
# @return [Tuple] with (issues, pull-requests)
|
||||
def fetch_closed_issues_and_pr
|
||||
print "Fetching closed issues...\r" if @options[:verbose]
|
||||
issues = []
|
||||
|
||||
begin
|
||||
response = @github.issues.list user: @options[:user],
|
||||
repo: @options[:project],
|
||||
state: "closed",
|
||||
filter: "all",
|
||||
labels: nil
|
||||
page_i = 0
|
||||
count_pages = response.count_pages
|
||||
response.each_page do |page|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
issues.concat(page)
|
||||
break if @options[:max_issues] && issues.length >= @options[:max_issues]
|
||||
end
|
||||
print_empty_line
|
||||
Helper.log.info "Received issues: #{issues.count}"
|
||||
|
||||
rescue Github::Error::Forbidden => e
|
||||
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||
end
|
||||
|
||||
# separate arrays of issues and pull requests:
|
||||
issues.partition do |x|
|
||||
x[:pull_request].nil?
|
||||
end
|
||||
end
|
||||
|
||||
# Fetch all pull requests. We need them to detect :merged_at parameter
|
||||
# @return [Array] all pull requests
|
||||
def fetch_closed_pull_requests
|
||||
pull_requests = []
|
||||
begin
|
||||
response = if @options[:release_branch].nil?
|
||||
@github.pull_requests.list @options[:user],
|
||||
@options[:project],
|
||||
state: "closed"
|
||||
else
|
||||
@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|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
log_string = "Fetching merged dates... #{page_i}/#{count_pages * PER_PAGE_NUMBER}"
|
||||
print_in_same_line(log_string)
|
||||
pull_requests.concat(page)
|
||||
end
|
||||
print_empty_line
|
||||
rescue Github::Error::Forbidden => e
|
||||
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||
end
|
||||
|
||||
Helper.log.info "Fetching merged dates: #{pull_requests.count}"
|
||||
pull_requests
|
||||
end
|
||||
|
||||
# Print specified line on the same string
|
||||
# @param [String] log_string
|
||||
def print_in_same_line(log_string)
|
||||
print log_string + "\r"
|
||||
end
|
||||
|
||||
# Print long line with spaces on same line to clear prev message
|
||||
def print_empty_line
|
||||
print_in_same_line(" ")
|
||||
end
|
||||
|
||||
# Fetch event for all issues and add them to events
|
||||
# @param [Array] issues
|
||||
# @return [Void]
|
||||
def fetch_events_async(issues)
|
||||
i = 0
|
||||
threads = []
|
||||
issues.each_slice(MAX_SIMULTANEOUS_REQUESTS) do |issues_slice|
|
||||
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"]
|
||||
issue['events'] = []
|
||||
response.each_page do |page|
|
||||
issue['events'].concat(page)
|
||||
end
|
||||
rescue Github::Error::Forbidden => e
|
||||
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||
end
|
||||
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
threads.each(&:join)
|
||||
threads = []
|
||||
end
|
||||
|
||||
# to clear line from prev print
|
||||
print_empty_line
|
||||
|
||||
Helper.log.info "Fetching events for issues and PR: #{i}"
|
||||
end
|
||||
|
||||
# Fetch tag time from repo
|
||||
#
|
||||
# @param [Hash] tag
|
||||
# @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"]
|
||||
rescue Github::Error::Forbidden => e
|
||||
Helper.log.warn e.error_messages.map { |m| m[:message] }.join(", ")
|
||||
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG
|
||||
end
|
||||
time_string = commit_data["committer"]["date"]
|
||||
Time.parse(time_string)
|
||||
end
|
||||
|
||||
# Fetch commit for specified event
|
||||
# @return [Hash]
|
||||
def fetch_commit(event)
|
||||
@github.git_data.commits.get @options[:user], @options[:project], event['commit_id']
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
require_relative "../fetcher"
|
||||
require_relative "../octo_fetcher"
|
||||
require_relative "generator_generation"
|
||||
require_relative "generator_fetcher"
|
||||
@@ -107,13 +106,13 @@ module GitHubChangelogGenerator
|
||||
|
||||
issues.each do |dict|
|
||||
added = false
|
||||
dict['labels'].each do |label|
|
||||
if @options[:bug_labels].include? label['name']
|
||||
dict["labels"].each do |label|
|
||||
if @options[:bug_labels].include? label["name"]
|
||||
bugs_a.push dict
|
||||
added = true
|
||||
next
|
||||
end
|
||||
if @options[:enhancement_labels].include? label['name']
|
||||
if @options[:enhancement_labels].include? label["name"]
|
||||
enhancement_a.push dict
|
||||
added = true
|
||||
next
|
||||
@@ -124,13 +123,13 @@ module GitHubChangelogGenerator
|
||||
|
||||
added_pull_requests = []
|
||||
pull_requests.each do |pr|
|
||||
pr['labels'].each do |label|
|
||||
if @options[:bug_labels].include? label['name']
|
||||
pr["labels"].each do |label|
|
||||
if @options[:bug_labels].include? label["name"]
|
||||
bugs_a.push pr
|
||||
added_pull_requests.push pr
|
||||
next
|
||||
end
|
||||
if @options[:enhancement_labels].include? label['name']
|
||||
if @options[:enhancement_labels].include? label["name"]
|
||||
enhancement_a.push pr
|
||||
added_pull_requests.push pr
|
||||
next
|
||||
|
||||
@@ -50,12 +50,12 @@ module GitHubChangelogGenerator
|
||||
# Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit.
|
||||
# @param [Hash] issue
|
||||
def find_closed_date_by_commit(issue)
|
||||
unless issue['events'].nil?
|
||||
unless issue["events"].nil?
|
||||
# if it's PR -> then find "merged event", in case of usual issue -> fond closed date
|
||||
compare_string = issue['merged_at'].nil? ? "closed" : "merged"
|
||||
compare_string = issue["merged_at"].nil? ? "closed" : "merged"
|
||||
# reverse! - to find latest closed event. (event goes in date order)
|
||||
issue['events'].reverse!.each do |event|
|
||||
if event['event'].eql? compare_string
|
||||
issue["events"].reverse!.each do |event|
|
||||
if event["event"].eql? compare_string
|
||||
set_date_from_event(event, issue)
|
||||
break
|
||||
end
|
||||
@@ -69,16 +69,17 @@ module GitHubChangelogGenerator
|
||||
# @param [Hash] event
|
||||
# @param [Hash] issue
|
||||
def set_date_from_event(event, issue)
|
||||
if event['commit_id'].nil?
|
||||
issue['actual_date'] = issue['closed_at']
|
||||
if event["commit_id"].nil?
|
||||
issue["actual_date"] = issue["closed_at"]
|
||||
else
|
||||
begin
|
||||
commit = @fetcher.fetch_commit(event)
|
||||
issue['actual_date'] = commit['commit']['author']['date']
|
||||
issue["actual_date"] = commit["commit"]["author"]["date"]
|
||||
|
||||
# issue['actual_date'] = commit['author']['date']
|
||||
rescue
|
||||
puts "Warning: Can't fetch commit #{event['commit_id']}. It is probably referenced from another repo."
|
||||
issue['actual_date'] = issue['closed_at']
|
||||
issue["actual_date"] = issue["closed_at"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,9 +119,8 @@ module GitHubChangelogGenerator
|
||||
#
|
||||
# @return [Array] filtered issues and pull requests
|
||||
def filter_issues_for_tags(newer_tag, older_tag)
|
||||
|
||||
filtered_pull_requests = delete_by_time(@pull_requests, 'actual_date', older_tag, newer_tag)
|
||||
filtered_issues = delete_by_time(@issues, 'actual_date', older_tag, newer_tag)
|
||||
filtered_pull_requests = delete_by_time(@pull_requests, "actual_date", older_tag, newer_tag)
|
||||
filtered_issues = delete_by_time(@issues, "actual_date", older_tag, newer_tag)
|
||||
|
||||
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]
|
||||
|
||||
@@ -167,7 +166,7 @@ module GitHubChangelogGenerator
|
||||
# @param [Hash] issue Fetched issue from GitHub
|
||||
# @return [String] Markdown-formatted single issue
|
||||
def get_string_for_issue(issue)
|
||||
encapsulated_title = encapsulate_string issue['title']
|
||||
encapsulated_title = encapsulate_string issue["title"]
|
||||
|
||||
title_with_number = "#{encapsulated_title} [\\##{issue['number']}](#{issue['html_url']})"
|
||||
issue_line_with_user(title_with_number, issue)
|
||||
@@ -178,13 +177,13 @@ module GitHubChangelogGenerator
|
||||
def issue_line_with_user(line, issue)
|
||||
return line if !@options[:author] || issue.pull_request.nil?
|
||||
|
||||
user = issue['user']
|
||||
user = issue["user"]
|
||||
return "#{line} ({Null user})" unless user
|
||||
|
||||
if @options[:usernames_as_github_logins]
|
||||
"#{line} (@#{user['login']})"
|
||||
"#{line} (@#{user["login"]})"
|
||||
else
|
||||
"#{line} ([#{user['login']}](#{user['html_url']}))"
|
||||
"#{line} ([#{user["login"]}](#{user["html_url"]}))"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module GitHubChangelogGenerator
|
||||
return issues if !@options[:exclude_labels] || @options[:exclude_labels].empty?
|
||||
|
||||
issues.reject do |issue|
|
||||
labels = issue['labels'].map{|l| l['name'] }
|
||||
labels = issue["labels"].map { |l| l["name"] }
|
||||
(labels & @options[:exclude_labels]).any?
|
||||
end
|
||||
end
|
||||
@@ -32,18 +32,18 @@ module GitHubChangelogGenerator
|
||||
# @return [Array] issues with milestone #tag_name
|
||||
def find_issues_to_add(all_issues, tag_name)
|
||||
all_issues.select do |issue|
|
||||
if issue['milestone'].nil?
|
||||
if issue["milestone"].nil?
|
||||
false
|
||||
else
|
||||
# check, that this milestone in tag list:
|
||||
milestone_is_tag = @filtered_tags.find do |tag|
|
||||
tag['name'] == issue['milestone']['title']
|
||||
tag["name"] == issue["milestone"]["title"]
|
||||
end
|
||||
|
||||
if milestone_is_tag.nil?
|
||||
false
|
||||
else
|
||||
issue['milestone']['title'] == tag_name
|
||||
issue["milestone"]["title"] == tag_name
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -53,11 +53,11 @@ module GitHubChangelogGenerator
|
||||
def remove_issues_in_milestones(filtered_issues)
|
||||
filtered_issues.select! do |issue|
|
||||
# leave issues without milestones
|
||||
if issue['milestone'].nil?
|
||||
if issue["milestone"].nil?
|
||||
true
|
||||
else
|
||||
# check, that this milestone in tag list:
|
||||
@filtered_tags.find { |tag| tag['name'] == issue['milestone']['title'] }.nil?
|
||||
@filtered_tags.find { |tag| tag["name"] == issue["milestone"]["title"] }.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -68,7 +68,7 @@ module GitHubChangelogGenerator
|
||||
# @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag
|
||||
# @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section
|
||||
# @return [Array] filtered issues
|
||||
def delete_by_time(issues, hash_key = 'actual_date', older_tag = nil, newer_tag = nil)
|
||||
def delete_by_time(issues, hash_key = "actual_date", older_tag = nil, newer_tag = nil)
|
||||
# in case if not tags specified - return unchanged array
|
||||
return issues if older_tag.nil? && newer_tag.nil?
|
||||
|
||||
@@ -123,7 +123,7 @@ module GitHubChangelogGenerator
|
||||
def filter_wo_labels(issues)
|
||||
if @options[:add_issues_wo_labels]
|
||||
issues_wo_labels = issues.select do |issue|
|
||||
!issue['labels'].map{|l| l['name'] }.any?
|
||||
!issue["labels"].map { |l| l["name"] }.any?
|
||||
end
|
||||
return issues_wo_labels
|
||||
end
|
||||
@@ -135,7 +135,7 @@ module GitHubChangelogGenerator
|
||||
issues
|
||||
else
|
||||
issues.select do |issue|
|
||||
labels = issue['labels'].map { |l| l['name'] } & @options[:include_labels]
|
||||
labels = issue["labels"].map { |l| l["name"] } & @options[:include_labels]
|
||||
labels.any?
|
||||
end
|
||||
end
|
||||
@@ -179,16 +179,16 @@ module GitHubChangelogGenerator
|
||||
|
||||
pull_requests.each do |pr|
|
||||
fetched_pr = closed_pull_requests.find do |fpr|
|
||||
fpr['number'] == pr['number']
|
||||
fpr["number"] == pr["number"]
|
||||
end
|
||||
if fetched_pr
|
||||
pr['merged_at'] = fetched_pr['merged_at']
|
||||
pr["merged_at"] = fetched_pr["merged_at"]
|
||||
closed_pull_requests.delete(fetched_pr)
|
||||
end
|
||||
end
|
||||
|
||||
pull_requests.select! do |pr|
|
||||
!pr['merged_at'].nil?
|
||||
!pr["merged_at"].nil?
|
||||
end
|
||||
|
||||
pull_requests
|
||||
|
||||
@@ -80,8 +80,8 @@ module GitHubChangelogGenerator
|
||||
filtered_tags = all_tags
|
||||
tag = detect_since_tag
|
||||
if tag
|
||||
if all_tags.map(&:name).include? tag
|
||||
idx = all_tags.index { |t| t.name == tag }
|
||||
if all_tags.map { |t| t["name"] }.include? tag
|
||||
idx = all_tags.index { |t| t["name"] == tag }
|
||||
filtered_tags = if idx > 0
|
||||
all_tags[0..idx - 1]
|
||||
else
|
||||
@@ -100,8 +100,8 @@ module GitHubChangelogGenerator
|
||||
filtered_tags = all_tags
|
||||
tag = @options[:due_tag]
|
||||
if tag
|
||||
if all_tags.any? && all_tags.map(&:name).include?(tag)
|
||||
idx = all_tags.index { |t| t.name == tag }
|
||||
if all_tags.any? && all_tags.map { |t| t["name"] }.include?(tag)
|
||||
idx = all_tags.index { |t| t["name"] == tag }
|
||||
last_index = all_tags.count - 1
|
||||
filtered_tags = if idx > 0 && idx < last_index
|
||||
all_tags[idx + 1..last_index]
|
||||
@@ -121,11 +121,11 @@ module GitHubChangelogGenerator
|
||||
filtered_tags = all_tags
|
||||
if @options[:between_tags]
|
||||
@options[:between_tags].each do |tag|
|
||||
unless all_tags.map(&:name).include? tag
|
||||
unless all_tags.map { |t| t["name"] }.include? tag
|
||||
Helper.log.warn "Warning: can't find tag #{tag}, specified with --between-tags option."
|
||||
end
|
||||
end
|
||||
filtered_tags = all_tags.select { |tag| @options[:between_tags].include? tag.name }
|
||||
filtered_tags = all_tags.select { |tag| @options[:between_tags].include? tag["name"] }
|
||||
end
|
||||
filtered_tags
|
||||
end
|
||||
@@ -158,18 +158,18 @@ module GitHubChangelogGenerator
|
||||
|
||||
def filter_tags_with_regex(all_tags, regex)
|
||||
warn_if_nonmatching_regex(all_tags)
|
||||
all_tags.reject { |tag| regex =~ tag.name }
|
||||
all_tags.reject { |tag| regex =~ tag["name"] }
|
||||
end
|
||||
|
||||
def filter_exact_tags(all_tags)
|
||||
@options[:exclude_tags].each do |tag|
|
||||
warn_if_tag_not_found(all_tags, tag)
|
||||
end
|
||||
all_tags.reject { |tag| @options[:exclude_tags].include? tag.name }
|
||||
all_tags.reject { |tag| @options[:exclude_tags].include? tag["name"] }
|
||||
end
|
||||
|
||||
def warn_if_nonmatching_regex(all_tags)
|
||||
unless all_tags.map(&:name).any? { |t| @options[:exclude_tags] =~ t }
|
||||
unless all_tags.map { |t| t["name"] }.any? { |t| @options[:exclude_tags] =~ t }
|
||||
Helper.log.warn "Warning: unable to reject any tag, using regex "\
|
||||
"#{@options[:exclude_tags].inspect} in --exclude-tags "\
|
||||
"option."
|
||||
@@ -177,7 +177,7 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
def warn_if_tag_not_found(all_tags, tag)
|
||||
unless all_tags.map(&:name).include? tag
|
||||
unless all_tags.map { |t| t["name"] }.include? tag
|
||||
Helper.log.warn "Warning: can't find tag #{tag}, specified with --exclude-tags option."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,14 +2,14 @@ class Hash
|
||||
def stringify_keys_deep!
|
||||
new_hash = {}
|
||||
keys.each do |k|
|
||||
ks = k.respond_to?(:to_s) ? k.to_s : k
|
||||
if values_at(k).first.kind_of? Hash or values_at(k).first.kind_of? Array
|
||||
new_hash[ks] = values_at(k).first.send(:stringify_keys_deep!)
|
||||
else
|
||||
new_hash[ks] = values_at(k).first
|
||||
end
|
||||
ks = k.respond_to?(:to_s) ? k.to_s : k
|
||||
new_hash[ks] = if values_at(k).first.is_a?(Hash) || values_at(k).first.is_a?(Array)
|
||||
values_at(k).first.send(:stringify_keys_deep!)
|
||||
else
|
||||
values_at(k).first
|
||||
end
|
||||
end
|
||||
|
||||
new_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,7 +28,7 @@ module GitHubChangelogGenerator
|
||||
|
||||
@github_token = fetch_github_token
|
||||
|
||||
@request_options = { :per_page => PER_PAGE_NUMBER }
|
||||
@request_options = { per_page: PER_PAGE_NUMBER }
|
||||
@github_options = {}
|
||||
@github_options[:access_token] = @github_token unless @github_token.nil?
|
||||
@github_options[:api_endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
|
||||
@@ -63,7 +63,6 @@ module GitHubChangelogGenerator
|
||||
check_github_response { github_fetch_tags }
|
||||
end
|
||||
|
||||
|
||||
# Returns the number of pages for a API call
|
||||
#
|
||||
# @return [Integer] number of pages for this API call in total
|
||||
@@ -75,23 +74,22 @@ module GitHubChangelogGenerator
|
||||
|
||||
last_response = client.last_response
|
||||
|
||||
if last_pg = last_response.rels[:last]
|
||||
parse_url_for_vars(last_pg.href)['page'].to_i
|
||||
if (last_pg = last_response.rels[:last])
|
||||
parse_url_for_vars(last_pg.href)["page"].to_i
|
||||
else
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Fill input array with tags
|
||||
#
|
||||
# @return [Array <Hash>] array of tags in repo
|
||||
def github_fetch_tags
|
||||
tags = []
|
||||
page_i = 0
|
||||
count_pages = calculate_pages(@client, 'tags', {})
|
||||
count_pages = calculate_pages(@client, "tags", {})
|
||||
|
||||
iterate_pages(@client, 'tags', {}) do |new_tags|
|
||||
iterate_pages(@client, "tags", {}) do |new_tags|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
tags.concat(new_tags)
|
||||
@@ -105,7 +103,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
Helper.log.info "Found #{tags.count} tags"
|
||||
end
|
||||
# tags are a Sawyer::Resource. Convert to hash
|
||||
tags = tags.map{|h| h.to_hash.stringify_keys_deep! }
|
||||
tags = tags.map { |h| h.to_hash.stringify_keys_deep! }
|
||||
tags
|
||||
end
|
||||
|
||||
@@ -117,16 +115,16 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
print "Fetching closed issues...\r" if @options[:verbose]
|
||||
issues = []
|
||||
options = {
|
||||
:state => "closed",
|
||||
:filter => "all",
|
||||
:labels => nil,
|
||||
state: "closed",
|
||||
filter: "all",
|
||||
labels: nil
|
||||
}
|
||||
options[:since] = @since unless @since.nil?
|
||||
|
||||
page_i = 0
|
||||
count_pages = calculate_pages(@client, 'issues', options)
|
||||
count_pages = calculate_pages(@client, "issues", options)
|
||||
|
||||
iterate_pages(@client, 'issues', options) do |new_issues|
|
||||
iterate_pages(@client, "issues", options) do |new_issues|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
|
||||
issues.concat(new_issues)
|
||||
@@ -135,11 +133,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
print_empty_line
|
||||
Helper.log.info "Received issues: #{issues.count}"
|
||||
|
||||
issues = issues.map{|h| h.to_hash.stringify_keys_deep! }
|
||||
issues = issues.map { |h| h.to_hash.stringify_keys_deep! }
|
||||
|
||||
# separate arrays of issues and pull requests:
|
||||
issues.partition do |x|
|
||||
x['pull_request'].nil?
|
||||
x["pull_request"].nil?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -148,17 +146,17 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
# @return [Array <Hash>] all pull requests
|
||||
def fetch_closed_pull_requests
|
||||
pull_requests = []
|
||||
options = { :state => 'closed' }
|
||||
options = { state: "closed" }
|
||||
|
||||
if !@options[:release_branch].nil?
|
||||
unless @options[:release_branch].nil?
|
||||
options[:base] = @options[:release_branch]
|
||||
end
|
||||
|
||||
page_i = 0
|
||||
count_pages = calculate_pages(@client, 'pull_requests', options)
|
||||
count_pages = calculate_pages(@client, "pull_requests", options)
|
||||
|
||||
iterate_pages(@client, 'pull_requests', options) do |new_pr|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
iterate_pages(@client, "pull_requests", options) do |new_pr|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
log_string = "Fetching merged dates... #{page_i}/#{count_pages * PER_PAGE_NUMBER}"
|
||||
print_in_same_line(log_string)
|
||||
pull_requests.concat(new_pr)
|
||||
@@ -166,7 +164,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
print_empty_line
|
||||
|
||||
Helper.log.info "Pull Request count: #{pull_requests.count}"
|
||||
pull_requests = pull_requests.map{|h| h.to_hash.stringify_keys_deep! }
|
||||
pull_requests = pull_requests.map { |h| h.to_hash.stringify_keys_deep! }
|
||||
pull_requests
|
||||
end
|
||||
|
||||
@@ -181,11 +179,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
issues.each_slice(MAX_THREAD_NUMBER) do |issues_slice|
|
||||
issues_slice.each do |issue|
|
||||
threads << Thread.new do
|
||||
issue['events'] = []
|
||||
iterate_pages(@client, 'issue_events', issue['number'], {}) do |new_event|
|
||||
issue['events'].concat(new_event)
|
||||
issue["events"] = []
|
||||
iterate_pages(@client, "issue_events", issue["number"], {}) do |new_event|
|
||||
issue["events"].concat(new_event)
|
||||
end
|
||||
issue['events'] = issue['events'].map{|h| h.to_hash.stringify_keys_deep! }
|
||||
issue["events"] = issue["events"].map { |h| h.to_hash.stringify_keys_deep! }
|
||||
print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
|
||||
i += 1
|
||||
end
|
||||
@@ -205,10 +203,10 @@ 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)
|
||||
commit_data = check_github_response { @client.commit(user_project, tag['commit']['sha']) }
|
||||
commit_data = check_github_response { @client.commit(user_project, tag["commit"]["sha"]) }
|
||||
commit_data = commit_data.to_hash.stringify_keys_deep!
|
||||
|
||||
commit_data['commit']['committer']['date']
|
||||
commit_data["commit"]["committer"]["date"]
|
||||
end
|
||||
|
||||
# Fetch commit for specified event
|
||||
@@ -216,8 +214,9 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
# @return [Hash]
|
||||
def fetch_commit(event)
|
||||
check_github_response do
|
||||
commit = @client.commit(user_project, event['commit_id'])
|
||||
commit = @client.commit(user_project, event["commit_id"])
|
||||
commit = commit.to_hash.stringify_keys_deep!
|
||||
commit
|
||||
end
|
||||
end
|
||||
|
||||
@@ -229,7 +228,7 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
# @param [Octokit::Client] client
|
||||
# @param [String] method (eg. 'tags')
|
||||
# @return [Integer] total number of pages
|
||||
def iterate_pages(client, method, *args, &block)
|
||||
def iterate_pages(client, method, *args)
|
||||
if args.size == 1 && args.first.is_a?(Hash)
|
||||
request_options = args.delete_at(0)
|
||||
elsif args.size > 1 && args.last.is_a?(Hash)
|
||||
@@ -247,8 +246,8 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
|
||||
yield last_response.data
|
||||
|
||||
while !(next_one = last_response.rels[:next]).nil?
|
||||
pages +=1
|
||||
until (next_one = last_response.rels[:next]).nil?
|
||||
pages += 1
|
||||
|
||||
last_response = check_github_response { next_one.get }
|
||||
yield last_response.data
|
||||
@@ -307,12 +306,11 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
|
||||
# @param [String] uri eg. https://api.github.com/repositories/43914960/tags?page=37&foo=1
|
||||
# @return [Hash] of all GET variables. eg. { 'page' => 37, 'foo' => 1 }
|
||||
def parse_url_for_vars(uri)
|
||||
URI(uri).query.split("&").inject({}) do |params, get_var|
|
||||
k,v = get_var.split("=")
|
||||
URI(uri).query.split("&").each_with_object({}) do |params, get_var|
|
||||
k, v = get_var.split("=")
|
||||
params[k] = v
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user