Compare commits

...

55 Commits
1.1.4 ... 1.2.2

Author SHA1 Message Date
Petr Korolev
7be5021685 Merge branch 'release/1.2.2' 2014-12-10 12:18:58 +02:00
Petr Korolev
c3373b2343 Update gemspec to version 1.2.2 2014-12-10 12:18:56 +02:00
Petr Korolev
9aa156a02b improve script 2014-12-10 12:18:45 +02:00
Petr Korolev
68a8d8d2c8 fix trimming for issues 2014-12-10 12:18:45 +02:00
Petr Korolev
057fb488d5 create class and implement encapsulation. This fix #34 2014-12-10 12:18:45 +02:00
Petr Korolev
f1d9c839c7 optimize script 2014-12-10 12:18:44 +02:00
Petr Korolev
97d048d62f Merge branch 'develop' 2014-12-03 11:52:17 +02:00
Petr Korolev
7972ec0977 update yml 2014-12-03 11:51:59 +02:00
Petr Korolev
f55598825d Merge branch 'master' into develop 2014-12-03 11:43:00 +02:00
Petr Korolev
a678b52fe4 fc 2014-12-03 11:42:52 +02:00
Petr Korolev
aac04726ba Merge branch 'develop' 2014-12-03 11:42:02 +02:00
Petr Korolev
0c65035cde update readme 2014-12-03 11:40:54 +02:00
Petr Korolev
e038c7e680 Merge branch 'travis-update' into develop 2014-12-03 11:37:39 +02:00
Petr Korolev
bcecb4eb81 Revert "remove dep rake"
This reverts commit 326a067ac5.
2014-12-03 11:31:51 +02:00
Petr Korolev
52123885a1 add rakefile 2014-12-03 11:30:26 +02:00
Petr Korolev
326a067ac5 remove dep rake 2014-12-03 11:27:05 +02:00
Petr Korolev
5dcbef87d1 put back gem updates 2014-12-03 11:19:31 +02:00
Petr Korolev
caf264360b remove before install 2014-12-03 11:18:13 +02:00
Petr Korolev
bc13632545 add rake to gemfile 2014-12-03 11:09:11 +02:00
Petr Korolev
67b438f46b update gem 2014-12-02 18:09:18 +02:00
Petr Korolev
ff52291d2a Merge branch 'master' into travis-update
Conflicts:
	Gemfile
2014-12-02 18:03:55 +02:00
Petr Korolev
b2df1cfdcd Merge pull request #36 from bitdeli-chef/master
Add a Bitdeli Badge to README
2014-12-01 18:39:34 +02:00
Bitdeli Chef
f037a839ce Add a Bitdeli badge to README 2014-12-01 16:48:39 +00:00
Petr Korolev
5295389fcc update 2014-11-24 21:38:06 +02:00
Petr Korolev
8e5b4ed191 update 2014-11-24 21:37:10 +02:00
Petr Korolev
80cc3fc625 update parser 2014-11-24 21:33:03 +02:00
Petr Korolev
f087699d07 update readme 2014-11-24 21:20:46 +02:00
Petr Korolev
540df2ef51 UPdate changelog 2014-11-22 23:30:24 +02:00
Petr Korolev
54d029d8ea update readme 2014-11-22 23:18:17 +02:00
Petr Korolev
bec4fdef0e Update gemspec to version 1.2.1 2014-11-22 22:56:23 +02:00
Petr Korolev
b5d5615244 update readme 2014-11-21 10:59:12 +02:00
Petr Korolev
766569c27a update README 2014-11-19 22:16:41 +02:00
Petr Korolev
51e3c2ee54 Merge branch 'new-features' 2014-11-19 17:29:07 +02:00
Petr Korolev
e1e5de555b Issues for last tag not in list 2014-11-19 17:28:49 +02:00
Petr Korolev
0e4474bb2d Merge branch 'new-features' 2014-11-19 17:26:23 +02:00
Petr Korolev
fa4ccb7e9c gix bug in logic 2014-11-19 16:23:54 +02:00
Petr Korolev
36fbe509fa Merge branch 'new-features' 2014-11-19 15:59:39 +02:00
Petr Korolev
4c5ca562cf Disable default --filter-pull-requests option. 2014-11-19 15:58:14 +02:00
Petr Korolev
27432c3328 Merge branch 'new-features' 2014-11-19 15:49:42 +02:00
Petr Korolev
4a27872695 Update changelog for version 1.2.0 2014-11-19 15:49:22 +02:00
Petr Korolev
bf88bc0a0e Update gemspec to version 1.2.0 2014-11-19 15:48:32 +02:00
Petr Korolev
3b145bd7ed Merge branch 'filter-pull-requests' 2014-11-19 15:47:28 +02:00
Petr Korolev
97311bc5a0 add parse option --filter-pull-requests 2014-11-19 15:45:24 +02:00
Petr Korolev
bdc4657e2c add filter option 2014-11-19 15:04:10 +02:00
Petr Korolev
0c8a96aef8 update readme 2014-11-19 14:33:38 +02:00
Petr Korolev
c9462a6c9b Merge branch 'new-features' 2014-11-19 14:30:59 +02:00
Petr Korolev
0a43c25f8f Code refactoring 2014-11-19 14:30:18 +02:00
Petr Korolev
c58ec0dcbb Merge branch 'new-features' 2014-11-19 13:55:13 +02:00
Petr Korolev
7aa9b6ca47 Add ability to insert authors of pull-requests (--[no-]author option) 2014-11-19 13:53:36 +02:00
Petr Korolev
865a364dff pretty print for input options 2014-11-19 12:51:23 +02:00
Petr Korolev
062f3fd3f2 code cleanup 2014-11-19 12:43:55 +02:00
Petr Korolev
a4e9390283 Merge branch 'new-features' 2014-11-19 12:43:43 +02:00
Petr Korolev
09f5ac5d37 Don't receive issues in case of --no-isses flag specied 2014-11-19 12:42:23 +02:00
Petr Korolev
aed5c37559 Update changelog for version 1.1.4 2014-11-18 15:50:21 +02:00
Petr Korolev
a5c4899360 add travis configs 2014-11-12 11:03:46 +02:00
10 changed files with 250 additions and 143 deletions

15
.travis.yml Normal file
View 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]

View File

@@ -1,26 +1,42 @@
# Changelog # Changelog
## [1.1.3] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.3) ## [1.2.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1)
#### 18/11/14 #### 22/11/14
- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) - *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) - *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) ## [1.1.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2)
#### 12/11/14 #### 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) ## [1.1.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1)
#### 10/11/14 #### 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) ## [1.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0)
#### 10/11/14 #### 10/11/14
@@ -32,13 +48,13 @@
## [1.0.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) ## [1.0.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1)
#### 10/11/14 #### 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) ## [1.0.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0)
#### 07/11/14 #### 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) - *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) ## [0.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0)
#### 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) - *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) ## [0.0.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2)
#### 06/11/14 #### 06/11/14

View File

@@ -1,3 +1,4 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'github_api' gem 'github_api'
gem 'colorize' gem 'colorize'
gem 'rake'

View File

@@ -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

View File

@@ -2,60 +2,59 @@ GitHub Changelog Generator
================== ==================
[![Gem Version](https://badge.fury.io/rb/github_changelog_generator.svg)](http://badge.fury.io/rb/github_changelog_generator) [![Gem Version](https://badge.fury.io/rb/github_changelog_generator.svg)](http://badge.fury.io/rb/github_changelog_generator)
[![Build Status](https://travis-ci.org/skywinder/Github-Changelog-Generator.svg?branch=master)](https://travis-ci.org/skywinder/Github-Changelog-Generator)
Changelog generation has never been so easy. Changelog generation has never been so easy.
This script automatically generate change-log from your tags and merged pull-requests. This script automatically generate change-log from your tags and merged pull-requests.
## Installation: ## Installation:
You're almost done!
[sudo] gem install github_changelog_generator [sudo] gem install github_changelog_generator
## 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]
-u, --user [USER] Username of the owner of target GitHub repo -u, --user [USER] Username of the owner of target GitHub repo
-p, --project [PROJECT] Name of project on GitHub -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 -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 -h, --help Displays Help
-v, --[no-]verbose Run verbosely. Default is true --[no-]verbose Run verbosely. Default is true
--[no-]issues Include closed issues to changelog. 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-]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 --[no-]pull-requests Include pull-requests to changelog. Default is true
-l, --last-changes Generate log between last 2 tags only -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 -f, --date-format [FORMAT] Date format. Default is %d/%m/%y
-o, --output [NAME] Output file. Default is CHANGELOG.md -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' --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
## 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
## FAQ: ### GitHub token
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"'`
@@ -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. 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!
@@ -83,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).
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/skywinder/github-changelog-generator/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

9
Rakefile Normal file
View 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

View File

@@ -4,6 +4,7 @@ require 'github_api'
require 'json' require 'json'
require 'colorize' require 'colorize'
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
@@ -15,6 +16,12 @@ module GitHubChangelogGenerator
@options = Parser.parse_options @options = Parser.parse_options
if options[:verbose]
puts 'Input options:'
pp options
puts ''
end
github_token github_token
if @github_token.nil? if @github_token.nil?
@@ -23,9 +30,15 @@ module GitHubChangelogGenerator
@github = Github.new oauth_token: @github_token @github = Github.new oauth_token: @github_token
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]
@issues = self.get_all_issues @issues = self.get_all_issues
else
@issues = []
end
@tag_times_hash = {} @tag_times_hash = {}
end end
@@ -35,12 +48,17 @@ module GitHubChangelogGenerator
end end
def exec_command(cmd) def exec_command(cmd)
exec_cmd = "cd #{$project_path} && #{cmd}" exec_cmd = "cd #{$project_path} and #{cmd}"
%x[#{exec_cmd}] %x[#{exec_cmd}]
end end
def get_all_closed_pull_requests 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' response = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
pull_requests = [] pull_requests = []
@@ -49,7 +67,38 @@ module GitHubChangelogGenerator
end end
if @options[:verbose] 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 end
pull_requests pull_requests
@@ -64,8 +113,7 @@ 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] && @options[:tag2] elsif @options[:tag1] and @options[:tag2]
tag1 = @options[:tag1] tag1 = @options[:tag1]
tag2 = @options[:tag2] tag2 = @options[:tag2]
tags_strings = [] tags_strings = []
@@ -94,7 +142,7 @@ 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
@@ -113,11 +161,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
@@ -128,11 +176,8 @@ module GitHubChangelogGenerator
def get_all_tags def get_all_tags
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
if @options[:verbose] if @options[:verbose]
puts 'Fetching all tags..'
puts "Receive tags for repo #{url}"
end end
response = @github.repos.tags @options[:user], @options[:project] response = @github.repos.tags @options[:user], @options[:project]
@@ -167,90 +212,54 @@ module GitHubChangelogGenerator
def generate_log_between_tags(older_tag, newer_tag) 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) 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'] 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)
pull_requests.delete_if { |req| filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time)
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 else
true 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 end
} self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time)
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)
end end
def generate_log_before_tag(tag) def delete_by_time(array, hash_key, newer_tag_time, older_tag_time = nil)
tag_time = self.get_time_of_tag(tag) array.select { |req|
tag_name = tag['name'] 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
pull_requests.delete_if { |req|
if req[:merged_at]
t = Time.parse(req[:merged_at]).utc
t > tag_time
else else
true tag_in_range_old = t > older_tag_time
end end
} tag_in_range_new = t <= newer_tag_time
issues = Array.new(@issues) tag_in_range = (tag_in_range_old) && (tag_in_range_new)
issues.delete_if { |issue| tag_in_range
if issue[:closed_at]
t = Time.parse(issue[:closed_at]).utc
t > tag_time
else else
true false
end end
} }
self.create_log(pull_requests, issues, tag_name, tag_time)
end 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) 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]
@@ -258,12 +267,11 @@ module GitHubChangelogGenerator
if @options[:pulls] if @options[:pulls]
# Generate pull requests: # Generate pull requests:
if pull_requests pull_requests.each { |pull_request|
pull_requests.each { |dict| merge = @generator.get_string_for_pull_request(pull_request)
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
log += "- #{merge}" log += "- #{merge}"
}
end } if pull_requests
end end
if @options[:issues] if @options[:issues]
@@ -306,7 +314,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
@@ -330,8 +340,8 @@ module GitHubChangelogGenerator
end end
def get_all_issues 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 = [] issues = []
response.each_page do |page| response.each_page do |page|
@@ -344,7 +354,7 @@ module GitHubChangelogGenerator
} }
if @options[:verbose] if @options[:verbose]
puts "Receive all closed issues: #{issues.count}" puts "Received closed issues: #{issues.count}"
end end
filtered_issues = issues.select { |issue| filtered_issues = issues.select { |issue|

View 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

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'optparse' require 'optparse'
require 'PP'
require_relative 'version' require_relative 'version'
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
def self.parse_options 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| parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]' opts.banner = 'Usage: changelog_generator [options]'
@@ -15,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
@@ -34,22 +37,23 @@ 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| opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
options[:last] = last options[:last] = author
end end
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last| opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
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|
options[:labels] = list options[:labels] = list
end 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| 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!

View File

@@ -1,3 +1,3 @@
module GitHubChangelogGenerator module GitHubChangelogGenerator
VERSION = '1.1.4' VERSION = '1.2.2'
end end