Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7be5021685 | ||
|
|
c3373b2343 | ||
|
|
9aa156a02b | ||
|
|
68a8d8d2c8 | ||
|
|
057fb488d5 | ||
|
|
f1d9c839c7 | ||
|
|
97d048d62f | ||
|
|
7972ec0977 | ||
|
|
f55598825d | ||
|
|
a678b52fe4 | ||
|
|
aac04726ba | ||
|
|
0c65035cde | ||
|
|
e038c7e680 | ||
|
|
bcecb4eb81 | ||
|
|
52123885a1 | ||
|
|
326a067ac5 | ||
|
|
5dcbef87d1 | ||
|
|
caf264360b | ||
|
|
bc13632545 | ||
|
|
67b438f46b | ||
|
|
ff52291d2a | ||
|
|
b2df1cfdcd | ||
|
|
f037a839ce | ||
|
|
5295389fcc | ||
|
|
8e5b4ed191 | ||
|
|
80cc3fc625 | ||
|
|
f087699d07 | ||
|
|
540df2ef51 | ||
|
|
54d029d8ea | ||
|
|
bec4fdef0e | ||
|
|
b5d5615244 | ||
|
|
766569c27a | ||
|
|
51e3c2ee54 | ||
|
|
e1e5de555b | ||
|
|
0e4474bb2d | ||
|
|
fa4ccb7e9c | ||
|
|
36fbe509fa | ||
|
|
4c5ca562cf | ||
|
|
27432c3328 | ||
|
|
4a27872695 | ||
|
|
bf88bc0a0e | ||
|
|
3b145bd7ed | ||
|
|
97311bc5a0 | ||
|
|
bdc4657e2c | ||
|
|
0c8a96aef8 | ||
|
|
c9462a6c9b | ||
|
|
0a43c25f8f | ||
|
|
c58ec0dcbb | ||
|
|
7aa9b6ca47 | ||
|
|
865a364dff | ||
|
|
062f3fd3f2 | ||
|
|
a4e9390283 | ||
|
|
09f5ac5d37 | ||
|
|
aed5c37559 | ||
|
|
a5c4899360 |
15
.travis.yml
Normal file
15
.travis.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
language: ruby
|
||||
before_install:
|
||||
- gem update --system
|
||||
- gem --version
|
||||
rvm:
|
||||
- 2.1.0
|
||||
gemfile:
|
||||
- Gemfile
|
||||
|
||||
notifications:
|
||||
email:
|
||||
recipients:
|
||||
- sky4winder+githubchangeloggenerator@gmail.com
|
||||
on_success: never # [always|never|change]
|
||||
on_failure: change # [always|never|change]
|
||||
44
CHANGELOG.md
44
CHANGELOG.md
@@ -1,26 +1,42 @@
|
||||
# Changelog
|
||||
|
||||
## [1.1.3] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.3)
|
||||
#### 18/11/14
|
||||
- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23)
|
||||
## [1.2.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1)
|
||||
#### 22/11/14
|
||||
- *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Implemented enhancement:* Implement ability to retrieve GitHub token from some shell variable (to not put it to script directly) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19)
|
||||
- *Merged pull-request:* Disable default --filter-pull-requests option. [\#28](https://github.com/skywinder/Github-Changelog-Generator/pull/28) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [1.2.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0)
|
||||
#### 19/11/14
|
||||
- *Merged pull-request:* Add filter for pull-requests labels. (option --filter-pull-requests) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Test Pull-Request [\#26](https://github.com/skywinder/Github-Changelog-Generator/pull/26) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Add ability to insert authors of pull-requests (--[no-]author option) [\#25](https://github.com/skywinder/Github-Changelog-Generator/pull/25) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Don't receive issues in case of --no-isses flag specied [\#24](https://github.com/skywinder/Github-Changelog-Generator/pull/24) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [1.1.4] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4)
|
||||
#### 18/11/14
|
||||
- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable (to not put it to script directly) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19)
|
||||
|
||||
- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20)
|
||||
|
||||
## [1.1.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2)
|
||||
#### 12/11/14
|
||||
- *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18)
|
||||
- *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17)
|
||||
- *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [1.1.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1)
|
||||
#### 10/11/14
|
||||
- *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15)
|
||||
- *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Sort issues by tags [\#14](https://github.com/skywinder/Github-Changelog-Generator/pull/14)
|
||||
- *Merged pull-request:* Sort issues by tags [\#14](https://github.com/skywinder/Github-Changelog-Generator/pull/14) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13)
|
||||
- *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [1.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0)
|
||||
#### 10/11/14
|
||||
@@ -32,13 +48,13 @@
|
||||
|
||||
## [1.0.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1)
|
||||
#### 10/11/14
|
||||
- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8)
|
||||
- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [1.0.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0)
|
||||
#### 07/11/14
|
||||
- *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7)
|
||||
- *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3)
|
||||
- *Merged pull-request:* Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Implemented enhancement:* Implement option to specify output filename [\#4](https://github.com/skywinder/Github-Changelog-Generator/issues/4)
|
||||
|
||||
@@ -48,9 +64,9 @@
|
||||
|
||||
## [0.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0)
|
||||
#### 07/11/14
|
||||
- *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2)
|
||||
- *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
- *Merged pull-request:* Add option (-o --output) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1)
|
||||
- *Merged pull-request:* Add option (-o --output) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) ([skywinder](https://github.com/skywinder))
|
||||
|
||||
## [0.0.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2)
|
||||
#### 06/11/14
|
||||
|
||||
1
Gemfile
1
Gemfile
@@ -1,3 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
gem 'github_api'
|
||||
gem 'colorize'
|
||||
gem 'rake'
|
||||
|
||||
@@ -30,6 +30,7 @@ GEM
|
||||
multi_xml (~> 0.5)
|
||||
rack (~> 1.2)
|
||||
rack (1.5.2)
|
||||
rake (10.4.2)
|
||||
thread_safe (0.3.4)
|
||||
|
||||
PLATFORMS
|
||||
@@ -38,3 +39,4 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
colorize
|
||||
github_api
|
||||
rake
|
||||
|
||||
64
README.md
64
README.md
@@ -2,60 +2,59 @@ GitHub Changelog Generator
|
||||
==================
|
||||
|
||||
[](http://badge.fury.io/rb/github_changelog_generator)
|
||||
[](https://travis-ci.org/skywinder/Github-Changelog-Generator)
|
||||
|
||||
Changelog generation has never been so easy.
|
||||
|
||||
This script automatically generate change-log from your tags and merged pull-requests.
|
||||
|
||||
## Installation:
|
||||
You're almost done!
|
||||
|
||||
[sudo] gem install github_changelog_generator
|
||||
|
||||
## Usage
|
||||
**It's really simple**:
|
||||
|
||||
- `cd` to your Project folder with configured git and just type:
|
||||
- If your **git remote** `origin` refer to your GitHub repo, then just go to your project folder just run:
|
||||
|
||||
github_changelog_generator
|
||||
|
||||
- from anywhere:
|
||||
- or from anywhere:
|
||||
|
||||
github_changelog_generator -u github-username -p github-project
|
||||
|
||||
As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* changelog.
|
||||
|
||||
## Params:
|
||||
### Params:
|
||||
Type `github_changelog_generator --help` for detailed usage.
|
||||
|
||||
Usage: changelog_generator [options]
|
||||
-u, --user [USER] Username of the owner of target GitHub repo
|
||||
-p, --project [PROJECT] Name of project on GitHub
|
||||
-t, --token [TOKEN] To make more than 50 requests this script required your OAuth token for GitHub. You can generate it on https://github.com/settings/applications
|
||||
-h, --help Displays Help
|
||||
-v, --[no-]verbose Run verbosely. Default is true
|
||||
--[no-]issues Include closed issues to changelog. Default is true
|
||||
--[no-]issues-without-labels Include closed issues without any labels to changelog. Default is true
|
||||
--[no-]pull-requests Include pull-requests to changelog. Default is true
|
||||
-l, --last-changes Generate log between last 2 tags only
|
||||
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y
|
||||
-o, --output [NAME] Output file. Default is CHANGELOG.md
|
||||
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement'
|
||||
|
||||
## Examples:
|
||||
|
||||
- Look at changelog for **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for this project
|
||||
- This changelog: [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md) was generated by command:
|
||||
|
||||
github_changelog_generator -u skywinder -p ActionSheetPicker-3.0
|
||||
-u, --user [USER] Username of the owner of target GitHub repo
|
||||
-p, --project [PROJECT] Name of project on GitHub
|
||||
-t, --token [TOKEN] To make more than 50 requests this script required your OAuth token for GitHub. You can generate here: https://github.com/settings/tokens/new
|
||||
-h, --help Displays Help
|
||||
--[no-]verbose Run verbosely. Default is true
|
||||
--[no-]issues Include closed issues to changelog. Default is true
|
||||
--[no-]issues-without-labels Include closed issues without any labels to changelog. Default is true
|
||||
--[no-]pull-requests Include pull-requests to changelog. Default is true
|
||||
-l, --last-changes Generate log between last 2 tags only
|
||||
--[no-]author Add author of pull-request in the end. Default is true
|
||||
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y
|
||||
-o, --output [NAME] Output file. Default is CHANGELOG.md
|
||||
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement'
|
||||
-v, --version Print version number
|
||||
|
||||
|
||||
## FAQ:
|
||||
### GitHub token
|
||||
|
||||
Since GitHub allow to make only 50 requests without authentication it's recommended to run this script with token
|
||||
|
||||
**You can easily [generate it here](https://github.com/settings/applications)**.
|
||||
|
||||
And:
|
||||
|
||||
- Run with key `-t [your-16-digit-token]` that
|
||||
- Run with key `-t [your-16-digit-token]`
|
||||
- Or set environment variable `CHANGELOG_GITHUB_TOKEN` and specify there your token.
|
||||
|
||||
i.e. add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string `export CHANGELOG_GITHUB_TOKEN="your-40-digit-github-token"'`
|
||||
@@ -65,6 +64,19 @@ So, if you got error like this:
|
||||
|
||||
It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP.
|
||||
|
||||
## Examples:
|
||||
|
||||
- Look at **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for **this** project
|
||||
- [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md) was generated by command:
|
||||
|
||||
github_changelog_generator -u skywinder -p ActionSheetPicker-3.0
|
||||
|
||||
|
||||
## Projects using this library
|
||||
[Wikipage with list of projects](https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator)
|
||||
|
||||
*If you are using `github_changelog_generator` for generation chamgelog in your project or know of project that uses it, please add it to [this] (https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator) list.*
|
||||
|
||||
## Am I missed some essential feature?
|
||||
|
||||
**Nothing is impossible!** Open an [issue](https://github.com/skywinder/Github-Changelog-Generator/issues/new) and let's make generator better together!
|
||||
@@ -83,3 +95,7 @@ It's time to create this token or wait for 1 hour before GitHub reset the counte
|
||||
## License
|
||||
|
||||
Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
||||
|
||||
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
||||
|
||||
9
Rakefile
Normal file
9
Rakefile
Normal file
@@ -0,0 +1,9 @@
|
||||
require "rake/testtask"
|
||||
|
||||
task :default => [:test]
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.verbose = true
|
||||
t.libs.push("demo", "test")
|
||||
t.pattern = "test/**/*_test.rb"
|
||||
end
|
||||
@@ -4,6 +4,7 @@ require 'github_api'
|
||||
require 'json'
|
||||
require 'colorize'
|
||||
require_relative 'github_changelog_generator/parser'
|
||||
require_relative 'github_changelog_generator/generator'
|
||||
require_relative 'github_changelog_generator/version'
|
||||
|
||||
module GitHubChangelogGenerator
|
||||
@@ -15,6 +16,12 @@ module GitHubChangelogGenerator
|
||||
|
||||
@options = Parser.parse_options
|
||||
|
||||
if options[:verbose]
|
||||
puts 'Input options:'
|
||||
pp options
|
||||
puts ''
|
||||
end
|
||||
|
||||
github_token
|
||||
|
||||
if @github_token.nil?
|
||||
@@ -23,9 +30,15 @@ module GitHubChangelogGenerator
|
||||
@github = Github.new oauth_token: @github_token
|
||||
end
|
||||
|
||||
@generator = Generator.new(@options)
|
||||
|
||||
@all_tags = self.get_all_tags
|
||||
@pull_requests = self.get_all_closed_pull_requests
|
||||
@issues = self.get_all_issues
|
||||
if @options[:issues]
|
||||
@issues = self.get_all_issues
|
||||
else
|
||||
@issues = []
|
||||
end
|
||||
|
||||
@tag_times_hash = {}
|
||||
end
|
||||
@@ -35,12 +48,17 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
def exec_command(cmd)
|
||||
exec_cmd = "cd #{$project_path} && #{cmd}"
|
||||
exec_cmd = "cd #{$project_path} and #{cmd}"
|
||||
%x[#{exec_cmd}]
|
||||
end
|
||||
|
||||
|
||||
def get_all_closed_pull_requests
|
||||
|
||||
if @options[:verbose]
|
||||
puts 'Fetching pull requests..'
|
||||
end
|
||||
|
||||
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||
|
||||
pull_requests = []
|
||||
@@ -49,7 +67,38 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Receive all pull requests: #{pull_requests.count}"
|
||||
puts "Received all closed pull requests: #{pull_requests.count}"
|
||||
end
|
||||
|
||||
unless @options[:pull_request_labels].nil?
|
||||
|
||||
if @options[:verbose]
|
||||
puts 'Filter all pull requests by labels.'
|
||||
end
|
||||
|
||||
filtered_pull_requests = pull_requests.select { |pull_request|
|
||||
#We need issue to fetch labels
|
||||
issue = @github.issues.get @options[:user], @options[:project], pull_request.number
|
||||
#compare is there any labels from @options[:labels] array
|
||||
select_no_label = !issue.labels.map { |label| label.name }.any?
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Filter request \##{issue.number}."
|
||||
end
|
||||
|
||||
if @options[:pull_request_labels].any?
|
||||
select_by_label = (issue.labels.map { |label| label.name } & @options[:pull_request_labels]).any?
|
||||
else
|
||||
select_by_label = false
|
||||
end
|
||||
|
||||
select_by_label | select_no_label
|
||||
}
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Filtered pull requests with specified labels and w/o labels: #{filtered_pull_requests.count}"
|
||||
end
|
||||
return filtered_pull_requests
|
||||
end
|
||||
|
||||
pull_requests
|
||||
@@ -64,8 +113,7 @@ module GitHubChangelogGenerator
|
||||
|
||||
if @options[:last]
|
||||
log += self.generate_log_between_tags(self.all_tags[0], self.all_tags[1])
|
||||
elsif @options[:tag1] && @options[:tag2]
|
||||
|
||||
elsif @options[:tag1] and @options[:tag2]
|
||||
tag1 = @options[:tag1]
|
||||
tag2 = @options[:tag2]
|
||||
tags_strings = []
|
||||
@@ -94,7 +142,7 @@ module GitHubChangelogGenerator
|
||||
output_filename = "#{@options[:output]}"
|
||||
File.open(output_filename, 'w') { |file| file.write(log) }
|
||||
|
||||
puts "Done! Generated log placed in #{output_filename}"
|
||||
puts "Done! Generated log placed in #{`pwd`.strip!}/#{output_filename}"
|
||||
|
||||
end
|
||||
|
||||
@@ -113,11 +161,11 @@ module GitHubChangelogGenerator
|
||||
puts "Generating log.."
|
||||
end
|
||||
|
||||
for index in 1 ... self.all_tags.size
|
||||
(1 ... self.all_tags.size).each { |index|
|
||||
log += self.generate_log_between_tags(self.all_tags[index], self.all_tags[index-1])
|
||||
end
|
||||
}
|
||||
|
||||
log += self.generate_log_before_tag(self.all_tags.last)
|
||||
log += generate_log_between_tags(nil, self.all_tags.last)
|
||||
|
||||
log
|
||||
end
|
||||
@@ -128,11 +176,8 @@ module GitHubChangelogGenerator
|
||||
|
||||
def get_all_tags
|
||||
|
||||
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
|
||||
|
||||
if @options[:verbose]
|
||||
|
||||
puts "Receive tags for repo #{url}"
|
||||
puts 'Fetching all tags..'
|
||||
end
|
||||
|
||||
response = @github.repos.tags @options[:user], @options[:project]
|
||||
@@ -167,90 +212,54 @@ module GitHubChangelogGenerator
|
||||
|
||||
|
||||
def generate_log_between_tags(older_tag, newer_tag)
|
||||
older_tag_time = self.get_time_of_tag(older_tag)
|
||||
|
||||
newer_tag_time = self.get_time_of_tag(newer_tag)
|
||||
|
||||
# if we mix up tags order - lits fix it!
|
||||
# if older_tag_time < newer_tag_time
|
||||
# older_tag, newer_tag = newer_tag, older_tag
|
||||
# older_tag_time, newer_tag_time = newer_tag_time, older_tag_time
|
||||
# puts "Swap tags!"
|
||||
# end
|
||||
|
||||
newer_tag_name = newer_tag['name']
|
||||
|
||||
pull_requests = Array.new(@pull_requests)
|
||||
if older_tag.nil?
|
||||
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
|
||||
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time)
|
||||
else
|
||||
older_tag_time = self.get_time_of_tag(older_tag)
|
||||
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time)
|
||||
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
|
||||
end
|
||||
|
||||
pull_requests.delete_if { |req|
|
||||
if req[:merged_at]
|
||||
t = Time.parse(req[:merged_at]).utc
|
||||
tag_is_older_of_older = t > older_tag_time
|
||||
tag_is_newer_than_new = t <= newer_tag_time
|
||||
|
||||
tag_not_in_range = (tag_is_older_of_older) && (tag_is_newer_than_new)
|
||||
!tag_not_in_range
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
issues = Array.new(@issues)
|
||||
|
||||
issues.delete_if { |issue|
|
||||
if issue[:closed_at]
|
||||
t = Time.parse(issue[:closed_at]).utc
|
||||
tag_is_later_since = t > older_tag_time
|
||||
tag_is_before_till = t <= newer_tag_time
|
||||
|
||||
in_range = (tag_is_later_since) && (tag_is_before_till)
|
||||
!in_range
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
self.create_log(pull_requests, issues, newer_tag_name, newer_tag_time)
|
||||
self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time)
|
||||
|
||||
end
|
||||
|
||||
def generate_log_before_tag(tag)
|
||||
tag_time = self.get_time_of_tag(tag)
|
||||
tag_name = tag['name']
|
||||
def delete_by_time(array, hash_key, newer_tag_time, older_tag_time = nil)
|
||||
array.select { |req|
|
||||
if req[hash_key]
|
||||
t = Time.parse(req[hash_key]).utc
|
||||
|
||||
pull_requests = Array.new(@pull_requests)
|
||||
if older_tag_time.nil?
|
||||
tag_in_range_old = true
|
||||
else
|
||||
tag_in_range_old = t > older_tag_time
|
||||
end
|
||||
|
||||
pull_requests.delete_if { |req|
|
||||
if req[:merged_at]
|
||||
t = Time.parse(req[:merged_at]).utc
|
||||
t > tag_time
|
||||
tag_in_range_new = t <= newer_tag_time
|
||||
|
||||
tag_in_range = (tag_in_range_old) && (tag_in_range_new)
|
||||
|
||||
tag_in_range
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
}
|
||||
|
||||
issues = Array.new(@issues)
|
||||
|
||||
issues.delete_if { |issue|
|
||||
if issue[:closed_at]
|
||||
t = Time.parse(issue[:closed_at]).utc
|
||||
t > tag_time
|
||||
else
|
||||
true
|
||||
false
|
||||
end
|
||||
}
|
||||
|
||||
self.create_log(pull_requests, issues, tag_name, tag_time)
|
||||
|
||||
end
|
||||
|
||||
# @param [Array] pull_requests
|
||||
# @param [Array] issues
|
||||
# @param [String] tag_name
|
||||
# @param [String] tag_time
|
||||
# @return [String]
|
||||
def create_log(pull_requests, issues, tag_name, tag_time)
|
||||
|
||||
# Generate tag name and link
|
||||
trimmed_tag = tag_name.tr('v', '')
|
||||
log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
|
||||
log = "## [#{tag_name}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
|
||||
|
||||
#Generate date string:
|
||||
time_string = tag_time.strftime @options[:format]
|
||||
@@ -258,12 +267,11 @@ module GitHubChangelogGenerator
|
||||
|
||||
if @options[:pulls]
|
||||
# Generate pull requests:
|
||||
if pull_requests
|
||||
pull_requests.each { |dict|
|
||||
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
||||
log += "- #{merge}"
|
||||
}
|
||||
end
|
||||
pull_requests.each { |pull_request|
|
||||
merge = @generator.get_string_for_pull_request(pull_request)
|
||||
log += "- #{merge}"
|
||||
|
||||
} if pull_requests
|
||||
end
|
||||
|
||||
if @options[:issues]
|
||||
@@ -306,7 +314,9 @@ module GitHubChangelogGenerator
|
||||
intro = 'Implemented enhancement'
|
||||
end
|
||||
|
||||
merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
||||
enc_string = @generator.encapsulate_string dict[:title]
|
||||
|
||||
merge = "*#{intro}:* #{enc_string} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
||||
log += "- #{merge}"
|
||||
}
|
||||
end
|
||||
@@ -330,8 +340,8 @@ module GitHubChangelogGenerator
|
||||
end
|
||||
|
||||
def get_all_issues
|
||||
response = @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
|
||||
|
||||
issues = []
|
||||
response.each_page do |page|
|
||||
@@ -344,7 +354,7 @@ module GitHubChangelogGenerator
|
||||
}
|
||||
|
||||
if @options[:verbose]
|
||||
puts "Receive all closed issues: #{issues.count}"
|
||||
puts "Received closed issues: #{issues.count}"
|
||||
end
|
||||
|
||||
filtered_issues = issues.select { |issue|
|
||||
|
||||
34
lib/github_changelog_generator/generator.rb
Normal file
34
lib/github_changelog_generator/generator.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
module GitHubChangelogGenerator
|
||||
class Generator
|
||||
|
||||
def initialize(options = nil)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def get_string_for_pull_request(pull_request)
|
||||
encapsulated_title = self.encapsulate_string pull_request[:title]
|
||||
|
||||
merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})"
|
||||
if @options[:author]
|
||||
merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n"
|
||||
else
|
||||
merge += "\n\n"
|
||||
end
|
||||
merge
|
||||
end
|
||||
|
||||
def encapsulate_string(string)
|
||||
|
||||
string.gsub! '\\', '\\\\'
|
||||
|
||||
encpas_chars = %w(> * _ \( \) [ ])
|
||||
encpas_chars.each{ |char|
|
||||
string.gsub! char, "\\#{char}"
|
||||
}
|
||||
|
||||
string
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'optparse'
|
||||
require 'PP'
|
||||
require_relative 'version'
|
||||
|
||||
module GitHubChangelogGenerator
|
||||
class Parser
|
||||
def self.parse_options
|
||||
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* '}
|
||||
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :pull_request_labels => nil}
|
||||
|
||||
parser = OptionParser.new { |opts|
|
||||
opts.banner = 'Usage: changelog_generator [options]'
|
||||
@@ -15,12 +16,14 @@ module GitHubChangelogGenerator
|
||||
opts.on('-p', '--project [PROJECT]', 'Name of project on GitHub') do |last|
|
||||
options[:project] = last
|
||||
end
|
||||
opts.on('-t', '--token [TOKEN]', 'To make more than 50 requests this script required your OAuth token for GitHub. You can generate here: https://github.com/settings/tokens/new') do |last|
|
||||
opts.on('-t', '--token [TOKEN]', 'To make more than 50 requests per hour your GitHub token required. You can generate it here: https://github.com/settings/tokens/new') do |last|
|
||||
options[:token] = last
|
||||
end
|
||||
opts.on('-h', '--help', 'Displays Help') do
|
||||
puts opts
|
||||
exit
|
||||
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
||||
options[:format] = last
|
||||
end
|
||||
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
||||
options[:output] = last
|
||||
end
|
||||
opts.on('--[no-]verbose', 'Run verbosely. Default is true') do |v|
|
||||
options[:verbose] = v
|
||||
@@ -34,22 +37,23 @@ module GitHubChangelogGenerator
|
||||
opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
|
||||
options[:pulls] = v
|
||||
end
|
||||
opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
|
||||
options[:last] = last
|
||||
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
|
||||
options[:last] = author
|
||||
end
|
||||
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
||||
options[:format] = last
|
||||
end
|
||||
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
||||
options[:output] = last
|
||||
end
|
||||
opts.on('--labels x,y,z', Array, 'List of labels. Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
|
||||
opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
|
||||
options[:labels] = list
|
||||
end
|
||||
opts.on('--labels-pr x,y,z', Array, 'Only pull requests with specified labels will be included to changelog. Default is nil') do |list|
|
||||
options[:pull_request_labels] = list
|
||||
end
|
||||
opts.on('-v', '--version', 'Print version number') do |v|
|
||||
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
||||
exit
|
||||
end
|
||||
opts.on('-h', '--help', 'Displays Help') do
|
||||
puts opts
|
||||
exit
|
||||
end
|
||||
}
|
||||
|
||||
parser.parse!
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module GitHubChangelogGenerator
|
||||
VERSION = '1.1.4'
|
||||
VERSION = '1.2.2'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user