Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcc1c608a2 | ||
|
|
46ae40f250 | ||
|
|
00f98b8ca6 | ||
|
|
5da838efee | ||
|
|
73b789ab82 | ||
|
|
b5778b14a0 | ||
|
|
e29ff3c3a9 | ||
|
|
9646b49add | ||
|
|
a44b0bdd25 | ||
|
|
433d46d85b | ||
|
|
950e8916d9 | ||
|
|
87c6e33335 | ||
|
|
4488ac8cc6 | ||
|
|
c697c6be4a | ||
|
|
69dd5eadc2 | ||
|
|
4ea1058cd5 | ||
|
|
fcd78e6bc4 | ||
|
|
e6c0d49200 | ||
|
|
0f5db97474 | ||
|
|
0901b38577 | ||
|
|
2a24f49a83 | ||
|
|
2ad014d5c7 | ||
|
|
188ba7e073 | ||
|
|
6f53fe0a1d | ||
|
|
2c7853cf9f | ||
|
|
6830ea49f2 | ||
|
|
5be1a2afaf | ||
|
|
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 | ||
|
|
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]
|
||||||
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,12 +1,22 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.2.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2)
|
||||||
|
#### 10/12/14
|
||||||
|
- *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef))
|
||||||
|
|
||||||
|
## [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))
|
||||||
|
|
||||||
|
- *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)
|
## [1.2.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0)
|
||||||
#### 19/11/14
|
#### 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:* 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:* Test Pull-Request SHOULD NOT APPEAR IN LOG! [\#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:* 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))
|
- *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))
|
||||||
|
|
||||||
@@ -14,7 +24,7 @@
|
|||||||
#### 18/11/14
|
#### 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))
|
- *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)
|
- *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)
|
- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20)
|
||||||
|
|
||||||
@@ -60,7 +70,7 @@
|
|||||||
#### 07/11/14
|
#### 07/11/14
|
||||||
- *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 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) ([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) ([skywinder](https://github.com/skywinder))
|
||||||
|
|
||||||
## [0.0.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2)
|
## [0.0.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2)
|
||||||
#### 06/11/14
|
#### 06/11/14
|
||||||
|
|||||||
3
Gemfile
3
Gemfile
@@ -1,3 +1,4 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gem 'github_api'
|
gem 'github_api'
|
||||||
gem 'colorize'
|
gem 'colorize'
|
||||||
|
gem 'rake'
|
||||||
|
|||||||
10
Gemfile.lock
10
Gemfile.lock
@@ -2,7 +2,7 @@ GEM
|
|||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
addressable (2.3.6)
|
addressable (2.3.6)
|
||||||
colorize (0.7.3)
|
colorize (0.7.4)
|
||||||
descendants_tracker (0.0.4)
|
descendants_tracker (0.0.4)
|
||||||
thread_safe (~> 0.3, >= 0.3.1)
|
thread_safe (~> 0.3, >= 0.3.1)
|
||||||
faraday (0.9.0)
|
faraday (0.9.0)
|
||||||
@@ -15,13 +15,13 @@ GEM
|
|||||||
multi_json (>= 1.7.5, < 2.0)
|
multi_json (>= 1.7.5, < 2.0)
|
||||||
nokogiri (~> 1.6.3)
|
nokogiri (~> 1.6.3)
|
||||||
oauth2
|
oauth2
|
||||||
hashie (3.3.1)
|
hashie (3.3.2)
|
||||||
jwt (1.0.0)
|
jwt (1.2.0)
|
||||||
mini_portile (0.6.1)
|
mini_portile (0.6.1)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
multi_xml (0.5.5)
|
multi_xml (0.5.5)
|
||||||
multipart-post (2.0.0)
|
multipart-post (2.0.0)
|
||||||
nokogiri (1.6.4)
|
nokogiri (1.6.5)
|
||||||
mini_portile (~> 0.6.0)
|
mini_portile (~> 0.6.0)
|
||||||
oauth2 (1.0.0)
|
oauth2 (1.0.0)
|
||||||
faraday (>= 0.8, < 0.10)
|
faraday (>= 0.8, < 0.10)
|
||||||
@@ -30,6 +30,7 @@ GEM
|
|||||||
multi_xml (~> 0.5)
|
multi_xml (~> 0.5)
|
||||||
rack (~> 1.2)
|
rack (~> 1.2)
|
||||||
rack (1.5.2)
|
rack (1.5.2)
|
||||||
|
rake (10.4.2)
|
||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
@@ -38,3 +39,4 @@ PLATFORMS
|
|||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
colorize
|
colorize
|
||||||
github_api
|
github_api
|
||||||
|
rake
|
||||||
|
|||||||
34
README.md
34
README.md
@@ -2,6 +2,7 @@ GitHub Changelog Generator
|
|||||||
==================
|
==================
|
||||||
|
|
||||||
[](http://badge.fury.io/rb/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.
|
Changelog generation has never been so easy.
|
||||||
|
|
||||||
@@ -15,17 +16,17 @@ You're almost done!
|
|||||||
## Usage
|
## Usage
|
||||||
**It's really simple**:
|
**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
|
github_changelog_generator
|
||||||
|
|
||||||
- from anywhere:
|
- or from anywhere:
|
||||||
|
|
||||||
github_changelog_generator -u github-username -p github-project
|
github_changelog_generator -u github-username -p github-project
|
||||||
|
|
||||||
As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* changelog.
|
As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* changelog.
|
||||||
|
|
||||||
## Params:
|
### Params:
|
||||||
Type `github_changelog_generator --help` for detailed usage.
|
Type `github_changelog_generator --help` for detailed usage.
|
||||||
|
|
||||||
Usage: changelog_generator [options]
|
Usage: changelog_generator [options]
|
||||||
@@ -44,22 +45,16 @@ Type `github_changelog_generator --help` for detailed usage.
|
|||||||
--labels x,y,z List of labels. Issues with that labels will be included to changelog. Default is 'bug,enhancement'
|
--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
|
-v, --version Print version number
|
||||||
|
|
||||||
## Examples:
|
|
||||||
|
|
||||||
- Look at **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for **this** project
|
### GitHub token
|
||||||
- [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
|
|
||||||
|
|
||||||
|
|
||||||
## FAQ:
|
|
||||||
Since GitHub allow to make only 50 requests without authentication it's recommended to run this script with 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)**.
|
**You can easily [generate it here](https://github.com/settings/applications)**.
|
||||||
|
|
||||||
And:
|
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.
|
- 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"'`
|
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"'`
|
||||||
@@ -69,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.
|
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?
|
## 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!
|
**Nothing is impossible!** Open an [issue](https://github.com/skywinder/Github-Changelog-Generator/issues/new) and let's make generator better together!
|
||||||
@@ -87,3 +95,7 @@ It's time to create this token or wait for 1 hour before GitHub reset the counte
|
|||||||
## License
|
## License
|
||||||
|
|
||||||
Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
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
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
require 'github_api'
|
require 'github_api'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'colorize'
|
require 'colorize'
|
||||||
|
require 'benchmark'
|
||||||
|
|
||||||
require_relative 'github_changelog_generator/parser'
|
require_relative 'github_changelog_generator/parser'
|
||||||
|
require_relative 'github_changelog_generator/generator'
|
||||||
require_relative 'github_changelog_generator/version'
|
require_relative 'github_changelog_generator/version'
|
||||||
|
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
@@ -11,6 +14,8 @@ module GitHubChangelogGenerator
|
|||||||
|
|
||||||
attr_accessor :options, :all_tags, :github
|
attr_accessor :options, :all_tags, :github
|
||||||
|
|
||||||
|
PER_PAGE_NUMBER = 30
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|
||||||
@options = Parser.parse_options
|
@options = Parser.parse_options
|
||||||
@@ -24,11 +29,14 @@ module GitHubChangelogGenerator
|
|||||||
github_token
|
github_token
|
||||||
|
|
||||||
if @github_token.nil?
|
if @github_token.nil?
|
||||||
@github = Github.new
|
@github = Github.new per_page: PER_PAGE_NUMBER
|
||||||
else
|
else
|
||||||
@github = Github.new oauth_token: @github_token
|
@github = Github.new oauth_token: @github_token,
|
||||||
|
per_page: PER_PAGE_NUMBER
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@generator = Generator.new(@options)
|
||||||
|
|
||||||
@all_tags = self.get_all_tags
|
@all_tags = self.get_all_tags
|
||||||
@pull_requests = self.get_all_closed_pull_requests
|
@pull_requests = self.get_all_closed_pull_requests
|
||||||
if @options[:issues]
|
if @options[:issues]
|
||||||
@@ -53,18 +61,23 @@ module GitHubChangelogGenerator
|
|||||||
def get_all_closed_pull_requests
|
def get_all_closed_pull_requests
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts 'Fetching pull requests..'
|
print "Fetching pull requests...\r"
|
||||||
end
|
end
|
||||||
|
|
||||||
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
|
||||||
|
|
||||||
pull_requests = []
|
pull_requests = []
|
||||||
|
page_i = 0
|
||||||
response.each_page do |page|
|
response.each_page do |page|
|
||||||
|
page_i += PER_PAGE_NUMBER
|
||||||
|
print "Fetching pull requests... #{page_i}\r"
|
||||||
pull_requests.concat(page)
|
pull_requests.concat(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print "\r"
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Received all closed pull requests: #{pull_requests.count}"
|
puts "Received closed pull requests: #{pull_requests.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless @options[:pull_request_labels].nil?
|
unless @options[:pull_request_labels].nil?
|
||||||
@@ -111,7 +124,6 @@ module GitHubChangelogGenerator
|
|||||||
if @options[:last]
|
if @options[:last]
|
||||||
log += self.generate_log_between_tags(self.all_tags[0], self.all_tags[1])
|
log += self.generate_log_between_tags(self.all_tags[0], self.all_tags[1])
|
||||||
elsif @options[:tag1] and @options[:tag2]
|
elsif @options[:tag1] and @options[:tag2]
|
||||||
|
|
||||||
tag1 = @options[:tag1]
|
tag1 = @options[:tag1]
|
||||||
tag2 = @options[:tag2]
|
tag2 = @options[:tag2]
|
||||||
tags_strings = []
|
tags_strings = []
|
||||||
@@ -140,14 +152,19 @@ module GitHubChangelogGenerator
|
|||||||
output_filename = "#{@options[:output]}"
|
output_filename = "#{@options[:output]}"
|
||||||
File.open(output_filename, 'w') { |file| file.write(log) }
|
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
|
end
|
||||||
|
|
||||||
def generate_log_for_all_tags
|
def generate_log_for_all_tags
|
||||||
log = ''
|
log = ''
|
||||||
@all_tags.each { |tag| self.get_time_of_tag(tag) }
|
|
||||||
|
|
||||||
|
# Async fetching tags:
|
||||||
|
threads = []
|
||||||
|
@all_tags.each { |tag|
|
||||||
|
threads << Thread.new { self.get_time_of_tag(tag) }
|
||||||
|
}
|
||||||
|
threads.each { |thr| thr.join }
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Sorting tags.."
|
puts "Sorting tags.."
|
||||||
@@ -159,11 +176,11 @@ module GitHubChangelogGenerator
|
|||||||
puts "Generating log.."
|
puts "Generating log.."
|
||||||
end
|
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])
|
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
|
log
|
||||||
end
|
end
|
||||||
@@ -175,16 +192,19 @@ module GitHubChangelogGenerator
|
|||||||
def get_all_tags
|
def get_all_tags
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts 'Fetching all tags..'
|
print "Fetching tags...\r"
|
||||||
end
|
end
|
||||||
|
|
||||||
response = @github.repos.tags @options[:user], @options[:project]
|
response = @github.repos.tags @options[:user], @options[:project]
|
||||||
|
|
||||||
tags = []
|
tags = []
|
||||||
|
page_i = 0
|
||||||
response.each_page do |page|
|
response.each_page do |page|
|
||||||
|
page_i += PER_PAGE_NUMBER
|
||||||
|
print "Fetching tags... #{page_i}\r"
|
||||||
tags.concat(page)
|
tags.concat(page)
|
||||||
end
|
end
|
||||||
|
print "\r"
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Found #{tags.count} tags"
|
puts "Found #{tags.count} tags"
|
||||||
end
|
end
|
||||||
@@ -216,14 +236,14 @@ module GitHubChangelogGenerator
|
|||||||
|
|
||||||
if older_tag.nil?
|
if older_tag.nil?
|
||||||
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
|
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
|
||||||
issues = delete_by_time(@issues, :closed_at, newer_tag_time)
|
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time)
|
||||||
else
|
else
|
||||||
older_tag_time = self.get_time_of_tag(older_tag)
|
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_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time)
|
||||||
issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
|
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.create_log(filtered_pull_requests, issues, newer_tag_name, newer_tag_time)
|
self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -241,7 +261,7 @@ module GitHubChangelogGenerator
|
|||||||
tag_in_range_new = t <= newer_tag_time
|
tag_in_range_new = t <= newer_tag_time
|
||||||
|
|
||||||
tag_in_range = (tag_in_range_old) && (tag_in_range_new)
|
tag_in_range = (tag_in_range_old) && (tag_in_range_new)
|
||||||
|
|
||||||
tag_in_range
|
tag_in_range
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
@@ -249,15 +269,15 @@ module GitHubChangelogGenerator
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_log_before_tag(tag)
|
# @param [Array] pull_requests
|
||||||
generate_log_between_tags(nil, tag)
|
# @param [Array] issues
|
||||||
end
|
# @param [String] tag_name
|
||||||
|
# @param [String] tag_time
|
||||||
|
# @return [String]
|
||||||
def create_log(pull_requests, issues, tag_name, tag_time)
|
def create_log(pull_requests, issues, tag_name, tag_time)
|
||||||
|
|
||||||
# Generate tag name and link
|
# Generate tag name and link
|
||||||
trimmed_tag = tag_name.tr('v', '')
|
log = "## [#{tag_name}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
|
||||||
log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
|
|
||||||
|
|
||||||
#Generate date string:
|
#Generate date string:
|
||||||
time_string = tag_time.strftime @options[:format]
|
time_string = tag_time.strftime @options[:format]
|
||||||
@@ -265,20 +285,11 @@ module GitHubChangelogGenerator
|
|||||||
|
|
||||||
if @options[:pulls]
|
if @options[:pulls]
|
||||||
# Generate pull requests:
|
# Generate pull requests:
|
||||||
if pull_requests
|
pull_requests.each { |pull_request|
|
||||||
if @options[:author]
|
merge = @generator.get_string_for_pull_request(pull_request)
|
||||||
pull_requests.each { |dict|
|
log += "- #{merge}"
|
||||||
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url}) ([#{dict.user.login}](#{dict.user.html_url}))\n\n"
|
|
||||||
log += "- #{merge}"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
pull_requests.each { |dict|
|
|
||||||
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
|
||||||
log += "- #{merge}"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
} if pull_requests
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:issues]
|
if @options[:issues]
|
||||||
@@ -321,7 +332,9 @@ module GitHubChangelogGenerator
|
|||||||
intro = 'Implemented enhancement'
|
intro = 'Implemented enhancement'
|
||||||
end
|
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}"
|
log += "- #{merge}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -334,10 +347,6 @@ module GitHubChangelogGenerator
|
|||||||
return @tag_times_hash[prev_tag['name']]
|
return @tag_times_hash[prev_tag['name']]
|
||||||
end
|
end
|
||||||
|
|
||||||
if @options[:verbose]
|
|
||||||
puts "Getting time for tag #{prev_tag['name']}"
|
|
||||||
end
|
|
||||||
|
|
||||||
github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], prev_tag['commit']['sha']
|
github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], prev_tag['commit']['sha']
|
||||||
time_string = github_git_data_commits_get['committer']['date']
|
time_string = github_git_data_commits_get['committer']['date']
|
||||||
Time.parse(time_string)
|
Time.parse(time_string)
|
||||||
@@ -346,13 +355,22 @@ module GitHubChangelogGenerator
|
|||||||
|
|
||||||
def get_all_issues
|
def get_all_issues
|
||||||
|
|
||||||
|
if @options[:verbose]
|
||||||
|
print "Fetching closed issues...\r"
|
||||||
|
end
|
||||||
|
|
||||||
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 = []
|
issues = []
|
||||||
|
page_i = 0
|
||||||
response.each_page do |page|
|
response.each_page do |page|
|
||||||
|
page_i += PER_PAGE_NUMBER
|
||||||
|
print "Fetching closed issues... #{page_i}\r"
|
||||||
issues.concat(page)
|
issues.concat(page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print "\r"
|
||||||
|
|
||||||
# remove pull request from issues:
|
# remove pull request from issues:
|
||||||
issues.select! { |x|
|
issues.select! { |x|
|
||||||
x.pull_request == nil
|
x.pull_request == nil
|
||||||
@@ -362,6 +380,11 @@ module GitHubChangelogGenerator
|
|||||||
puts "Received closed issues: #{issues.count}"
|
puts "Received closed issues: #{issues.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if @options[:verbose]
|
||||||
|
puts "Filtering issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}"
|
||||||
|
end
|
||||||
|
|
||||||
filtered_issues = issues.select { |issue|
|
filtered_issues = issues.select { |issue|
|
||||||
#compare is there any labels from @options[:labels] array
|
#compare is there any labels from @options[:labels] array
|
||||||
(issue.labels.map { |label| label.name } & @options[:labels]).any?
|
(issue.labels.map { |label| label.name } & @options[:labels]).any?
|
||||||
@@ -376,7 +399,7 @@ module GitHubChangelogGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Filter issues with labels #{@options[:labels]}#{@options[:add_issues_wo_labels] ? ' and w/o labels' : ''}: #{filtered_issues.count} issues"
|
puts "Filtered issues: #{filtered_issues.count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
filtered_issues
|
filtered_issues
|
||||||
|
|||||||
38
lib/github_changelog_generator/generator.rb
Normal file
38
lib/github_changelog_generator/generator.rb
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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]
|
||||||
|
if !pull_request.user.nil?
|
||||||
|
merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n"
|
||||||
|
else
|
||||||
|
merge += " ({Null user})\n\n"
|
||||||
|
end
|
||||||
|
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
|
||||||
@@ -16,12 +16,14 @@ module GitHubChangelogGenerator
|
|||||||
opts.on('-p', '--project [PROJECT]', 'Name of project on GitHub') do |last|
|
opts.on('-p', '--project [PROJECT]', 'Name of project on GitHub') do |last|
|
||||||
options[:project] = last
|
options[:project] = last
|
||||||
end
|
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
|
options[:token] = last
|
||||||
end
|
end
|
||||||
opts.on('-h', '--help', 'Displays Help') do
|
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
|
||||||
puts opts
|
options[:format] = last
|
||||||
exit
|
end
|
||||||
|
opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last|
|
||||||
|
options[:output] = last
|
||||||
end
|
end
|
||||||
opts.on('--[no-]verbose', 'Run verbosely. Default is true') do |v|
|
opts.on('--[no-]verbose', 'Run verbosely. Default is true') do |v|
|
||||||
options[:verbose] = v
|
options[:verbose] = v
|
||||||
@@ -35,41 +37,42 @@ module GitHubChangelogGenerator
|
|||||||
opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
|
opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v|
|
||||||
options[:pulls] = v
|
options[:pulls] = v
|
||||||
end
|
end
|
||||||
opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
|
|
||||||
options[:last] = last
|
|
||||||
end
|
|
||||||
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
|
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
|
||||||
options[:last] = author
|
options[:last] = author
|
||||||
end
|
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, '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
|
options[:labels] = list
|
||||||
end
|
end
|
||||||
opts.on('--filter-pull-requests x,y,z', Array, 'Pull requests with that labels will be included to changelog. pull requests w\o labels will be included anyway.') do |list|
|
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
|
options[:pull_request_labels] = list
|
||||||
end
|
end
|
||||||
opts.on('-v', '--version', 'Print version number') do |v|
|
opts.on('-v', '--version', 'Print version number') do |v|
|
||||||
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
opts.on('-h', '--help', 'Displays Help') do
|
||||||
|
puts opts
|
||||||
|
exit
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.parse!
|
parser.parse!
|
||||||
|
|
||||||
#udefined case with 1 parameter:
|
|
||||||
if ARGV[0] && !ARGV[1]
|
if ARGV[0] && !ARGV[1]
|
||||||
puts parser.banner
|
# this match should parse https://github.com/skywinder/Github-Changelog-Generator and skywinder/Github-Changelog-Generator to user and name
|
||||||
exit
|
match = /(?:.+github\.com\/)?(.+)\/(.+)/.match(ARGV[0])
|
||||||
|
|
||||||
|
if match[2].nil?
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
options[:user] = match[1]
|
||||||
|
options[:project]= match[2]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !options[:user] && !options[:project]
|
if !options[:user] && !options[:project]
|
||||||
remote = `git remote -vv`.split("\n")
|
remote = `git remote -vv`.split("\n")
|
||||||
match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)\.git.*/.match(remote[0])
|
match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git)?.*/.match(remote[0])
|
||||||
|
|
||||||
if match && match[1] && match[2]
|
if match && match[1] && match[2]
|
||||||
puts "Detected user:#{match[1]}, project:#{match[2]}"
|
puts "Detected user:#{match[1]}, project:#{match[2]}"
|
||||||
@@ -86,7 +89,6 @@ module GitHubChangelogGenerator
|
|||||||
if ARGV[1]
|
if ARGV[1]
|
||||||
options[:tag1] = ARGV[0]
|
options[:tag1] = ARGV[0]
|
||||||
options[:tag2] = ARGV[1]
|
options[:tag2] = ARGV[1]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
options
|
options
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
VERSION = '1.2.1'
|
VERSION = '1.2.3'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user