Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b44c4aa78 | ||
|
|
95bdd60c34 | ||
|
|
1357b3980d | ||
|
|
b30587ce14 | ||
|
|
18e0f937ea | ||
|
|
1af8e18f9f | ||
|
|
a458a1e378 | ||
|
|
bc3af7fa93 | ||
|
|
6682ffe452 | ||
|
|
dbc7b3e567 | ||
|
|
a96f74208c | ||
|
|
cdc009b4ad | ||
|
|
0046f344a9 | ||
|
|
1b792bc67b | ||
|
|
f0716771b5 | ||
|
|
50dd7b2ed6 | ||
|
|
3797b3ac31 | ||
|
|
f08685b015 | ||
|
|
fc96007741 | ||
|
|
7e2826e3b8 | ||
|
|
c55881bdfa | ||
|
|
f6f9facc71 | ||
|
|
807bacd95a | ||
|
|
936b191566 | ||
|
|
a33b52d6d0 | ||
|
|
337c9a7d59 | ||
|
|
8247fd8520 | ||
|
|
223cd2640c | ||
|
|
459b0ec7ec | ||
|
|
ea1c5c1f6d | ||
|
|
86512d3606 | ||
|
|
b908b07e0a | ||
|
|
737774a164 | ||
|
|
62d9b7f4a6 | ||
|
|
e75e358ef8 | ||
|
|
3ac83e9ea7 | ||
|
|
70d3f63e89 | ||
|
|
2db69dd27c | ||
|
|
5a7589f8ca | ||
|
|
1adcd9918c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -0,0 +1 @@
|
|||||||
|
/lib/CHANGELOG.md
|
||||||
|
|||||||
38
CHANGELOG.md
38
CHANGELOG.md
@@ -1,18 +1,42 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.3.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.3.0)
|
## [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:* Sort issues by tags [\#14](https://github.com/skywinder/Github-Changelog-Generator/pull/14)
|
||||||
|
|
||||||
|
- *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13)
|
||||||
|
|
||||||
|
## [1.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0)
|
||||||
|
#### 10/11/14
|
||||||
|
- *Implemented enhancement:* Detect username and project form origin [\#11](https://github.com/skywinder/Github-Changelog-Generator/issues/11)
|
||||||
|
|
||||||
|
- *Fixed bug:* Markdown formating in the last line wrong [\#9](https://github.com/skywinder/Github-Changelog-Generator/issues/9)
|
||||||
|
|
||||||
|
- *Fixed bug:* Bug with wrong credentials in 1.0.1 [\#12](https://github.com/skywinder/Github-Changelog-Generator/issues/12)
|
||||||
|
|
||||||
|
## [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)
|
||||||
|
|
||||||
|
## [1.0.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0)
|
||||||
#### 07/11/14
|
#### 07/11/14
|
||||||
- Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3)
|
- *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7)
|
||||||
|
|
||||||
|
- *Merged pull-request:* Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3)
|
||||||
|
|
||||||
|
- *Implemented enhancement:* Implement option to specify output filename [\#4](https://github.com/skywinder/Github-Changelog-Generator/issues/4)
|
||||||
|
|
||||||
|
- *Implemented enhancement:* Add support for fixed issues and implemented enchanments. [\#6](https://github.com/skywinder/Github-Changelog-Generator/issues/6)
|
||||||
|
|
||||||
- *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5)
|
- *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5)
|
||||||
|
|
||||||
- *Fixed issue:* Implement option to specify output filename [\#4](https://github.com/skywinder/Github-Changelog-Generator/issues/4)
|
|
||||||
|
|
||||||
## [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
|
||||||
- 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)
|
||||||
|
|
||||||
- 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)
|
||||||
|
|
||||||
## [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
|
||||||
@@ -20,4 +44,4 @@
|
|||||||
#### 06/11/14
|
#### 06/11/14
|
||||||
|
|
||||||
|
|
||||||
**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
\* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
||||||
45
README.md
45
README.md
@@ -11,28 +11,39 @@ This script automatically generate change-log from your tags and merged pull-req
|
|||||||
[sudo] gem install github_changelog_generator
|
[sudo] gem install github_changelog_generator
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
**It's really simple**:
|
||||||
|
|
||||||
|
- `cd` to your Project folder with configured git and just type:
|
||||||
|
|
||||||
|
github_changelog_generator
|
||||||
|
|
||||||
|
- from anywhere:
|
||||||
|
|
||||||
github_changelog_generator -u github-username -p github-project
|
github_changelog_generator -u github-username -p github-project
|
||||||
|
|
||||||
In output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* changelogs in your current directory.
|
As output you will get `CHANGELOG.md` file with *pretty Markdown-formatted* changelog.
|
||||||
|
|
||||||
### Params:
|
## Params:
|
||||||
See `github_changelog_generator --help` for detailed usage.
|
Type `github_changelog_generator --help` for detailed usage.
|
||||||
|
|
||||||
Usage: changelog_generator --user username --project project_name [options]
|
Usage: changelog_generator [options]
|
||||||
-u, --user [USER] Username of the owner of target GitHub repo (required)
|
-u, --user [USER] Username of the owner of target GitHub repo
|
||||||
-p, --project [PROJECT] Name of project on GitHub (required)
|
-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 it on https://github.com/settings/applications
|
||||||
-h, --help Displays Help
|
-h, --help Displays Help
|
||||||
-v, --[no-]verbose Run verbosely
|
-v, --[no-]verbose Run verbosely. Default is true
|
||||||
-l, --last-changes Generate log between only last 2 tags
|
--[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
|
-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'
|
||||||
|
|
||||||
## Examples:
|
## Examples:
|
||||||
### This changelog: [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md)
|
|
||||||
|
|
||||||
Was generated by command:
|
- 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
|
github_changelog_generator -u skywinder -p ActionSheetPicker-3.0
|
||||||
|
|
||||||
@@ -41,13 +52,15 @@ Was generated by command:
|
|||||||
Since GitHub allow to make only 50 requests without authentication it's recommended to run this scrip with key `-t [your-16-digit-token]` that you can easily **[generate it here](https://github.com/settings/applications)**.
|
Since GitHub allow to make only 50 requests without authentication it's recommended to run this scrip with key `-t [your-16-digit-token]` that you can easily **[generate it here](https://github.com/settings/applications)**.
|
||||||
|
|
||||||
So, if you got error like this:
|
So, if you got error like this:
|
||||||
>! /Library/Ruby/Gems/2.0.0/gems/github_api-0.12.2/lib/github_api/response/raise_error.rb:14:in `on_complete': GET https://api.github.com/repos/skywinder/ActionSheetPicker-3.0/git/commits/89678f7d7f66873c858e6cb07bf697192aca6768: 403 API rate limit exceeded for 195.88.177.9. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) (Github::Error::Forbidden)
|
>! /Library/Ruby/Gems/2.0.0/gems/github_api-0.12.2/lib/github_api/response/raise_error.rb:14:in `on_complete'
|
||||||
|
|
||||||
It's time to generate this token or wait for 1 hour before GitHub reset counter for your IP.
|
It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP.
|
||||||
|
|
||||||
## License
|
## Am I missed some essential feature?
|
||||||
|
|
||||||
Github the Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
**Nothing is impossible!** Open an [issue](https://github.com/skywinder/Github-Changelog-Generator/issues/new) and let's get this generator better together!
|
||||||
|
|
||||||
|
*Bug reports, feature requests, patches, well-wishes are always welcome!*
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@@ -58,6 +71,6 @@ Github the Generator is released under the [MIT License](http://www.opensource.o
|
|||||||
5. Push to the branch (`git push origin my-new-feature`)
|
5. Push to the branch (`git push origin my-new-feature`)
|
||||||
6. Create a new Pull Request
|
6. Create a new Pull Request
|
||||||
|
|
||||||
**Bug reports, feature requests, patches, well-wishes, and rap demo tapes are always welcome!**
|
## License
|
||||||
|
|
||||||
*Improvements more than welcome - they are kindly requested! :)*
|
Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
||||||
|
|||||||
227
bump_gemfile.rb
Executable file
227
bump_gemfile.rb
Executable file
@@ -0,0 +1,227 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
require 'optparse'
|
||||||
|
|
||||||
|
SPEC_TYPE = 'gemspec'
|
||||||
|
|
||||||
|
:major
|
||||||
|
:minor
|
||||||
|
:patch
|
||||||
|
|
||||||
|
@options = {:dry_run => false, :bump_number => :patch}
|
||||||
|
|
||||||
|
OptionParser.new { |opts|
|
||||||
|
opts.banner = 'Usage: bump.rb [options]'
|
||||||
|
|
||||||
|
opts.on('-d', '--dry-run', 'Dry run') do |v|
|
||||||
|
@options[:dry_run] = v
|
||||||
|
end
|
||||||
|
opts.on('-a', '--major', 'Bump major version') do |v|
|
||||||
|
@options[:bump_number] = :major
|
||||||
|
end
|
||||||
|
opts.on('-m', '--minor', 'Bump minor version') do |v|
|
||||||
|
@options[:bump_number] = :minor
|
||||||
|
end
|
||||||
|
opts.on('-p', '--patch', 'Bump patch version') do |v|
|
||||||
|
@options[:bump_number] = :patch
|
||||||
|
end
|
||||||
|
opts.on('-r', '--revert', 'Revert last bump') do |v|
|
||||||
|
@options[:revert] = v
|
||||||
|
end
|
||||||
|
}.parse!
|
||||||
|
|
||||||
|
p @options
|
||||||
|
|
||||||
|
def check_repo_is_clean_or_dry_run
|
||||||
|
value =%x[#{'git status --porcelain'}]
|
||||||
|
|
||||||
|
if value.empty?
|
||||||
|
puts 'Repo is clean -> continue'
|
||||||
|
else
|
||||||
|
if @options[:dry_run]
|
||||||
|
puts 'Repo not clean, "Dry run" enabled -> continue'
|
||||||
|
else
|
||||||
|
puts 'Repository not clean -> exit'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def find_spec_file
|
||||||
|
list_of_specs = execute_line("find . -name '*.#{SPEC_TYPE}'")
|
||||||
|
arr = list_of_specs.split("\n")
|
||||||
|
|
||||||
|
spec_file = ''
|
||||||
|
|
||||||
|
case arr.count
|
||||||
|
when 0
|
||||||
|
puts "No #{SPEC_TYPE} files found. -> Exit."
|
||||||
|
exit
|
||||||
|
when 1
|
||||||
|
spec_file = arr[0]
|
||||||
|
else
|
||||||
|
puts 'Which spec should be used?'
|
||||||
|
arr.each_with_index { |file, index| puts "#{index+1}. #{file}" }
|
||||||
|
input_index = Integer(gets.chomp)
|
||||||
|
spec_file = arr[input_index-1]
|
||||||
|
end
|
||||||
|
|
||||||
|
if spec_file == nil
|
||||||
|
puts "Can't find specified spec file -> exit"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
spec_file.sub('./', '')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_current_gem_file
|
||||||
|
list_of_specs = execute_line("find . -name '*.gem'")
|
||||||
|
arr = list_of_specs.split("\n")
|
||||||
|
|
||||||
|
spec_file = ''
|
||||||
|
|
||||||
|
case arr.count
|
||||||
|
when 0
|
||||||
|
puts "No #{SPEC_TYPE} files found. -> Exit."
|
||||||
|
exit
|
||||||
|
when 1
|
||||||
|
spec_file = arr[0]
|
||||||
|
else
|
||||||
|
puts 'Which spec should be used?'
|
||||||
|
arr.each_with_index { |file, index| puts "#{index+1}. #{file}" }
|
||||||
|
input_index = Integer(gets.chomp)
|
||||||
|
spec_file = arr[input_index-1]
|
||||||
|
end
|
||||||
|
|
||||||
|
if spec_file == nil
|
||||||
|
puts "Can't find specified spec file -> exit"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
spec_file.sub('./', '')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_version_in_podspec(podspec)
|
||||||
|
readme = File.read(podspec)
|
||||||
|
|
||||||
|
#try to find version in format 1.22.333
|
||||||
|
re = /(\d+)\.(\d+)\.(\d+)/m
|
||||||
|
|
||||||
|
match_result = re.match(readme)
|
||||||
|
|
||||||
|
unless match_result
|
||||||
|
puts 'Not found any versions'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Found version #{match_result[0]}"
|
||||||
|
return match_result[0], match_result.captures
|
||||||
|
end
|
||||||
|
|
||||||
|
def bump_version(versions_array)
|
||||||
|
bumped_result = versions_array.dup
|
||||||
|
bumped_result.map! { |x| x.to_i }
|
||||||
|
|
||||||
|
case @options[:bump_number]
|
||||||
|
when :major
|
||||||
|
bumped_result[0] += 1
|
||||||
|
bumped_result[1] = 0
|
||||||
|
bumped_result[2] = 0
|
||||||
|
when :minor
|
||||||
|
bumped_result[1] += 1
|
||||||
|
bumped_result[2] = 0
|
||||||
|
when :patch
|
||||||
|
bumped_result[2] += 1
|
||||||
|
else
|
||||||
|
raise('unknown bump_number')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
bumped_version = bumped_result.join('.')
|
||||||
|
puts "Bump version: #{versions_array.join('.')} -> #{bumped_version}"
|
||||||
|
bumped_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute_line(line)
|
||||||
|
output = `#{line}`
|
||||||
|
check_exit_status(output)
|
||||||
|
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute_line_if_not_dry_run(line)
|
||||||
|
if @options[:dry_run]
|
||||||
|
puts "Dry run: #{line}"
|
||||||
|
nil
|
||||||
|
else
|
||||||
|
puts line
|
||||||
|
value = %x[#{line}]
|
||||||
|
puts value
|
||||||
|
check_exit_status(value)
|
||||||
|
value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_exit_status(output)
|
||||||
|
if $?.exitstatus != 0
|
||||||
|
puts "Output:\n#{output}\nExit status = #{$?.exitstatus} ->Terminate script."
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_bumping_script
|
||||||
|
|
||||||
|
check_repo_is_clean_or_dry_run
|
||||||
|
spec_file = find_spec_file
|
||||||
|
result, versions_array = find_version_in_podspec(spec_file)
|
||||||
|
bumped_version = bump_version(versions_array)
|
||||||
|
|
||||||
|
unless @options[:dry_run]
|
||||||
|
puts 'Are you sure? Press Y to continue:'
|
||||||
|
str = gets.chomp
|
||||||
|
if str != 'Y'
|
||||||
|
puts '-> exit'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
execute_line_if_not_dry_run("sed -i \"\" \"s/#{result}/#{bumped_version}/\" README.md")
|
||||||
|
execute_line_if_not_dry_run("sed -i \"\" \"s/#{result}/#{bumped_version}/\" #{spec_file}")
|
||||||
|
execute_line_if_not_dry_run("git commit --all -m \"Update #{$SPEC_TYPE} to version #{bumped_version}\"")
|
||||||
|
execute_line_if_not_dry_run("git tag #{bumped_version}")
|
||||||
|
execute_line_if_not_dry_run('git push')
|
||||||
|
execute_line_if_not_dry_run('git push --tags')
|
||||||
|
execute_line_if_not_dry_run("gem build #{spec_file}")
|
||||||
|
|
||||||
|
gem = find_current_gem_file
|
||||||
|
execute_line_if_not_dry_run("gem push #{gem}")
|
||||||
|
# execute_line_if_not_dry_run("pod trunk push #{spec_file}")
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def revert_last_bump
|
||||||
|
spec_file = find_spec_file
|
||||||
|
result, _ = find_version_in_podspec(spec_file)
|
||||||
|
|
||||||
|
puts "DELETE tag #{result} and HARD reset HEAD~1?\nPress Y to continue:"
|
||||||
|
str = gets.chomp
|
||||||
|
if str != 'Y'
|
||||||
|
puts '-> exit'
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
execute_line_if_not_dry_run("git tag -d #{result}")
|
||||||
|
execute_line_if_not_dry_run('git reset --hard HEAD~1')
|
||||||
|
execute_line_if_not_dry_run("git push --delete origin #{result}")
|
||||||
|
end
|
||||||
|
|
||||||
|
if __FILE__ == $0
|
||||||
|
|
||||||
|
if @options[:revert]
|
||||||
|
revert_last_bump
|
||||||
|
else
|
||||||
|
run_bumping_script
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "github_changelog_generator"
|
s.name = "github_changelog_generator"
|
||||||
s.version = "1.0.0"
|
s.version = "1.1.2"
|
||||||
s.default_executable = "github_changelog_generator"
|
s.default_executable = "github_changelog_generator"
|
||||||
|
|
||||||
s.required_ruby_version = '>= 1.9.3'
|
s.required_ruby_version = '>= 1.9.3'
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class ChangelogGenerator
|
|||||||
tag1 = @options[:tag1]
|
tag1 = @options[:tag1]
|
||||||
tag2 = @options[:tag2]
|
tag2 = @options[:tag2]
|
||||||
tags_strings = []
|
tags_strings = []
|
||||||
self.all_tags.each { |x| tags_strings.push(x['name'])}
|
self.all_tags.each { |x| tags_strings.push(x['name']) }
|
||||||
|
|
||||||
if tags_strings.include?(tag1)
|
if tags_strings.include?(tag1)
|
||||||
if tags_strings.include?(tag2)
|
if tags_strings.include?(tag2)
|
||||||
@@ -80,12 +80,7 @@ class ChangelogGenerator
|
|||||||
log += self.generate_log_for_all_tags
|
log += self.generate_log_for_all_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
|
log += "\n\n\\* *This changelog was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
||||||
if @options[:verbose]
|
|
||||||
puts log
|
|
||||||
end
|
|
||||||
|
|
||||||
log += "\n\n**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
|
|
||||||
|
|
||||||
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) }
|
||||||
@@ -117,9 +112,14 @@ class ChangelogGenerator
|
|||||||
puts "Receive tags for repo #{url}"
|
puts "Receive tags for repo #{url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @options[:token]
|
||||||
response = HTTParty.get(url,
|
response = HTTParty.get(url,
|
||||||
:headers => {'Authorization' => "token #{@options[:token]}",
|
:headers => {'Authorization' => "token #{@options[:token]}",
|
||||||
'User-Agent' => 'Changelog-Generator'})
|
'User-Agent' => 'Changelog-Generator'})
|
||||||
|
else
|
||||||
|
response = HTTParty.get(url,
|
||||||
|
:headers => {'User-Agent' => 'Changelog-Generator'})
|
||||||
|
end
|
||||||
|
|
||||||
json_parse = JSON.parse(response.body)
|
json_parse = JSON.parse(response.body)
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ class ChangelogGenerator
|
|||||||
|
|
||||||
issues = Array.new(@issues)
|
issues = Array.new(@issues)
|
||||||
|
|
||||||
issues.delete_if{ |issue|
|
issues.delete_if { |issue|
|
||||||
if issue[:closed_at]
|
if issue[:closed_at]
|
||||||
t = Time.parse(issue[:closed_at]).utc
|
t = Time.parse(issue[:closed_at]).utc
|
||||||
tag_is_later_since = t > since_tag_time
|
tag_is_later_since = t > since_tag_time
|
||||||
@@ -196,7 +196,7 @@ class ChangelogGenerator
|
|||||||
|
|
||||||
issues = Array.new(@issues)
|
issues = Array.new(@issues)
|
||||||
|
|
||||||
issues.delete_if{ |issue|
|
issues.delete_if { |issue|
|
||||||
if issue[:closed_at]
|
if issue[:closed_at]
|
||||||
t = Time.parse(issue[:closed_at]).utc
|
t = Time.parse(issue[:closed_at]).utc
|
||||||
t > tag_time
|
t > tag_time
|
||||||
@@ -223,7 +223,7 @@ class ChangelogGenerator
|
|||||||
# Generate pull requests:
|
# Generate pull requests:
|
||||||
if pull_requests
|
if pull_requests
|
||||||
pull_requests.each { |dict|
|
pull_requests.each { |dict|
|
||||||
merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n"
|
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
||||||
log += "- #{merge}"
|
log += "- #{merge}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -232,6 +232,22 @@ class ChangelogGenerator
|
|||||||
if @options[:issues]
|
if @options[:issues]
|
||||||
# Generate issues:
|
# Generate issues:
|
||||||
if issues
|
if issues
|
||||||
|
issues.sort! { |x, y|
|
||||||
|
if x.labels.any? && y.labels.any?
|
||||||
|
x.labels[0].name <=> y.labels[0].name
|
||||||
|
else
|
||||||
|
if x.labels.any?
|
||||||
|
1
|
||||||
|
else
|
||||||
|
if y.labels.any?
|
||||||
|
-1
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}.reverse!
|
||||||
|
end
|
||||||
issues.each { |dict|
|
issues.each { |dict|
|
||||||
is_bug = false
|
is_bug = false
|
||||||
is_enhancement = false
|
is_enhancement = false
|
||||||
@@ -253,13 +269,10 @@ class ChangelogGenerator
|
|||||||
intro = 'Implemented enhancement'
|
intro = 'Implemented enhancement'
|
||||||
end
|
end
|
||||||
|
|
||||||
merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n"
|
merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
|
||||||
log += "- #{merge}"
|
log += "- #{merge}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
log
|
log
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -281,15 +294,31 @@ class ChangelogGenerator
|
|||||||
|
|
||||||
def get_all_issues
|
def get_all_issues
|
||||||
all_issues = []
|
all_issues = []
|
||||||
@options[:labels].each { |label|
|
|
||||||
issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label
|
issues_req = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: nil
|
||||||
all_issues = all_issues.concat(issues.body)
|
|
||||||
|
filtered_issues = issues_req.body.select { |issues|
|
||||||
|
#compare is there any labels from @options[:labels] array
|
||||||
|
(issues.labels.map { |issue| issue.name } & @options[:labels]).any?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if @options[:add_issues_wo_labels]
|
||||||
|
issues_wo_labels = issues_req.body.select {
|
||||||
|
|issues| !issues.labels.map { |issue| issue.name }.any?
|
||||||
|
}
|
||||||
|
filtered_issues.concat(issues_wo_labels)
|
||||||
|
end
|
||||||
|
|
||||||
|
# remove pull request from issues:
|
||||||
|
filtered_issues.select! { |x|
|
||||||
|
x.pull_request == nil
|
||||||
|
}
|
||||||
|
|
||||||
if @options[:verbose]
|
if @options[:verbose]
|
||||||
puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues"
|
puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues"
|
||||||
end
|
end
|
||||||
|
|
||||||
all_issues
|
filtered_issues
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ require 'optparse'
|
|||||||
|
|
||||||
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 }
|
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:* ' }
|
||||||
|
|
||||||
parser = OptionParser.new { |opts|
|
parser = OptionParser.new { |opts|
|
||||||
opts.banner = 'Usage: changelog_generator --user username --project project_name [options]'
|
opts.banner = 'Usage: changelog_generator [options]'
|
||||||
opts.on('-u', '--user [USER]', 'Username of the owner of target GitHub repo (required)') do |last|
|
opts.on('-u', '--user [USER]', 'Username of the owner of target GitHub repo') do |last|
|
||||||
options[:user] = last
|
options[:user] = last
|
||||||
end
|
end
|
||||||
opts.on('-p', '--project [PROJECT]', 'Name of project on GitHub (required)') 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 it on https://github.com/settings/applications') do |last|
|
opts.on('-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') do |last|
|
||||||
@@ -20,12 +20,15 @@ class Parser
|
|||||||
puts opts
|
puts opts
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
opts.on('-v', '--[no-]verbose', 'Run verbosely. Default is true') do |v|
|
||||||
options[:verbose] = v
|
options[:verbose] = v
|
||||||
end
|
end
|
||||||
opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
|
opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v|
|
||||||
options[:issues] = v
|
options[:issues] = v
|
||||||
end
|
end
|
||||||
|
opts.on('--[no-]issues-without-labels', 'Include closed issues without any labels to changelog. Default is true') do |v|
|
||||||
|
options[:add_issues_wo_labels] = v
|
||||||
|
end
|
||||||
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
|
||||||
@@ -51,6 +54,17 @@ class Parser
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !options[:user] && !options[:project]
|
||||||
|
remote = `git remote -vv`.split("\n")
|
||||||
|
match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)\.git.*/.match(remote[0])
|
||||||
|
|
||||||
|
if match && match[1] && match[2]
|
||||||
|
puts "Detected user:#{match[1]}, project:#{match[2]}"
|
||||||
|
options[:user], options[:project] = match[1], match[2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
if !options[:user] || !options[:project]
|
if !options[:user] || !options[:project]
|
||||||
puts parser.banner
|
puts parser.banner
|
||||||
exit
|
exit
|
||||||
|
|||||||
Reference in New Issue
Block a user