changelog_jira 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +233 -0
  3. data/Rakefile +39 -0
  4. data/bin/git-generate-changelog +4 -0
  5. data/bin/github_changelog_generator +4 -0
  6. data/lib/CHANGELOG.md +58 -0
  7. data/lib/github_changelog_generator.rb +41 -0
  8. data/lib/github_changelog_generator/fetcher.rb +221 -0
  9. data/lib/github_changelog_generator/generator/generator.rb +143 -0
  10. data/lib/github_changelog_generator/generator/generator_fetcher.rb +83 -0
  11. data/lib/github_changelog_generator/generator/generator_generation.rb +190 -0
  12. data/lib/github_changelog_generator/generator/generator_processor.rb +193 -0
  13. data/lib/github_changelog_generator/generator/generator_tags.rb +184 -0
  14. data/lib/github_changelog_generator/helper.rb +37 -0
  15. data/lib/github_changelog_generator/parser.rb +285 -0
  16. data/lib/github_changelog_generator/parser_file.rb +103 -0
  17. data/lib/github_changelog_generator/reader.rb +84 -0
  18. data/lib/github_changelog_generator/task.rb +67 -0
  19. data/lib/github_changelog_generator/version.rb +3 -0
  20. data/man/git-generate-changelog.1 +252 -0
  21. data/man/git-generate-changelog.html +262 -0
  22. data/man/git-generate-changelog.md +179 -0
  23. data/spec/files/angular.js.md +9395 -0
  24. data/spec/files/bundler.md +1911 -0
  25. data/spec/files/github-changelog-generator.md +305 -0
  26. data/spec/install-gem-in-bundler.gemfile +3 -0
  27. data/spec/spec_helper.rb +55 -0
  28. data/spec/unit/fetcher_spec.rb +59 -0
  29. data/spec/unit/generator/generator_processor_spec.rb +28 -0
  30. data/spec/unit/generator/generator_tags_spec.rb +243 -0
  31. data/spec/unit/parse_file_spec.rb +73 -0
  32. data/spec/unit/parser_spec.rb +60 -0
  33. data/spec/unit/reader_spec.rb +113 -0
  34. metadata +190 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f72fbd2d4a53d385fd560b8c8e6d691c67d8c66
4
+ data.tar.gz: a2c31d2c3572ccfd4f532117f12c7d68cf361ea5
5
+ SHA512:
6
+ metadata.gz: 715930d1249d9df4a7849285996cfd7230c188f1649fe1acc7c9b1093028a0e72087ced86848d9ed51258a87933af37b6b36d0102ec22029b86c1059c19b81d1
7
+ data.tar.gz: 31b5580ad17d8907bc42c779f5c6be928eb8e253ebd68bd00df5f686223d6b7c0f809d089fd8f94356e203880c9beb5b1e0c2ef8bd0c18b62b92e7d1eed0535c
@@ -0,0 +1,233 @@
1
+ [![Gem Version](https://badge.fury.io/rb/github_changelog_generator.svg)](http://badge.fury.io/rb/github_changelog_generator)
2
+ [![Dependency Status](https://gemnasium.com/skywinder/github-changelog-generator.svg)](https://gemnasium.com/skywinder/github-changelog-generator)
3
+ [![Build Status](https://travis-ci.org/skywinder/github-changelog-generator.svg?branch=master)](https://travis-ci.org/skywinder/github-changelog-generator)
4
+ [![Inline docs](http://inch-ci.org/github/skywinder/github-changelog-generator.svg)](http://inch-ci.org/github/skywinder/github-changelog-generator)
5
+ [![Code Climate](https://codeclimate.com/github/skywinder/github-changelog-generator/badges/gpa.svg)](https://codeclimate.com/github/skywinder/github-changelog-generator)
6
+ [![Test Coverage](https://codeclimate.com/github/skywinder/github-changelog-generator/badges/coverage.svg)](https://codeclimate.com/github/skywinder/github-changelog-generator)
7
+
8
+ GitHub Changelog Generator ![GitHub Logo](../master/images/logo.jpg)
9
+ ==================
10
+
11
+ - [Installation](#installation)
12
+ - [Output example](#output-example)
13
+ - [Usage](#usage)
14
+ - [Params](#params)
15
+ - [GitHub token](#github-token)
16
+ - [Features and advantages of this project](#features-and-advantages-of-this-project)
17
+ - [Alternatives](#alternatives)
18
+ - [Projects using this library](#projects-using-this-library)
19
+ - [Am I missing some essential feature?](#am-i-missing-some-essential-feature)
20
+ - [Contributing](#contributing)
21
+ - [License](#license)
22
+
23
+
24
+ ### Changelog generation has never been so easy
25
+
26
+ **Fully automate changelog generation** - This gem generates change log file based on **tags**, **issues** and merged **pull requests** (and splits them into separate lists according labels) from :octocat: GitHub Issue Tracker.
27
+
28
+ Since now you don't have to fill your `CHANGELOG.md` manually: just run the script, relax and take a cup of :coffee: before your next release! :tada:
29
+
30
+ >### *What’s the point of a change log?*
31
+ To make it easier for users and contributors to see precisely what notable changes have been made between each release (or version) of the project.
32
+ ### *Why should I care?*
33
+ Because software tools are for people. If you don’t care, why are you contributing to open source? Surely, there must be a kernel (ha!) of care somewhere in that lovely little brain of yours.
34
+
35
+ > :arrow_right: *[http://keepachangelog.com](http://keepachangelog.com)*
36
+
37
+ ## Installation
38
+
39
+ [sudo] gem install github_changelog_generator
40
+
41
+ ## Output example
42
+
43
+ - Look at **[CHANGELOG.md](https://github.com/skywinder/Github-Changelog-Generator/blob/master/CHANGELOG.md)** for this project
44
+ - [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md) was generated by command:
45
+
46
+ github_changelog_generator -u skywinder -p ActionSheetPicker-3.0
47
+
48
+ - In general, it looks like this:
49
+
50
+ > ## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5) (2015-01-15)
51
+ >
52
+ > [Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.4...1.2.5)
53
+ >
54
+ > **Implemented enhancements:**
55
+ >
56
+ > - Use milestone to specify in which version bug was fixed [\#22](https://github.com/skywinder/Github-Changelog-Generator/issues/22)
57
+ >
58
+ > **Fixed bugs:**
59
+ >
60
+ > - Error when trying to generate log for repo without tags [\#32](https://github.com/skywinder/Github-Changelog-Generator/issues/32)
61
+ >
62
+ > **Merged pull requests:**
63
+ >
64
+ > - PrettyPrint class is included using lowercase 'pp' [\#43](https://github.com/skywinder/Github-Changelog-Generator/pull/43) ([schwing](https://github.com/schwing))
65
+ >
66
+ > - support enterprise github via command line options [\#42](https://github.com/skywinder/Github-Changelog-Generator/pull/42) ([glenlovett](https://github.com/glenlovett))
67
+
68
+
69
+ ## Usage
70
+ **It's really simple!**
71
+
72
+ - If your **`git remote`** `origin` refers to your GitHub repo, just go to your project folder and run:
73
+
74
+ github_changelog_generator
75
+
76
+ - Or, run this from anywhere:
77
+ - `github_changelog_generator -u github_username -p github_project`
78
+ - `github_changelog_generator github_username/github_project`
79
+
80
+ This generates a changelog to the `CHANGELOG.md` file, with pretty markdown formatting.
81
+
82
+ ### Params
83
+ Type `github_changelog_generator --help` for details.
84
+
85
+ For more details about params, read the Wiki page: [**Advanced change log generation examples**](https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples)
86
+
87
+ ### Params File
88
+ In your project root, you can put a params file named `.github_changelog_generator` to override default params:
89
+
90
+ Example:
91
+ ```
92
+ unreleased=false
93
+ future-release=5.0.0
94
+ since-tag=1.0.0
95
+ ```
96
+
97
+ ### GitHub token
98
+
99
+ GitHub only allows only 50 unauthenticated requests per hour.
100
+ Therefore, it's recommended to run this script with authentication by using a **token**.
101
+
102
+ Here's how:
103
+
104
+ - [Generate a token here](https://github.com/settings/tokens/new?description=GitHub%20Changelog%20Generator%20token) - you only need "repo" scope for private repositories
105
+ - Either:
106
+ - Run the script with `--token <your-40-digit-token>`; **OR**
107
+ - Set the `CHANGELOG_GITHUB_TOKEN` environment variable to your 40 digit token
108
+
109
+ You can set an environment variable by running the following command at the prompt, or by adding it to your shell profile (e.g., `~/.bash_profile` or `~/.zshrc`):
110
+
111
+ export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
112
+
113
+ So, if you got an error like this:
114
+ >! /Library/Ruby/Gems/2.0.0/gems/github_api-0.12.2/lib/github_api/response/raise_error.rb:14:in `on_complete'
115
+
116
+ It's time to create this token! (Or, wait an hour for GitHub to reset your unauthenticated request limit.)
117
+
118
+ ## Migrating from a manual changelog
119
+
120
+ Knowing how dedicated you are to your project, you probably haven't been waiting for `github-changelog-generator` to keep a changelog.
121
+ But you probably don't want your project's open issues and PRs for all past features listed in your historic changelog, either.
122
+
123
+ That's where `--base <your-manual-changelog.md>` comes in handy!
124
+ This option lets append your old manual changelog to the end of the generated entries.
125
+
126
+ If you have a `HISTORY.md` file in your project, it will automatically be picked as the static historical changelog and appended.
127
+
128
+ ### Rake task
129
+
130
+ You love `rake`? We do, too! So, we've made it even easier for you:
131
+ we've provided a `rake` task library for your changelog generation.
132
+
133
+ Just put something like this in your `Rakefile`:
134
+
135
+ ```ruby
136
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
137
+ config.since_tag = '0.1.14'
138
+ config.future_release = '0.2.0'
139
+ end
140
+ ```
141
+
142
+ All command line options can be passed to the `rake` task as `config` parameters. And since you're naming the `rake` task yourself, you can create as many as you want.
143
+
144
+ ## Features and advantages of this project
145
+ - Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com) :gem:
146
+ - Optionally generate **Unreleased** changes (closed issues that have not released yet) :dizzy:
147
+ - **GitHub Enterprise support** via command line options! :factory:
148
+ - Flexible format **customization**:
149
+ - **Customize** issues that **should be added** to changelog :eight_spoked_asterisk:
150
+ - **Custom date formats** supported (but keep [ISO 8601](http://xkcd.com/1179/) in mind!) :date:
151
+ - Manually specify the version that fixed an issue (for cases when the issue's Closed date doesn't match) by giving the issue's `milestone` the same name as the tag of version :pushpin:
152
+ - Automatically **exclude specific issues** that are irrelevant to your changelog (by default, any issue labeled `question`, `duplicate`, `invalid`, or `wontfix`) :scissors:
153
+ - **Distinguish** issues **by labels**. :mag_right:
154
+ - Merged pull requests (all merged pull-requests) :twisted_rightwards_arrows:
155
+ - Bug fixes (issues labeled `bug`) :beetle:
156
+ - Enhancements (issues labeled `enhancement`) :star2:
157
+ - Issues (closed issues with no labels) :non-potable_water:
158
+
159
+ - Manually include or exclude issues by labels :wrench:
160
+ - Customize lots more! Tweak the changelog to fit your preferences :tophat:
161
+ (*See `github_changelog_generator --help` for details)*
162
+
163
+
164
+ ###Alternatives
165
+ Here is a [wikipage list of alternatives](https://github.com/skywinder/Github-Changelog-Generator/wiki/Alternatives) that I found. But none satisfied my requirements.
166
+
167
+ *If you know other projects, feel free to edit this Wiki page!*
168
+
169
+
170
+ ### Projects using this library
171
+ Here's a [wikipage list of projects](https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator).
172
+
173
+ If you've used this project in a live app, please let me know! Nothing makes me happier than seeing someone else take my work and go wild with it.
174
+
175
+ *If you are using `github_changelog_generator` to generate your project's changelog, or know of other projects using it, please [add it to this list] (https://github.com/skywinder/Github-Changelog-Generator/wiki/Projects-using-Github-Changelog-Generator).*
176
+
177
+ ## Am I missing some essential feature?
178
+
179
+ - **Nothing is impossible!**
180
+
181
+ - Open an [issue](https://github.com/skywinder/Github-Changelog-Generator/issues/new) and let's make the generator better together!
182
+
183
+ - *Bug reports, feature requests, patches, and well-wishes are always welcome.* :heavy_exclamation_mark:
184
+
185
+ ## FAQ
186
+
187
+ - ***I already use GitHub Releases. Why do I need this?***
188
+
189
+ GitHub Releases is a very good thing. And it's very good practice to maintain it. (Not a lot of people are using it yet!) :congratulations:
190
+
191
+ *BTW: I would like to support GitHub Releases in [next releases](https://github.com/skywinder/github-changelog-generator/issues/56) ;)*
192
+
193
+ I'm not trying to compare the quality of handwritten and auto-generated logs. That said....
194
+
195
+ An auto-generated changelog really helps, even if you manually fill in the release notes!
196
+
197
+ For example:
198
+
199
+ When I found a closed bug, it's very useful know which release fixed it.
200
+ In this case, you can easily find the issue by \# in `CHANGELOG.md`.
201
+
202
+ - it's not quite as easy to find this in handwritten releases notes
203
+ - a generated file saves you the trouble of remembering everything;
204
+ sometimes people forget to add things to a handwritten file
205
+
206
+ Ultimately, I think GitHub Releases is ideal for end-users.
207
+ Meanwhile, `CHANGELOG.md` lives right in the repository, with its detailed list of changes, which is handy for developers.
208
+ Finally, there's nothing wrong with using GitHub Releases alongside `CHANGELOG.md` in this combination.
209
+
210
+ - ***I received a warning: "GitHub API rate limit exceed" What does this mean?***
211
+
212
+ GitHub [limits the number of API requests](https://developer.github.com/v3/#rate-limiting) you can make in an hour. You can make up to 5,000 requests per hour. For unauthenticated requests, the rate limit is only up to 60 requests per hour. Unauthenticated requests are associated with your IP address (not the user making requests).
213
+
214
+ If you're seeing this warning, please do the following:
215
+
216
+ 1. Make sure you're providing an OAuth token, so you're not making requests anonymously. Using an OAuth token increases your hourly request maximum from 60 to 5000.
217
+ 2. If you have a large repo with lots of issues/PRs, you can use `--max-issues NUM` to limit the number of issues that are pulled back. For example: `--max-issues 1000`
218
+
219
+ ## Contributing
220
+
221
+ 1. Create an issue and describe your idea
222
+ 2. [Fork it] (https://github.com/skywinder/Github-Changelog-Generator/fork)
223
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
224
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
225
+ 5. Publish the branch (`git push origin my-new-feature`)
226
+ 6. Create a new Pull Request
227
+ 7. Profit! :white_check_mark:
228
+
229
+ *To test your workflow with changelog generator, you can use [test repo](https://github.com/skywinder/changelog_test/)*
230
+
231
+ ## License
232
+
233
+ Github Changelog Generator is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1,39 @@
1
+ require "bundler"
2
+ require "bundler/gem_tasks"
3
+ require "rubocop/rake_task"
4
+ require "rspec/core/rake_task"
5
+ require "pathname"
6
+ require "fileutils"
7
+ require "overcommit"
8
+
9
+ RuboCop::RakeTask.new
10
+ RSpec::Core::RakeTask.new(:rspec)
11
+
12
+ task :copy_man_page_to_manpath do |_t|
13
+ known_manpath_paths = %w(/etc/manpath.config /etc/manpaths)
14
+ manpath = known_manpath_paths.find do |f|
15
+ path = Pathname(f)
16
+ path.file? && path.readable?
17
+ end
18
+
19
+ next unless manpath
20
+
21
+ writable_man_path = Pathname(manpath).each_line.find do |line|
22
+ path = Pathname(line.chomp)
23
+ path.directory? && path.writable?
24
+ end
25
+
26
+ next unless writable_man_path
27
+
28
+ man_prefix = Pathname("#{writable_man_path.chomp}/man1")
29
+ man_pages = "man/git-*.1"
30
+
31
+ Pathname.glob(man_pages) do |path|
32
+ if path.exist? && man_prefix.exist? && man_prefix.writable?
33
+ FileUtils.cp(path, man_prefix + path.basename)
34
+ end
35
+ end
36
+ end
37
+
38
+ task checks: [:rubocop, :rspec]
39
+ task default: [:copy_man_page_to_manpath]
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require_relative "../lib/github_changelog_generator"
4
+ GitHubChangelogGenerator::ChangelogGenerator.new.run
@@ -0,0 +1,4 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require_relative "../lib/github_changelog_generator"
4
+ GitHubChangelogGenerator::ChangelogGenerator.new.run
@@ -0,0 +1,58 @@
1
+ # Change Log
2
+
3
+ ## [Unreleased](https://github.com/skywinder/changelog_test/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/skywinder/changelog_test/compare/0.0.4...HEAD)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Enchancment [\#9](https://github.com/skywinder/changelog_test/issues/9)
10
+ - PR with enhancement label [\#16](https://github.com/skywinder/changelog_test/pull/16) ([skywinder](https://github.com/skywinder))
11
+
12
+ **Fixed bugs:**
13
+
14
+ - BugFix [\#11](https://github.com/skywinder/changelog_test/issues/11)
15
+
16
+ **Closed issues:**
17
+
18
+ - Issue closed from commit from PR [\#14](https://github.com/skywinder/changelog_test/issues/14)
19
+ - Issue, closed by PR [\#12](https://github.com/skywinder/changelog_test/issues/12)
20
+ - Issue [\#10](https://github.com/skywinder/changelog_test/issues/10)
21
+ - Issue with some other label - Should be in closed issues [\#8](https://github.com/skywinder/changelog_test/issues/8)
22
+
23
+ **Merged pull requests:**
24
+
25
+ - Merged br \(should appear in change log also\) [\#21](https://github.com/skywinder/changelog_test/pull/21) ([skywinder](https://github.com/skywinder))
26
+ - This a PR with a lot of comments and events [\#17](https://github.com/skywinder/changelog_test/pull/17) ([skywinder](https://github.com/skywinder))
27
+ - This PR closes 14 from commit [\#15](https://github.com/skywinder/changelog_test/pull/15) ([skywinder](https://github.com/skywinder))
28
+ - This PR to close \#12 from body [\#13](https://github.com/skywinder/changelog_test/pull/13) ([skywinder](https://github.com/skywinder))
29
+
30
+ ## [0.0.4](https://github.com/skywinder/changelog_test/tree/0.0.4) (2015-05-22)
31
+ [Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.3...0.0.4)
32
+
33
+ **Closed issues:**
34
+
35
+ - Test issue, that should appear in 0.0.4 [\#3](https://github.com/skywinder/changelog_test/issues/3)
36
+
37
+ **Merged pull requests:**
38
+
39
+ - Add automatically generated change log file. [\#5](https://github.com/skywinder/changelog_test/pull/5) ([skywinder](https://github.com/skywinder))
40
+
41
+ ## [v0.0.3](https://github.com/skywinder/changelog_test/tree/v0.0.3) (2015-03-04)
42
+ [Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.2...v0.0.3)
43
+
44
+ **Merged pull requests:**
45
+
46
+ - fix \#3. hotfix. Should appear in v0.0.3 [\#4](https://github.com/skywinder/changelog_test/pull/4) ([skywinder](https://github.com/skywinder))
47
+
48
+ ## [v0.0.2](https://github.com/skywinder/changelog_test/tree/v0.0.2) (2015-03-04)
49
+ [Full Changelog](https://github.com/skywinder/changelog_test/compare/v0.0.1...v0.0.2)
50
+
51
+ **Merged pull requests:**
52
+
53
+ - Here is a test hotfix should appear in v.0.0.2 [\#2](https://github.com/skywinder/changelog_test/pull/2) ([skywinder](https://github.com/skywinder))
54
+
55
+ ## [v0.0.1](https://github.com/skywinder/changelog_test/tree/v0.0.1) (2015-03-02)
56
+
57
+
58
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "github_api"
4
+ require "json"
5
+ require "colorize"
6
+ require "benchmark"
7
+
8
+ require_relative "github_changelog_generator/helper"
9
+ require_relative "github_changelog_generator/parser"
10
+ require_relative "github_changelog_generator/parser_file"
11
+ require_relative "github_changelog_generator/generator/generator"
12
+ require_relative "github_changelog_generator/version"
13
+ require_relative "github_changelog_generator/reader"
14
+
15
+ # The main module, where placed all classes (now, at least)
16
+ module GitHubChangelogGenerator
17
+ # Main class and entry point for this script.
18
+ class ChangelogGenerator
19
+ # Class, responsible for whole change log generation cycle
20
+ # @return initialised instance of ChangelogGenerator
21
+ def initialize
22
+ @options = Parser.parse_options
23
+ @generator = Generator.new @options
24
+ end
25
+
26
+ # The entry point of this script to generate change log
27
+ # @raise (ChangelogGeneratorError) Is thrown when one of specified tags was not found in list of tags.
28
+ def run
29
+ log = @generator.compound_changelog
30
+
31
+ output_filename = (@options[:output]).to_s
32
+ File.open(output_filename, "w") { |file| file.write(log) }
33
+ puts "Done!"
34
+ puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
35
+ end
36
+ end
37
+
38
+ if __FILE__ == $PROGRAM_NAME
39
+ GitHubChangelogGenerator::ChangelogGenerator.new.run
40
+ end
41
+ end
@@ -0,0 +1,221 @@
1
+ module GitHubChangelogGenerator
2
+ # A Fetcher responsible for all requests to GitHub and all basic manipulation with related data
3
+ # (such as filtering, validating, e.t.c)
4
+ #
5
+ # Example:
6
+ # fetcher = GitHubChangelogGenerator::Fetcher.new options
7
+
8
+ class Fetcher
9
+ PER_PAGE_NUMBER = 30
10
+ CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
11
+ GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: Can't finish operation: GitHub API rate limit exceeded, change log may be " \
12
+ "missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
13
+ NO_TOKEN_PROVIDED = "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found. " \
14
+ "This script can make only 50 requests to GitHub API per hour without token!"
15
+
16
+ def initialize(options = {})
17
+ @options = options || {}
18
+ @user = @options[:user]
19
+ @project = @options[:project]
20
+ @github_token = fetch_github_token
21
+ @github_options = { per_page: PER_PAGE_NUMBER }
22
+ @github_options[:oauth_token] = @github_token unless @github_token.nil?
23
+ @github_options[:endpoint] = @options[:github_endpoint] unless @options[:github_endpoint].nil?
24
+ @github_options[:site] = @options[:github_endpoint] unless @options[:github_site].nil?
25
+
26
+ @github = check_github_response { Github.new @github_options }
27
+ end
28
+
29
+ # Returns GitHub token. First try to use variable, provided by --token option,
30
+ # otherwise try to fetch it from CHANGELOG_GITHUB_TOKEN env variable.
31
+ #
32
+ # @return [String]
33
+ def fetch_github_token
34
+ env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
35
+
36
+ Helper.log.warn NO_TOKEN_PROVIDED.yellow unless env_var
37
+
38
+ env_var
39
+ end
40
+
41
+ # Fetch all tags from repo
42
+ # @return [Array] array of tags
43
+ def get_all_tags
44
+ print "Fetching tags...\r" if @options[:verbose]
45
+
46
+ check_github_response { github_fetch_tags }
47
+ end
48
+
49
+ # This is wrapper with rescue block
50
+ # @return [Object] returns exactly the same, what you put in the block, but wrap it with begin-rescue block
51
+ def check_github_response
52
+ begin
53
+ value = yield
54
+ rescue Github::Error::Unauthorized => e
55
+ Helper.log.error e.body.red
56
+ abort "Error: wrong GitHub token"
57
+ rescue Github::Error::Forbidden => e
58
+ Helper.log.warn e.body.red
59
+ Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
60
+ end
61
+ value
62
+ end
63
+
64
+ # Fill input array with tags
65
+ # @return [Array] array of tags in repo
66
+ def github_fetch_tags
67
+ tags = []
68
+ response = @github.repos.tags @options[:user], @options[:project]
69
+ page_i = 0
70
+ count_pages = response.count_pages
71
+ response.each_page do |page|
72
+ page_i += PER_PAGE_NUMBER
73
+ print_in_same_line("Fetching tags... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
74
+ tags.concat(page)
75
+ end
76
+ print_empty_line
77
+
78
+ if tags.count == 0
79
+ Helper.log.warn "Warning: Can't find any tags in repo.\
80
+ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
81
+ else
82
+ Helper.log.info "Found #{tags.count} tags"
83
+ end
84
+ tags
85
+ end
86
+
87
+ # This method fetch all closed issues and separate them to pull requests and pure issues
88
+ # (pull request is kind of issue in term of GitHub)
89
+ # @return [Tuple] with (issues, pull-requests)
90
+ def fetch_closed_issues_and_pr
91
+ print "Fetching closed issues...\r" if @options[:verbose]
92
+ issues = []
93
+
94
+ begin
95
+ response = @github.issues.list user: @options[:user],
96
+ repo: @options[:project],
97
+ state: "closed",
98
+ filter: "all",
99
+ labels: nil
100
+ page_i = 0
101
+ count_pages = response.count_pages
102
+ response.each_page do |page|
103
+ page_i += PER_PAGE_NUMBER
104
+ print_in_same_line("Fetching issues... #{page_i}/#{count_pages * PER_PAGE_NUMBER}")
105
+ issues.concat(page)
106
+ break if @options[:max_issues] && issues.length >= @options[:max_issues]
107
+ end
108
+ print_empty_line
109
+ Helper.log.info "Received issues: #{issues.count}"
110
+
111
+ rescue
112
+ Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
113
+ end
114
+
115
+ # separate arrays of issues and pull requests:
116
+ issues.partition do |x|
117
+ x[:pull_request].nil?
118
+ end
119
+ end
120
+
121
+ # Fetch all pull requests. We need them to detect :merged_at parameter
122
+ # @return [Array] all pull requests
123
+ def fetch_closed_pull_requests
124
+ pull_requests = []
125
+ begin
126
+ response = if @options[:release_branch].nil?
127
+ @github.pull_requests.list @options[:user],
128
+ @options[:project],
129
+ state: "closed"
130
+ else
131
+ @github.pull_requests.list @options[:user],
132
+ @options[:project],
133
+ state: "closed",
134
+ base: @options[:release_branch]
135
+ end
136
+ page_i = 0
137
+ count_pages = response.count_pages
138
+ response.each_page do |page|
139
+ page_i += PER_PAGE_NUMBER
140
+ log_string = "Fetching merged dates... #{page_i}/#{count_pages * PER_PAGE_NUMBER}"
141
+ print_in_same_line(log_string)
142
+ pull_requests.concat(page)
143
+ end
144
+ print_empty_line
145
+ rescue
146
+ Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
147
+ end
148
+
149
+ Helper.log.info "Fetching merged dates: #{pull_requests.count}"
150
+ pull_requests
151
+ end
152
+
153
+ # Print specified line on the same string
154
+ # @param [String] log_string
155
+ def print_in_same_line(log_string)
156
+ print log_string + "\r"
157
+ end
158
+
159
+ # Print long line with spaces on same line to clear prev message
160
+ def print_empty_line
161
+ print_in_same_line(" ")
162
+ end
163
+
164
+ # Fetch event for all issues and add them to :events
165
+ # @param [Array] issues
166
+ # @return [Void]
167
+ def fetch_events_async(issues)
168
+ i = 0
169
+ max_thread_number = 50
170
+ threads = []
171
+ issues.each_slice(max_thread_number) do |issues_slice|
172
+ issues_slice.each do |issue|
173
+ threads << Thread.new do
174
+ begin
175
+ response = @github.issues.events.list user: @options[:user],
176
+ repo: @options[:project],
177
+ issue_number: issue["number"]
178
+ issue[:events] = []
179
+ response.each_page do |page|
180
+ issue[:events].concat(page)
181
+ end
182
+ rescue
183
+ Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
184
+ end
185
+ print_in_same_line("Fetching events for issues and PR: #{i + 1}/#{issues.count}")
186
+ i += 1
187
+ end
188
+ end
189
+ threads.each(&:join)
190
+ threads = []
191
+ end
192
+
193
+ # to clear line from prev print
194
+ print_empty_line
195
+
196
+ Helper.log.info "Fetching events for issues and PR: #{i}"
197
+ end
198
+
199
+ # Fetch tag time from repo
200
+ #
201
+ # @param [Hash] tag
202
+ # @return [Time] time of specified tag
203
+ def fetch_date_of_tag(tag)
204
+ begin
205
+ commit_data = @github.git_data.commits.get @options[:user],
206
+ @options[:project],
207
+ tag["commit"]["sha"]
208
+ rescue
209
+ Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
210
+ end
211
+ time_string = commit_data["committer"]["date"]
212
+ Time.parse(time_string)
213
+ end
214
+
215
+ # Fetch commit for specified event
216
+ # @return [Hash]
217
+ def fetch_commit(event)
218
+ @github.git_data.commits.get @options[:user], @options[:project], event[:commit_id]
219
+ end
220
+ end
221
+ end