rubocop auto-fixes
This commit is contained in:
parent
a09b6affd4
commit
cca8e5d810
3
Rakefile
3
Rakefile
|
@ -4,5 +4,4 @@ require 'rspec/core/rake_task'
|
|||
RuboCop::RakeTask.new
|
||||
RSpec::Core::RakeTask.new(:rspec)
|
||||
|
||||
task :default => [:rubocop, :rspec]
|
||||
|
||||
task default: [:rubocop, :rspec]
|
||||
|
|
|
@ -7,7 +7,7 @@ SPEC_TYPE = 'gemspec'
|
|||
:minor
|
||||
:patch
|
||||
|
||||
@options = {:dry_run => false, :bump_number => :patch}
|
||||
@options = { dry_run: false, bump_number: :patch }
|
||||
|
||||
OptionParser.new { |opts|
|
||||
opts.banner = 'Usage: bump.rb [options]'
|
||||
|
@ -15,13 +15,13 @@ OptionParser.new { |opts|
|
|||
opts.on('-d', '--dry-run', 'Dry run') do |v|
|
||||
@options[:dry_run] = v
|
||||
end
|
||||
opts.on('-a', '--major', 'Bump major version') do |v|
|
||||
opts.on('-a', '--major', 'Bump major version') do |_v|
|
||||
@options[:bump_number] = :major
|
||||
end
|
||||
opts.on('-m', '--minor', 'Bump minor version') do |v|
|
||||
opts.on('-m', '--minor', 'Bump minor version') do |_v|
|
||||
@options[:bump_number] = :minor
|
||||
end
|
||||
opts.on('-p', '--patch', 'Bump patch version') do |v|
|
||||
opts.on('-p', '--patch', 'Bump patch version') do |_v|
|
||||
@options[:bump_number] = :patch
|
||||
end
|
||||
opts.on('-r', '--revert', 'Revert last bump') do |v|
|
||||
|
@ -32,7 +32,7 @@ OptionParser.new { |opts|
|
|||
p @options
|
||||
|
||||
def check_repo_is_clean_or_dry_run
|
||||
value =%x[#{'git status --porcelain'}]
|
||||
value = `#{'git status --porcelain'}`
|
||||
|
||||
if value.empty?
|
||||
puts 'Repo is clean -> continue'
|
||||
|
@ -46,7 +46,6 @@ def check_repo_is_clean_or_dry_run
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def find_spec_file
|
||||
list_of_specs = execute_line("find . -name '*.#{SPEC_TYPE}'")
|
||||
arr = list_of_specs.split("\n")
|
||||
|
@ -61,18 +60,17 @@ def find_spec_file
|
|||
spec_file = arr[0]
|
||||
else
|
||||
puts 'Which spec should be used?'
|
||||
arr.each_with_index { |file, index| puts "#{index+1}. #{file}" }
|
||||
arr.each_with_index { |file, index| puts "#{index + 1}. #{file}" }
|
||||
input_index = Integer(gets.chomp)
|
||||
spec_file = arr[input_index-1]
|
||||
spec_file = arr[input_index - 1]
|
||||
end
|
||||
|
||||
if spec_file == nil
|
||||
if spec_file.nil?
|
||||
puts "Can't find specified spec file -> exit"
|
||||
exit
|
||||
end
|
||||
|
||||
spec_file.sub('./', '')
|
||||
|
||||
end
|
||||
|
||||
def find_current_gem_file
|
||||
|
@ -89,24 +87,23 @@ def find_current_gem_file
|
|||
spec_file = arr[0]
|
||||
else
|
||||
puts 'Which spec should be used?'
|
||||
arr.each_with_index { |file, index| puts "#{index+1}. #{file}" }
|
||||
arr.each_with_index { |file, index| puts "#{index + 1}. #{file}" }
|
||||
input_index = Integer(gets.chomp)
|
||||
spec_file = arr[input_index-1]
|
||||
spec_file = arr[input_index - 1]
|
||||
end
|
||||
|
||||
if spec_file == nil
|
||||
if spec_file.nil?
|
||||
puts "Can't find specified spec file -> exit"
|
||||
exit
|
||||
end
|
||||
|
||||
spec_file.sub('./', '')
|
||||
|
||||
end
|
||||
|
||||
def find_version_in_podspec(podspec)
|
||||
readme = File.read(podspec)
|
||||
|
||||
#try to find version in format 1.22.333
|
||||
# try to find version in format 1.22.333
|
||||
re = /(\d+)\.(\d+)\.(\d+)/m
|
||||
|
||||
match_result = re.match(readme)
|
||||
|
@ -117,12 +114,12 @@ def find_version_in_podspec(podspec)
|
|||
end
|
||||
|
||||
puts "Found version #{match_result[0]}"
|
||||
return match_result[0], match_result.captures
|
||||
[match_result[0], match_result.captures]
|
||||
end
|
||||
|
||||
def bump_version(versions_array)
|
||||
bumped_result = versions_array.dup
|
||||
bumped_result.map! { |x| x.to_i }
|
||||
bumped_result.map!(&:to_i)
|
||||
|
||||
case @options[:bump_number]
|
||||
when :major
|
||||
|
@ -135,10 +132,9 @@ def bump_version(versions_array)
|
|||
when :patch
|
||||
bumped_result[2] += 1
|
||||
else
|
||||
raise('unknown bump_number')
|
||||
fail('unknown bump_number')
|
||||
end
|
||||
|
||||
|
||||
bumped_version = bumped_result.join('.')
|
||||
puts "Bump version: #{versions_array.join('.')} -> #{bumped_version}"
|
||||
bumped_version
|
||||
|
@ -157,7 +153,7 @@ def execute_line_if_not_dry_run(line)
|
|||
nil
|
||||
else
|
||||
puts line
|
||||
value = %x[#{line}]
|
||||
value = `#{line}`
|
||||
puts value
|
||||
check_exit_status(value)
|
||||
value
|
||||
|
@ -165,14 +161,13 @@ def execute_line_if_not_dry_run(line)
|
|||
end
|
||||
|
||||
def check_exit_status(output)
|
||||
if $?.exitstatus != 0
|
||||
puts "Output:\n#{output}\nExit status = #{$?.exitstatus} ->Terminate script."
|
||||
if $CHILD_STATUS.exitstatus != 0
|
||||
puts "Output:\n#{output}\nExit status = #{$CHILD_STATUS.exitstatus} ->Terminate script."
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def run_bumping_script
|
||||
|
||||
check_repo_is_clean_or_dry_run
|
||||
spec_file = find_spec_file
|
||||
result, versions_array = find_version_in_podspec(spec_file)
|
||||
|
@ -198,7 +193,6 @@ def run_bumping_script
|
|||
gem = find_current_gem_file
|
||||
execute_line_if_not_dry_run("gem push #{gem}")
|
||||
# execute_line_if_not_dry_run("pod trunk push #{spec_file}")
|
||||
|
||||
end
|
||||
|
||||
def revert_last_bump
|
||||
|
@ -216,7 +210,7 @@ def revert_last_bump
|
|||
execute_line_if_not_dry_run("git push --delete origin #{result}")
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
|
||||
if @options[:revert]
|
||||
revert_last_bump
|
||||
|
|
|
@ -5,28 +5,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|||
require 'github_changelog_generator/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "github_changelog_generator"
|
||||
spec.name = 'github_changelog_generator'
|
||||
spec.version = GitHubChangelogGenerator::VERSION
|
||||
spec.default_executable = "github_changelog_generator"
|
||||
spec.default_executable = 'github_changelog_generator'
|
||||
|
||||
spec.required_ruby_version = '>= 1.9.3'
|
||||
spec.authors = ["Petr Korolev"]
|
||||
spec.email = %q{sky4winder+github_changelog_generator@gmail.com}
|
||||
spec.authors = ['Petr Korolev']
|
||||
spec.email = 'sky4winder+github_changelog_generator@gmail.com'
|
||||
spec.date = `date +"%Y-%m-%d"`.strip!
|
||||
spec.summary = %q{Script, that automatically generate changelog from your tags, issues, labels and pull requests.}
|
||||
spec.description = %q{Changelog generation has never been so easy. Fully automate changelog generation - this gem generate change log file based on tags, issues and merged pull requests from Github issue tracker.}
|
||||
spec.homepage = %q{https://github.com/skywinder/Github-Changelog-Generator}
|
||||
spec.license = "MIT"
|
||||
spec.summary = 'Script, that automatically generate changelog from your tags, issues, labels and pull requests.'
|
||||
spec.description = 'Changelog generation has never been so easy. Fully automate changelog generation - this gem generate change log file based on tags, issues and merged pull requests from Github issue tracker.'
|
||||
spec.homepage = 'https://github.com/skywinder/Github-Changelog-Generator'
|
||||
spec.license = 'MIT'
|
||||
|
||||
spec.files = `git ls-files -z`.split("\x0")
|
||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||
spec.require_paths = ["lib"]
|
||||
spec.require_paths = ['lib']
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.7"
|
||||
spec.add_development_dependency "rake", "~> 10.0"
|
||||
|
||||
spec.add_runtime_dependency(%q<github_api>, ["~> 0.12"])
|
||||
spec.add_runtime_dependency(%q<colorize>, ["~> 0.7"])
|
||||
spec.add_development_dependency 'bundler', '~> 1.7'
|
||||
spec.add_development_dependency 'rake', '~> 10.0'
|
||||
|
||||
spec.add_runtime_dependency('github_api', ['~> 0.12'])
|
||||
spec.add_runtime_dependency('colorize', ['~> 0.7'])
|
||||
end
|
||||
|
|
|
@ -11,20 +11,18 @@ require_relative 'github_changelog_generator/version'
|
|||
|
||||
module GitHubChangelogGenerator
|
||||
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 ' +
|
||||
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'
|
||||
|
||||
def initialize
|
||||
|
||||
@options = Parser.parse_options
|
||||
|
||||
fetch_github_token
|
||||
|
||||
github_options = {per_page: PER_PAGE_NUMBER}
|
||||
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?
|
||||
|
@ -37,17 +35,17 @@ module GitHubChangelogGenerator
|
|||
|
||||
@generator = Generator.new(@options)
|
||||
|
||||
@all_tags = self.get_all_tags
|
||||
@issues, @pull_requests = self.fetch_issues_and_pull_requests
|
||||
@all_tags = get_all_tags
|
||||
@issues, @pull_requests = fetch_issues_and_pull_requests
|
||||
|
||||
if @options[:pulls]
|
||||
@pull_requests = self.get_filtered_pull_requests
|
||||
@pull_requests = get_filtered_pull_requests
|
||||
else
|
||||
@pull_requests = []
|
||||
end
|
||||
|
||||
if @options[:issues]
|
||||
@issues = self.get_filtered_issues
|
||||
@issues = get_filtered_issues
|
||||
else
|
||||
@issues = []
|
||||
end
|
||||
|
@ -58,7 +56,6 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def detect_actual_closed_dates
|
||||
|
||||
if @options[:verbose]
|
||||
print "Fetching closed dates for issues...\r"
|
||||
end
|
||||
|
@ -76,7 +73,7 @@ module GitHubChangelogGenerator
|
|||
find_closed_date_by_commit(pull_request)
|
||||
}
|
||||
}
|
||||
threads.each { |thr| thr.join }
|
||||
threads.each(&:join)
|
||||
|
||||
if @options[:verbose]
|
||||
puts 'Fetching closed dates for issues: Done!'
|
||||
|
@ -85,7 +82,7 @@ module GitHubChangelogGenerator
|
|||
|
||||
def find_closed_date_by_commit(issue)
|
||||
unless issue['events'].nil?
|
||||
#if it's PR -> then find "merged event", in case of usual issue -> fond closed date
|
||||
# if it's PR -> then find "merged event", in case of usual issue -> fond closed date
|
||||
compare_string = issue[:merged_at].nil? ? 'closed' : 'merged'
|
||||
# reverse! - to find latest closed event. (event goes in date order)
|
||||
issue['events'].reverse!.each { |event|
|
||||
|
@ -105,7 +102,7 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
}
|
||||
end
|
||||
#TODO: assert issues, that remain without 'actual_date' hash for some reason.
|
||||
# TODO: assert issues, that remain without 'actual_date' hash for some reason.
|
||||
end
|
||||
|
||||
def print_json(json)
|
||||
|
@ -118,7 +115,7 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
pull_requests = []
|
||||
begin
|
||||
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||
response = @github.pull_requests.list @options[:user], @options[:project], state: 'closed'
|
||||
page_i = 0
|
||||
response.each_page do |page|
|
||||
page_i += PER_PAGE_NUMBER
|
||||
|
@ -134,7 +131,8 @@ module GitHubChangelogGenerator
|
|||
|
||||
@pull_requests.each { |pr|
|
||||
fetched_pr = pull_requests.find { |fpr|
|
||||
fpr.number == pr.number }
|
||||
fpr.number == pr.number
|
||||
}
|
||||
pr[:merged_at] = fetched_pr[:merged_at]
|
||||
pull_requests.delete(fetched_pr)
|
||||
}
|
||||
|
@ -142,38 +140,34 @@ module GitHubChangelogGenerator
|
|||
if @options[:verbose]
|
||||
puts 'Fetching merged dates... Done!'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def get_filtered_pull_requests
|
||||
fetch_merged_at_pull_requests
|
||||
|
||||
self.fetch_merged_at_pull_requests
|
||||
|
||||
filtered_pull_requests = @pull_requests.select { |pr| pr[:merged_at] != nil }
|
||||
filtered_pull_requests = @pull_requests.select { |pr| !pr[:merged_at].nil? }
|
||||
|
||||
unless @options[:include_labels].nil?
|
||||
filtered_pull_requests = @pull_requests.select { |issue|
|
||||
#add all labels from @options[:incluse_labels] array
|
||||
(issue.labels.map { |label| label.name } & @options[:include_labels]).any?
|
||||
# add all labels from @options[:incluse_labels] array
|
||||
(issue.labels.map(&:name) & @options[:include_labels]).any?
|
||||
}
|
||||
end
|
||||
|
||||
unless @options[:exclude_labels].nil?
|
||||
filtered_pull_requests = filtered_pull_requests.select { |issue|
|
||||
#delete all labels from @options[:exclude_labels] array
|
||||
!(issue.labels.map { |label| label.name } & @options[:exclude_labels]).any?
|
||||
# delete all labels from @options[:exclude_labels] array
|
||||
!(issue.labels.map(&:name) & @options[:exclude_labels]).any?
|
||||
}
|
||||
end
|
||||
|
||||
if @options[:add_issues_wo_labels]
|
||||
issues_wo_labels = @pull_requests.select {
|
||||
# add issues without any labels
|
||||
|issue| !issue.labels.map { |label| label.name }.any?
|
||||
issues_wo_labels = @pull_requests.select { |issue|
|
||||
!issue.labels.map(&:name).any?
|
||||
}
|
||||
filtered_pull_requests |= issues_wo_labels
|
||||
end
|
||||
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Filtered pull requests: #{filtered_pull_requests.count}"
|
||||
end
|
||||
|
@ -182,16 +176,15 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def compund_changelog
|
||||
|
||||
log = "# Change Log\n\n"
|
||||
|
||||
if @options[:unreleased_only]
|
||||
log += self.generate_log_between_tags(self.all_tags[0], nil)
|
||||
log += generate_log_between_tags(all_tags[0], nil)
|
||||
elsif @options[:tag1] and @options[:tag2]
|
||||
tag1 = @options[:tag1]
|
||||
tag2 = @options[:tag2]
|
||||
tags_strings = []
|
||||
self.all_tags.each { |x| tags_strings.push(x['name']) }
|
||||
all_tags.each { |x| tags_strings.push(x['name']) }
|
||||
|
||||
if tags_strings.include?(tag1)
|
||||
if tags_strings.include?(tag2)
|
||||
|
@ -199,7 +192,7 @@ module GitHubChangelogGenerator
|
|||
hash = Hash[to_a]
|
||||
index1 = hash[tag1]
|
||||
index2 = hash[tag2]
|
||||
log += self.generate_log_between_tags(self.all_tags[index1], self.all_tags[index2])
|
||||
log += generate_log_between_tags(all_tags[index1], all_tags[index2])
|
||||
else
|
||||
puts "Can't find tag #{tag2} -> exit"
|
||||
exit
|
||||
|
@ -209,7 +202,7 @@ module GitHubChangelogGenerator
|
|||
exit
|
||||
end
|
||||
else
|
||||
log += self.generate_log_for_all_tags
|
||||
log += generate_log_for_all_tags
|
||||
end
|
||||
|
||||
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
||||
|
@ -218,38 +211,35 @@ module GitHubChangelogGenerator
|
|||
File.open(output_filename, 'w') { |file| file.write(log) }
|
||||
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| self.get_time_of_tag(x) }.reverse!
|
||||
@all_tags.sort_by! { |x| get_time_of_tag(x) }.reverse!
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Generating log.."
|
||||
puts 'Generating log..'
|
||||
end
|
||||
|
||||
|
||||
log = ''
|
||||
|
||||
if @options[:unreleased] && @all_tags.count != 0
|
||||
unreleased_log = self.generate_log_between_tags(self.all_tags[0], nil)
|
||||
unreleased_log = generate_log_between_tags(all_tags[0], nil)
|
||||
if unreleased_log
|
||||
log += unreleased_log
|
||||
end
|
||||
end
|
||||
|
||||
(1 ... self.all_tags.size).each { |index|
|
||||
log += self.generate_log_between_tags(self.all_tags[index], self.all_tags[index-1])
|
||||
(1...all_tags.size).each { |index|
|
||||
log += generate_log_between_tags(all_tags[index], all_tags[index - 1])
|
||||
}
|
||||
if @all_tags.count != 0
|
||||
log += generate_log_between_tags(nil, self.all_tags.last)
|
||||
log += generate_log_between_tags(nil, all_tags.last)
|
||||
end
|
||||
|
||||
log
|
||||
|
@ -267,18 +257,17 @@ module GitHubChangelogGenerator
|
|||
@all_tags.each { |tag|
|
||||
# explicit set @tag_times_hash to write data safety.
|
||||
threads << Thread.new {
|
||||
self.get_time_of_tag(tag, @tag_times_hash)
|
||||
get_time_of_tag(tag, @tag_times_hash)
|
||||
if @options[:verbose]
|
||||
print "Fetching tags dates: #{i+1}/#{all}\r"
|
||||
i+=1
|
||||
print "Fetching tags dates: #{i + 1}/#{all}\r"
|
||||
i += 1
|
||||
end
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
print " \r"
|
||||
|
||||
threads.each { |thr| thr.join }
|
||||
threads.each(&:join)
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Fetching tags dates: #{i} Done!"
|
||||
|
@ -292,7 +281,6 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def get_all_tags
|
||||
|
||||
if @options[:verbose]
|
||||
print "Fetching tags...\r"
|
||||
end
|
||||
|
@ -328,12 +316,11 @@ module GitHubChangelogGenerator
|
|||
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 to GitHub API per hour without token!'.yellow
|
||||
end
|
||||
|
||||
@github_token ||= env_var
|
||||
|
||||
end
|
||||
|
||||
def generate_log_between_tags(older_tag, newer_tag)
|
||||
|
@ -345,7 +332,7 @@ module GitHubChangelogGenerator
|
|||
older_tag_name = older_tag.nil? ? nil : older_tag['name']
|
||||
|
||||
if @options[:filter_issues_by_milestone]
|
||||
#delete excess irrelevant issues (according milestones)
|
||||
# delete excess irrelevant issues (according milestones)
|
||||
filtered_issues = filter_by_milestone(filtered_issues, newer_tag_name, @issues)
|
||||
filtered_pull_requests = filter_by_milestone(filtered_pull_requests, newer_tag_name, @pull_requests)
|
||||
end
|
||||
|
@ -355,7 +342,7 @@ module GitHubChangelogGenerator
|
|||
return ''
|
||||
end
|
||||
|
||||
self.create_log(filtered_pull_requests, filtered_issues, newer_tag, older_tag_name)
|
||||
create_log(filtered_pull_requests, filtered_issues, newer_tag, older_tag_name)
|
||||
end
|
||||
|
||||
def filter_by_milestone(filtered_issues, newer_tag_name, src_array)
|
||||
|
@ -364,18 +351,18 @@ module GitHubChangelogGenerator
|
|||
if issue.milestone.nil?
|
||||
true
|
||||
else
|
||||
#check, that this milestone in tag list:
|
||||
# check, that this milestone in tag list:
|
||||
@all_tags.find { |tag| tag.name == issue.milestone.title }.nil?
|
||||
end
|
||||
}
|
||||
unless newer_tag_name.nil?
|
||||
|
||||
#add missed issues (according milestones)
|
||||
# add missed issues (according milestones)
|
||||
issues_to_add = src_array.select { |issue|
|
||||
if issue.milestone.nil?
|
||||
false
|
||||
else
|
||||
#check, that this milestone in tag list:
|
||||
# check, that this milestone in tag list:
|
||||
milestone_is_tag = @all_tags.find { |tag|
|
||||
tag.name == issue.milestone.title
|
||||
}
|
||||
|
@ -394,11 +381,10 @@ module GitHubChangelogGenerator
|
|||
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?
|
||||
|
||||
raise 'At least one of the tags should be not nil!' if (older_tag.nil? && newer_tag.nil?)
|
||||
|
||||
newer_tag_time = self.get_time_of_tag(newer_tag)
|
||||
older_tag_time = self.get_time_of_tag(older_tag)
|
||||
newer_tag_time = get_time_of_tag(newer_tag)
|
||||
older_tag_time = get_time_of_tag(older_tag)
|
||||
|
||||
array.select { |req|
|
||||
if req[hash_key]
|
||||
|
@ -416,7 +402,6 @@ module GitHubChangelogGenerator
|
|||
tag_in_range_new = t <= newer_tag_time
|
||||
end
|
||||
|
||||
|
||||
tag_in_range = (tag_in_range_old) && (tag_in_range_new)
|
||||
|
||||
tag_in_range
|
||||
|
@ -431,8 +416,7 @@ module GitHubChangelogGenerator
|
|||
# @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 : self.get_time_of_tag(newer_tag)
|
||||
newer_tag_time = newer_tag.nil? ? nil : get_time_of_tag(newer_tag)
|
||||
newer_tag_name = newer_tag.nil? ? nil : newer_tag['name']
|
||||
|
||||
github_site = options[:github_site] || 'https://github.com'
|
||||
|
@ -454,7 +438,7 @@ module GitHubChangelogGenerator
|
|||
# Generate issues:
|
||||
issues_a = []
|
||||
enhancement_a = []
|
||||
bugs_a =[]
|
||||
bugs_a = []
|
||||
|
||||
issues.each { |dict|
|
||||
added = false
|
||||
|
@ -504,8 +488,7 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def generate_header(log, newer_tag_name, newer_tag_name2, newer_tag_time, older_tag_name, project_url)
|
||||
|
||||
#Generate date string:
|
||||
# Generate date string:
|
||||
time_string = newer_tag_time.strftime @options[:format]
|
||||
|
||||
# Generate tag name and link
|
||||
|
@ -524,7 +507,6 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def get_time_of_tag(tag_name, tag_times_hash = @tag_times_hash)
|
||||
|
||||
if tag_name.nil?
|
||||
return nil
|
||||
end
|
||||
|
@ -543,40 +525,36 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def get_filtered_issues
|
||||
|
||||
issues = @issues
|
||||
|
||||
filtered_issues = issues
|
||||
|
||||
unless @options[:include_labels].nil?
|
||||
filtered_issues = issues.select { |issue|
|
||||
#add all labels from @options[:incluse_labels] array
|
||||
(issue.labels.map { |label| label.name } & @options[:include_labels]).any?
|
||||
# add all labels from @options[:incluse_labels] array
|
||||
(issue.labels.map(&:name) & @options[:include_labels]).any?
|
||||
}
|
||||
end
|
||||
|
||||
unless @options[:exclude_labels].nil?
|
||||
filtered_issues = filtered_issues.select { |issue|
|
||||
#delete all labels from @options[:exclude_labels] array
|
||||
!(issue.labels.map { |label| label.name } & @options[:exclude_labels]).any?
|
||||
# delete all labels from @options[:exclude_labels] array
|
||||
!(issue.labels.map(&:name) & @options[:exclude_labels]).any?
|
||||
}
|
||||
end
|
||||
|
||||
if @options[:add_issues_wo_labels]
|
||||
issues_wo_labels = issues.select {
|
||||
# add issues without any labels
|
||||
|issue| !issue.labels.map { |label| label.name }.any?
|
||||
issues_wo_labels = issues.select { |issue|
|
||||
!issue.labels.map(&:name).any?
|
||||
}
|
||||
filtered_issues |= issues_wo_labels
|
||||
end
|
||||
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Filtered issues: #{filtered_issues.count}"
|
||||
end
|
||||
|
||||
filtered_issues
|
||||
|
||||
end
|
||||
|
||||
def fetch_issues_and_pull_requests
|
||||
|
@ -607,12 +585,12 @@ module GitHubChangelogGenerator
|
|||
|
||||
# remove pull request from issues:
|
||||
issues_wo_pr = issues.select { |x|
|
||||
x.pull_request == nil
|
||||
x.pull_request.nil?
|
||||
}
|
||||
pull_requests = issues.select { |x|
|
||||
x.pull_request != nil
|
||||
!x.pull_request.nil?
|
||||
}
|
||||
return issues_wo_pr, pull_requests
|
||||
[issues_wo_pr, pull_requests]
|
||||
end
|
||||
|
||||
def fetch_event_for_issues_and_pr
|
||||
|
@ -623,8 +601,6 @@ module GitHubChangelogGenerator
|
|||
# Async fetching events:
|
||||
|
||||
fetch_events_async(@issues + @pull_requests)
|
||||
|
||||
|
||||
end
|
||||
|
||||
def fetch_events_async(issues)
|
||||
|
@ -640,27 +616,24 @@ module GitHubChangelogGenerator
|
|||
puts GH_RATE_LIMIT_EXCEEDED_MSG.yellow
|
||||
end
|
||||
issue[:events] = obj.body
|
||||
print "Fetching events for issues and PR: #{i+1}/#{@issues.count + @pull_requests.count}\r"
|
||||
i +=1
|
||||
print "Fetching events for issues and PR: #{i + 1}/#{@issues.count + @pull_requests.count}\r"
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
threads.each { |thr| thr.join }
|
||||
threads.each(&:join)
|
||||
threads = []
|
||||
}
|
||||
|
||||
#to clear line from prev print
|
||||
# to clear line from prev print
|
||||
print " \r"
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Fetching events for issues and PR: #{i} Done!"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
GitHubChangelogGenerator::ChangelogGenerator.new.compund_changelog
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
module GitHubChangelogGenerator
|
||||
class Generator
|
||||
|
||||
def initialize(options = nil)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def get_string_for_issue(issue)
|
||||
encapsulated_title = self.encapsulate_string issue[:title]
|
||||
encapsulated_title = encapsulate_string issue[:title]
|
||||
|
||||
title_with_number = "#{encapsulated_title} [\\##{issue[:number]}](#{issue.html_url})"
|
||||
|
||||
unless issue.pull_request.nil?
|
||||
if @options[:author]
|
||||
if issue.user.nil?
|
||||
title_with_number += " ({Null user})"
|
||||
title_with_number += ' ({Null user})'
|
||||
else
|
||||
title_with_number += " ([#{issue.user.login}](#{issue.user.html_url}))"
|
||||
end
|
||||
|
@ -23,17 +22,14 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
def encapsulate_string(string)
|
||||
|
||||
string.gsub! '\\', '\\\\'
|
||||
|
||||
encpas_chars = %w(> * _ \( \) [ ] #)
|
||||
encpas_chars.each { |char|
|
||||
encpas_chars.each do |char|
|
||||
string.gsub! char, "\\#{char}"
|
||||
}
|
||||
end
|
||||
|
||||
string
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -6,32 +6,31 @@ require_relative 'version'
|
|||
module GitHubChangelogGenerator
|
||||
class Parser
|
||||
def self.parse_options
|
||||
|
||||
options = {
|
||||
:tag1 => nil,
|
||||
:tag2 => nil,
|
||||
:format => '%Y-%m-%d',
|
||||
:output => 'CHANGELOG.md',
|
||||
:exclude_labels => %w(duplicate question invalid wontfix),
|
||||
:pulls => true,
|
||||
:issues => true,
|
||||
:verbose => true,
|
||||
:add_issues_wo_labels => true,
|
||||
:add_pr_wo_labels => true,
|
||||
:merge_prefix => '**Merged pull requests:**',
|
||||
:issue_prefix => '**Closed issues:**',
|
||||
:bug_prefix => '**Fixed bugs:**',
|
||||
:enhancement_prefix => '**Implemented enhancements:**',
|
||||
:author => true,
|
||||
:filter_issues_by_milestone => true,
|
||||
:max_issues => nil,
|
||||
:compare_link => true,
|
||||
:unreleased => true,
|
||||
:unreleased_label => 'Unreleased',
|
||||
:branch => 'origin'
|
||||
tag1: nil,
|
||||
tag2: nil,
|
||||
format: '%Y-%m-%d',
|
||||
output: 'CHANGELOG.md',
|
||||
exclude_labels: %w(duplicate question invalid wontfix),
|
||||
pulls: true,
|
||||
issues: true,
|
||||
verbose: true,
|
||||
add_issues_wo_labels: true,
|
||||
add_pr_wo_labels: true,
|
||||
merge_prefix: '**Merged pull requests:**',
|
||||
issue_prefix: '**Closed issues:**',
|
||||
bug_prefix: '**Fixed bugs:**',
|
||||
enhancement_prefix: '**Implemented enhancements:**',
|
||||
author: true,
|
||||
filter_issues_by_milestone: true,
|
||||
max_issues: nil,
|
||||
compare_link: true,
|
||||
unreleased: true,
|
||||
unreleased_label: 'Unreleased',
|
||||
branch: 'origin'
|
||||
}
|
||||
|
||||
parser = OptionParser.new { |opts|
|
||||
parser = OptionParser.new do |opts|
|
||||
opts.banner = 'Usage: github_changelog_generator [options]'
|
||||
opts.on('-u', '--user [USER]', 'Username of the owner of target GitHub repo') do |last|
|
||||
options[:user] = last
|
||||
|
@ -99,7 +98,7 @@ module GitHubChangelogGenerator
|
|||
opts.on('--[no-]verbose', 'Run verbosely. Default is true') do |v|
|
||||
options[:verbose] = v
|
||||
end
|
||||
opts.on('-v', '--version', 'Print version number') do |v|
|
||||
opts.on('-v', '--version', 'Print version number') do |_v|
|
||||
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
||||
exit
|
||||
end
|
||||
|
@ -107,7 +106,7 @@ module GitHubChangelogGenerator
|
|||
puts opts
|
||||
exit
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
parser.parse!
|
||||
|
||||
|
@ -126,10 +125,9 @@ module GitHubChangelogGenerator
|
|||
exit
|
||||
else
|
||||
options[:user] = match[1]
|
||||
options[:project]= match[2]
|
||||
options[:project] = match[2]
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
if !options[:user] && !options[:project]
|
||||
|
@ -154,7 +152,6 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
if !options[:user] || !options[:project]
|
||||
puts parser.banner
|
||||
exit
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
#
|
||||
# Author:: Enrico Stahn <mail@enricostahn.com>
|
||||
#
|
||||
# Copyright 2014, Zanui, <engineering@zanui.com.au>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'github_changelog_generator'
|
||||
|
||||
# This file was generated by the `rspec --init` command. Conventionally, all
|
||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
||||
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
||||
|
@ -40,9 +60,6 @@ RSpec.configure do |config|
|
|||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
# These two settings work together to allow you to limit a spec run
|
||||
# to individual examples or groups you care about by tagging them with
|
||||
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
||||
|
@ -87,5 +104,4 @@ RSpec.configure do |config|
|
|||
# test failures related to randomization by passing the same `--seed` value
|
||||
# as the one that triggered the failure.
|
||||
Kernel.srand config.seed
|
||||
=end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user