From e1161f9d9073bff9de744042df10fe8ba1223784 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Sat, 4 Apr 2015 00:22:40 +0300 Subject: [PATCH] code cleanup. remove duplicate code --- lib/github_changelog_generator.rb | 38 +++++++++++++------------------ 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 8f227ce..31ba9e1 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -46,17 +46,9 @@ module GitHubChangelogGenerator @all_tags = get_all_tags @issues, @pull_requests = fetch_issues_and_pull_requests - if @options[:pulls] - @pull_requests = get_filtered_pull_requests - else - @pull_requests = [] - end + @options[:pulls] ? @pull_requests = get_filtered_pull_requests : @pull_requests = [] - if @options[:issues] - @issues = get_filtered_issues - else - @issues = [] - end + @options[:issues] ? @issues = get_filtered_issues : @issues = [] fetch_event_for_issues_and_pr detect_actual_closed_dates @@ -162,12 +154,7 @@ module GitHubChangelogGenerator } 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(&:name) & @options[:exclude_labels]).any? - } - end + filtered_pull_requests = exclude_issues_by_labels(filtered_pull_requests) if @options[:add_issues_wo_labels] issues_wo_labels = @pull_requests.select { |issue| @@ -183,6 +170,18 @@ module GitHubChangelogGenerator filtered_pull_requests end + # delete all labels with labels from @options[:exclude_labels] array + # @param [Array] issues + # @return [Array] filtered array + def exclude_issues_by_labels(issues) + unless @options[:exclude_labels].nil? + issues = issues.select { |issue| + !(issue.labels.map(&:name) & @options[:exclude_labels]).any? + } + end + issues + end + # The entry point of this script to generate change log # @raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags. def compound_changelog @@ -551,12 +550,7 @@ module GitHubChangelogGenerator } end - unless @options[:exclude_labels].nil? - filtered_issues = filtered_issues.select { |issue| - # delete all labels from @options[:exclude_labels] array - !(issue.labels.map(&:name) & @options[:exclude_labels]).any? - } - end + filtered_issues = exclude_issues_by_labels(filtered_issues) if @options[:add_issues_wo_labels] issues_wo_labels = issues.select { |issue|