support enterprise github via command line options

This commit is contained in:
Lovett, Glen 2014-12-19 16:55:42 -05:00
parent ad4c20d8d8
commit 6bad92e899
2 changed files with 17 additions and 8 deletions

View File

@ -28,12 +28,12 @@ module GitHubChangelogGenerator
github_token
if @github_token.nil?
@github = Github.new per_page: PER_PAGE_NUMBER
else
@github = Github.new oauth_token: @github_token,
per_page: PER_PAGE_NUMBER
end
github_options = {per_page: PER_PAGE_NUMBER}
github_options[:oauth_token] = @github_token unless @github_token.nil?
github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil?
github_options[:site] = options[:github_endpoint] unless options[:github_site].nil?
@github = Github.new github_options
@generator = Generator.new(@options)
@ -276,8 +276,10 @@ module GitHubChangelogGenerator
# @return [String]
def create_log(pull_requests, issues, tag_name, tag_time)
github_site = options[:github_site] || 'https://github.com'
# Generate tag name and link
log = "## [#{tag_name}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
log = "## [#{tag_name}] (#{github_site}/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
#Generate date string:
time_string = tag_time.strftime @options[:format]

View File

@ -46,6 +46,12 @@ module GitHubChangelogGenerator
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('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last|
options[:github_site] = last
end
opts.on('--github-api [URL]', 'The enterprise endpoint to use for your Github API.') do |last|
options[:github_endpoint] = last
end
opts.on('-v', '--version', 'Print version number') do |v|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
exit
@ -59,8 +65,9 @@ module GitHubChangelogGenerator
parser.parse!
if ARGV[0] && !ARGV[1]
github_site = options[:github_site] ? options[:github_site] : 'github.com'
# this match should parse https://github.com/skywinder/Github-Changelog-Generator and skywinder/Github-Changelog-Generator to user and name
match = /(?:.+github\.com\/)?(.+)\/(.+)/.match(ARGV[0])
match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(ARGV[0])
if match[2].nil?
exit