fixing rubocop and removing original fetcher

This commit is contained in:
Andrew Waage
2016-05-25 12:46:47 -07:00
committed by Olle Jonsson
parent 9ff27b690f
commit e89b03fe48
17 changed files with 435 additions and 654 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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