Add token support, resolved #19.
Use CHANGELOG_GITHUB_TOKEN variable to specify token in the shell.
This commit is contained in:
parent
91229c7472
commit
03bca478c8
1
Gemfile
1
Gemfile
|
@ -1,3 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
gem 'github_api'
|
||||
gem 'httparty'
|
||||
gem 'colorize'
|
||||
|
|
|
@ -2,6 +2,7 @@ GEM
|
|||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.3.6)
|
||||
colorize (0.7.3)
|
||||
descendants_tracker (0.0.4)
|
||||
thread_safe (~> 0.3, >= 0.3.1)
|
||||
faraday (0.9.0)
|
||||
|
@ -39,5 +40,6 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
colorize
|
||||
github_api
|
||||
httparty
|
||||
|
|
|
@ -49,7 +49,14 @@ Type `github_changelog_generator --help` for detailed usage.
|
|||
|
||||
|
||||
## FAQ:
|
||||
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 script with token
|
||||
|
||||
**You can easily [generate it here](https://github.com/settings/applications)**.
|
||||
|
||||
And:
|
||||
|
||||
- Run with key `-t [your-16-digit-token]` that
|
||||
- Or add to your shell variable CHANGELOG_GITHUB_TOKEN and specify there your token
|
||||
|
||||
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'
|
||||
|
|
|
@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|||
s.license = "MIT"
|
||||
s.add_runtime_dependency(%q<httparty>, ["~> 0.13"])
|
||||
s.add_runtime_dependency(%q<github_api>, ["~> 0.12"])
|
||||
s.add_runtime_dependency(%q<colorize>, ["~> 0.7"])
|
||||
|
||||
s.executables = %w(github_changelog_generator)
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
require 'github_api'
|
||||
require 'json'
|
||||
require 'httparty'
|
||||
require 'colorize'
|
||||
require_relative 'github_changelog_generator/parser'
|
||||
|
||||
|
||||
|
@ -13,11 +14,15 @@ class ChangelogGenerator
|
|||
def initialize()
|
||||
|
||||
@options = Parser.parse_options
|
||||
if @options[:token]
|
||||
@github = Github.new oauth_token: @options[:token]
|
||||
else
|
||||
|
||||
github_token
|
||||
|
||||
if @github_token.nil?
|
||||
@github = Github.new
|
||||
else
|
||||
@github = Github.new oauth_token: @github_token
|
||||
end
|
||||
|
||||
@all_tags = self.get_all_tags
|
||||
@pull_requests = self.get_all_closed_pull_requests
|
||||
@issues = self.get_all_issues
|
||||
|
@ -113,13 +118,13 @@ class ChangelogGenerator
|
|||
puts "Receive tags for repo #{url}"
|
||||
end
|
||||
|
||||
if @options[:token]
|
||||
response = HTTParty.get(url,
|
||||
:headers => {'Authorization' => "token #{@options[:token]}",
|
||||
'User-Agent' => 'Changelog-Generator'})
|
||||
else
|
||||
if @github_token.nil?
|
||||
response = HTTParty.get(url,
|
||||
:headers => {'User-Agent' => 'Changelog-Generator'})
|
||||
else
|
||||
response = HTTParty.get(url,
|
||||
:headers => {'Authorization' => "token #{@github_token}",
|
||||
'User-Agent' => 'Changelog-Generator'})
|
||||
end
|
||||
|
||||
json_parse = JSON.parse(response.body)
|
||||
|
@ -131,6 +136,23 @@ class ChangelogGenerator
|
|||
json_parse
|
||||
end
|
||||
|
||||
def github_token
|
||||
if @options[:token]
|
||||
return @github_token ||= @options[:token]
|
||||
end
|
||||
|
||||
env_var = ENV.fetch 'CHANGELOG_GITHUB_TOKEN', nil
|
||||
|
||||
unless env_var
|
||||
puts "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
|
||||
puts "This script can make only 50 requests to GitHub API per hour without token!".yellow
|
||||
end
|
||||
|
||||
@github_token ||= env_var
|
||||
|
||||
end
|
||||
|
||||
|
||||
def generate_log_between_tags(since_tag, till_tag)
|
||||
since_tag_time = self.get_time_of_tag(since_tag)
|
||||
till_tag_time = self.get_time_of_tag(till_tag)
|
||||
|
@ -325,5 +347,5 @@ end
|
|||
|
||||
if __FILE__ == $0
|
||||
changelog_generator = ChangelogGenerator.new
|
||||
changelog_generator.compund_changelog
|
||||
# changelog_generator.compund_changelog
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ class Parser
|
|||
opts.on('-p', '--project [PROJECT]', 'Name of project on GitHub') do |last|
|
||||
options[:project] = last
|
||||
end
|
||||
opts.on('-t', '--token [TOKEN]', 'To make more than 50 requests this script required your OAuth token for GitHub. You can generate 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 here: https://github.com/settings/tokens/new') do |last|
|
||||
options[:token] = last
|
||||
end
|
||||
opts.on('-h', '--help', 'Displays Help') do
|
||||
|
|
Loading…
Reference in New Issue
Block a user