Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #220

Merged
merged 14 commits into from Mar 27, 2015
2 changes: 1 addition & 1 deletion bin/github_changelog_generator
@@ -1,4 +1,4 @@
#! /usr/bin/env ruby

require_relative '../lib/github_changelog_generator'
GitHubChangelogGenerator::ChangelogGenerator.new.compund_changelog
GitHubChangelogGenerator::ChangelogGenerator.new.compound_changelog
58 changes: 22 additions & 36 deletions lib/github_changelog_generator.rb
Expand Up @@ -15,8 +15,8 @@ class ChangelogGenerator
attr_accessor :options, :all_tags, :github

PER_PAGE_NUMBER = 30
GH_RATE_LIMIT_EXCEEDED_MSG = 'Warning: GitHub API rate limit exceed (5000 per hour), change log may not ' \
'contain some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument'
GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: GitHub API rate limit (5000 per hour) exceeded, change log may be " \
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."

def initialize
@options = Parser.parse_options
Expand Down Expand Up @@ -95,7 +95,7 @@ def find_closed_date_by_commit(issue)
commit = @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id]
issue[:actual_date] = commit[:author][:date]
rescue
puts "Warning: can't fetch commit #{event[:commit_id]} probably it referenced from another repo.".yellow
puts "Warning: Can't fetch commit #{event[:commit_id]}. It is probably referenced from another repo.".yellow
issue[:actual_date] = issue[:closed_at]
end
end
Expand Down Expand Up @@ -139,7 +139,7 @@ def fetch_merged_at_pull_requests
}

if @options[:verbose]
puts 'Fetching merged dates... Done!'
puts "Fetching merged dates: Done!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleanup! I think there is should be single quotes, since you don't use any parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've gone with http://viget.com/extend/just-use-double-quoted-ruby-strings and always use double quotes. But if you prefer mixed style, I can revert this part :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuexss it really makes sense. I just new in ruby, and consider, if RubyMine and rubocop pronouncedly highlight this - it should be like that "a priori". So, I thinking to move to double quote and revert this "fancy" PR :)

.. and add to rubocom.yml.

Style/StringLiterals:
  EnforcedStyle: double_quotes

Thanks, for point it out!

end
end

Expand Down Expand Up @@ -176,7 +176,7 @@ def get_filtered_pull_requests
filtered_pull_requests
end

def compund_changelog
def compound_changelog
log = "# Change Log\n\n"

if @options[:unreleased_only]
Expand Down Expand Up @@ -210,21 +210,21 @@ def compund_changelog

output_filename = "#{@options[:output]}"
File.open(output_filename, 'w') { |file| file.write(log) }
puts 'Done!'
puts "Done!"
puts "Generated log placed in #{`pwd`.strip!}/#{output_filename}"
end

def generate_log_for_all_tags
fetch_tags_dates

if @options[:verbose]
puts 'Sorting tags..'
puts "Sorting tags..."
end

@all_tags.sort_by! { |x| get_time_of_tag(x) }.reverse!

if @options[:verbose]
puts 'Generating log..'
puts "Generating log..."
end

log = ''
Expand All @@ -248,7 +248,7 @@ def generate_log_for_all_tags

def fetch_tags_dates
if @options[:verbose]
print "Fetching tags dates..\r"
print "Fetching tag dates...\r"
end

# Async fetching tags:
Expand All @@ -275,12 +275,6 @@ def fetch_tags_dates
end
end

def is_megred(number)
@github.pull_requests.merged? @options[:user], @options[:project], number
rescue
puts GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end

def get_all_tags
if @options[:verbose]
print "Fetching tags...\r"
Expand All @@ -298,12 +292,11 @@ def get_all_tags
tags.concat(page)
end
print " \r"
if @options[:verbose]
puts "Found #{tags.count} tags"
end

if tags.count == 0
puts "Warning: Can't find any tags in repo. Make sure, that you push tags to remote repo via 'git push --tags'".yellow
elsif @options[:verbose]
puts "Found #{tags.count} tags"
end

rescue
Expand All @@ -317,8 +310,8 @@ def fetch_github_token
env_var = @options[:token] ? @options[:token] : (ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil)

unless env_var
puts 'Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.'.yellow
puts 'This script can make only 50 requests to GitHub API per hour without token!'.yellow
puts "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
puts "This script can make only 50 requests per hour to GitHub API without a token!".yellow
end

@github_token ||= env_var
Expand Down Expand Up @@ -382,7 +375,7 @@ def filter_by_milestone(filtered_issues, newer_tag_name, src_array)
end

def delete_by_time(array, hash_key, older_tag = nil, newer_tag = nil)
fail 'At least one of the tags should be not nil!' if older_tag.nil? && newer_tag.nil?
fail "At least one of the tags should be not nil!" if older_tag.nil? && newer_tag.nil?

newer_tag_time = get_time_of_tag(newer_tag)
older_tag_time = get_time_of_tag(older_tag)
Expand Down Expand Up @@ -417,23 +410,14 @@ def delete_by_time(array, hash_key, older_tag = nil, newer_tag = nil)
# @param [String] older_tag_name
# @return [String]
def create_log(pull_requests, issues, newer_tag, older_tag_name = nil)
newer_tag_time = newer_tag.nil? ? nil : get_time_of_tag(newer_tag)
newer_tag_name = newer_tag.nil? ? nil : newer_tag['name']
newer_tag_time = newer_tag.nil? ? Time.new : get_time_of_tag(newer_tag)
newer_tag_name = newer_tag.nil? ? @options[:unreleased_label] : newer_tag['name']
newer_tag_link = newer_tag.nil? ? 'HEAD' : newer_tag_name

github_site = options[:github_site] || 'https://github.com'
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"

if newer_tag.nil?
newer_tag_name = @options[:unreleased_label]
newer_tag_link = 'HEAD'
newer_tag_time = Time.new
else
newer_tag_link = newer_tag_name
end

log = ''

log += generate_header(log, newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)
log = generate_header(newer_tag_name, newer_tag_link, newer_tag_time, older_tag_name, project_url)

if @options[:issues]
# Generate issues:
Expand Down Expand Up @@ -488,7 +472,9 @@ def generate_log_from_array(issues, prefix)
log
end

def generate_header(log, newer_tag_name, newer_tag_name2, newer_tag_time, older_tag_name, project_url)
def generate_header(newer_tag_name, newer_tag_name2, newer_tag_time, older_tag_name, project_url)
log = ''

# Generate date string:
time_string = newer_tag_time.strftime @options[:format]

Expand Down Expand Up @@ -635,6 +621,6 @@ def fetch_events_async(issues)
end

if __FILE__ == $PROGRAM_NAME
GitHubChangelogGenerator::ChangelogGenerator.new.compund_changelog
GitHubChangelogGenerator::ChangelogGenerator.new.compound_changelog
end
end