Merge branch 'new-features'
This commit is contained in:
commit
269ab4e790
|
@ -41,11 +41,15 @@ class ChangelogGenerator
|
||||||
|
|
||||||
|
|
||||||
def get_all_closed_pull_requests
|
def get_all_closed_pull_requests
|
||||||
request = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||||
pull_requests = request.body
|
|
||||||
|
pull_requests = []
|
||||||
|
response.each_page do |page|
|
||||||
|
pull_requests.concat(page)
|
||||||
|
end
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts 'Receive all pull requests'
|
puts "Receive all pull requests: #{pull_requests.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
pull_requests
|
pull_requests
|
||||||
|
@ -97,7 +101,7 @@ class ChangelogGenerator
|
||||||
def generate_log_for_all_tags
|
def generate_log_for_all_tags
|
||||||
log = ''
|
log = ''
|
||||||
for index in 1 ... self.all_tags.size
|
for index in 1 ... self.all_tags.size
|
||||||
log += self.generate_log_between_tags(self.all_tags[index-1], self.all_tags[index])
|
log += self.generate_log_between_tags(self.all_tags[index], self.all_tags[index-1])
|
||||||
end
|
end
|
||||||
|
|
||||||
log += self.generate_log_before_tag(self.all_tags.last)
|
log += self.generate_log_before_tag(self.all_tags.last)
|
||||||
|
@ -118,22 +122,18 @@ class ChangelogGenerator
|
||||||
puts "Receive tags for repo #{url}"
|
puts "Receive tags for repo #{url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if @github_token.nil?
|
response = @github.repos.tags @options[:user], @options[:project]
|
||||||
response = HTTParty.get(url,
|
|
||||||
:headers => {'User-Agent' => 'Changelog-Generator'})
|
|
||||||
else
|
|
||||||
response = HTTParty.get(url,
|
|
||||||
:headers => {'Authorization' => "token #{@github_token}",
|
|
||||||
'User-Agent' => 'Changelog-Generator'})
|
|
||||||
end
|
|
||||||
|
|
||||||
json_parse = JSON.parse(response.body)
|
tags = []
|
||||||
|
response.each_page do |page|
|
||||||
|
tags.concat(page)
|
||||||
|
end
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Found #{json_parse.count} tags"
|
puts "Found #{tags.count} tags"
|
||||||
end
|
end
|
||||||
|
|
||||||
json_parse
|
tags
|
||||||
end
|
end
|
||||||
|
|
||||||
def github_token
|
def github_token
|
||||||
|
@ -153,28 +153,29 @@ class ChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def generate_log_between_tags(since_tag, till_tag)
|
def generate_log_between_tags(older_tag, newer_tag)
|
||||||
since_tag_time = self.get_time_of_tag(since_tag)
|
older_tag_time = self.get_time_of_tag(older_tag)
|
||||||
till_tag_time = self.get_time_of_tag(till_tag)
|
newer_tag_time = self.get_time_of_tag(newer_tag)
|
||||||
|
|
||||||
# if we mix up tags order - lits fix it!
|
# if we mix up tags order - lits fix it!
|
||||||
if since_tag_time > till_tag_time
|
# if older_tag_time < newer_tag_time
|
||||||
since_tag, till_tag = till_tag, since_tag
|
# older_tag, newer_tag = newer_tag, older_tag
|
||||||
since_tag_time, till_tag_time = till_tag_time, since_tag_time
|
# older_tag_time, newer_tag_time = newer_tag_time, older_tag_time
|
||||||
end
|
# puts "Swap tags!"
|
||||||
|
# end
|
||||||
|
|
||||||
till_tag_name = till_tag['name']
|
newer_tag_name = newer_tag['name']
|
||||||
|
|
||||||
pull_requests = Array.new(@pull_requests)
|
pull_requests = Array.new(@pull_requests)
|
||||||
|
|
||||||
pull_requests.delete_if { |req|
|
pull_requests.delete_if { |req|
|
||||||
if req[:merged_at]
|
if req[:merged_at]
|
||||||
t = Time.parse(req[:merged_at]).utc
|
t = Time.parse(req[:merged_at]).utc
|
||||||
tag_is_later_since = t > since_tag_time
|
tag_is_older_of_older = t > older_tag_time
|
||||||
tag_is_before_till = t <= till_tag_time
|
tag_is_newer_than_new = t <= newer_tag_time
|
||||||
|
|
||||||
in_range = (tag_is_later_since) && (tag_is_before_till)
|
tag_not_in_range = (tag_is_older_of_older) && (tag_is_newer_than_new)
|
||||||
!in_range
|
!tag_not_in_range
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -186,8 +187,8 @@ class ChangelogGenerator
|
||||||
issues.delete_if { |issue|
|
issues.delete_if { |issue|
|
||||||
if issue[:closed_at]
|
if issue[:closed_at]
|
||||||
t = Time.parse(issue[:closed_at]).utc
|
t = Time.parse(issue[:closed_at]).utc
|
||||||
tag_is_later_since = t > since_tag_time
|
tag_is_later_since = t > older_tag_time
|
||||||
tag_is_before_till = t <= till_tag_time
|
tag_is_before_till = t <= newer_tag_time
|
||||||
|
|
||||||
in_range = (tag_is_later_since) && (tag_is_before_till)
|
in_range = (tag_is_later_since) && (tag_is_before_till)
|
||||||
!in_range
|
!in_range
|
||||||
|
@ -197,7 +198,7 @@ class ChangelogGenerator
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.create_log(pull_requests, issues, till_tag_name, till_tag_time)
|
self.create_log(pull_requests, issues, newer_tag_name, newer_tag_time)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -316,27 +317,38 @@ class ChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_all_issues
|
def get_all_issues
|
||||||
issues_req = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
response = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
||||||
|
|
||||||
filtered_issues = issues_req.body.select { |issues|
|
|
||||||
#compare is there any labels from @options[:labels] array
|
|
||||||
(issues.labels.map { |issue| issue.name } & @options[:labels]).any?
|
|
||||||
}
|
|
||||||
|
|
||||||
if @options[:add_issues_wo_labels]
|
issues = []
|
||||||
issues_wo_labels = issues_req.body.select {
|
response.each_page do |page|
|
||||||
|issues| !issues.labels.map { |issue| issue.name }.any?
|
issues.concat(page)
|
||||||
}
|
|
||||||
filtered_issues.concat(issues_wo_labels)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove pull request from issues:
|
# remove pull request from issues:
|
||||||
filtered_issues.select! { |x|
|
issues.select! { |x|
|
||||||
x.pull_request == nil
|
x.pull_request == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Receive all closed issues with labels #{@options[:labels]}: #{filtered_issues.count} issues"
|
puts "Receive all closed issues: #{issues.count}"
|
||||||
|
end
|
||||||
|
|
||||||
|
filtered_issues = issues.select { |issue|
|
||||||
|
#compare is there any labels from @options[:labels] array
|
||||||
|
(issue.labels.map { |label| label.name } & @options[:labels]).any?
|
||||||
|
}
|
||||||
|
|
||||||
|
if @options[:add_issues_wo_labels]
|
||||||
|
issues_wo_labels = issues.select {
|
||||||
|
# add issues without any labels
|
||||||
|
|issue| !issue.labels.map { |label| label.name }.any?
|
||||||
|
}
|
||||||
|
filtered_issues.concat(issues_wo_labels)
|
||||||
|
end
|
||||||
|
|
||||||
|
if @options[:verbose]
|
||||||
|
puts "Filter issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels]? ' and w/o labels' : ''}: #{filtered_issues.count} issues"
|
||||||
end
|
end
|
||||||
|
|
||||||
filtered_issues
|
filtered_issues
|
||||||
|
@ -347,5 +359,5 @@ end
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
changelog_generator = ChangelogGenerator.new
|
changelog_generator = ChangelogGenerator.new
|
||||||
# changelog_generator.compund_changelog
|
changelog_generator.compund_changelog
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user