Fix: Improve method of detecting owner and repository. Fix #63

This commit is contained in:
Petr Korolev 2015-03-06 16:31:47 +02:00
parent 7c85082e7d
commit 045dff7cbc

View File

@ -129,17 +129,20 @@ module GitHubChangelogGenerator
end end
if !options[:user] && !options[:project] if !options[:user] && !options[:project]
remote = `git remote -vv`.split("\n") remote = `git config --get remote.#{options[:branch]}.url`
# try to find repo in format: origin git@github.com:skywinder/Github-Changelog-Generator.git (fetch) # try to find repo in format:
remote.select { |v| v.include? options[:branch] } # origin git@github.com:skywinder/Github-Changelog-Generator.git (fetch)
match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git).*/.match(remote[0]) # git@github.com:skywinder/Github-Changelog-Generator.git
match = /.*(?:[:\/])((?:-|\w|\.)*)\/((?:-|\w|\.)*)(?:\.git).*/.match(remote)
if match && match[1] && match[2] if match && match[1] && match[2]
puts "Detected user:#{match[1]}, project:#{match[2]}" puts "Detected user:#{match[1]}, project:#{match[2]}"
options[:user], options[:project] = match[1], match[2] options[:user], options[:project] = match[1], match[2]
else else
# try to find repo in format: origin https://github.com/skywinder/ChangelogMerger (fetch) # try to find repo in format:
match = /.*\/((?:-|\w|\.)*)\/((?:-|\w|\.)*).*/.match(remote[0]) # origin https://github.com/skywinder/ChangelogMerger (fetch)
# https://github.com/skywinder/ChangelogMerger
match = /.*\/((?:-|\w|\.)*)\/((?:-|\w|\.)*).*/.match(remote)
if match && match[1] && match[2] if match && match[1] && match[2]
puts "Detected user:#{match[1]}, project:#{match[2]}" puts "Detected user:#{match[1]}, project:#{match[2]}"
options[:user], options[:project] = match[1], match[2] options[:user], options[:project] = match[1], match[2]