Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
testerindevelopment committed Mar 24, 2016
1 parent e5a619b commit 6a0ade1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
14 changes: 0 additions & 14 deletions lib/github_changelog_generator/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,11 @@ def github_fetch_tags
response = @github.repos.tags @options[:user], @options[:project]
page_i = 0
count_pages = response.count_pages

response.each_page do |page|

if @options[:exclude_tags_filter]
body_new = []
reg = Regexp.new @options[:exclude_tags_filter]
page.body.each do |tag|
if !(tag.name =~ reg)
body_new << tag
end
end
page.body = body_new
end

page_i += PER_PAGE_NUMBER
print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
tags.concat(page)
end

print_empty_line

if tags.count == 0
Expand Down
22 changes: 5 additions & 17 deletions lib/github_changelog_generator/generator/generator_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,19 @@ def filter_between_tags(all_tags)
end

# @param [Array] all_tags all tags
# @return [Array] filtered tags according :exclude_tags option
# @return [Array] filtered tags according :exclude_tags or :exclude_tags_regex option
def filter_excluded_tags(all_tags)
if @options[:exclude_tags]
apply_exclude_tags(all_tags)
elsif @options[:exclude_tags_regex]
apply_exclude_tags_regex(all_tags)
if (@options[:exclude_tags].is_a?(Regexp) || @options[:exclude_tags_regex])
filter_tags_with_regex(all_tags)
elsif @options[:exclude_tags]
filter_exact_tags(all_tags)
else
all_tags
end
end

private

def apply_exclude_tags(all_tags)
if @options[:exclude_tags].is_a?(Regexp)
filter_tags_with_regex(all_tags)
else
filter_exact_tags(all_tags)
end
end

def apply_exclude_tags_regex(all_tags)
filter_tags_with_regex(all_tags)
end

def filter_tags_with_regex(all_tags)
warn_if_nonmatching_regex(all_tags)

Expand Down
6 changes: 3 additions & 3 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def self.setup_parser(options)
opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list|
options[:between_tags] = list
end
opts.on("--exclude-tags-filter [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-filter \".*\+\d{1,}\" ") do |last|
options[:exclude_tags_filter] = last
end
opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list|
options[:exclude_tags] = list
end
opts.on("--exclude-tags-regex [REGEX]", "Apply a regular expression on tag names so that they can be excluded, for example: --exclude-tags-regex \".*\+\d{1,}\" ") do |last|
options[:exclude_tags_regex] = last
end
opts.on("--since-tag x", "Change log will start after specified tag") do |v|
options[:since_tag] = v
end
Expand Down

0 comments on commit 6a0ade1

Please sign in to comment.