Merge pull request #401 from skywinder/fix-397

Ability to implicity set user and project from command line
This commit is contained in:
Olle Jonsson 2016-07-22 09:06:44 +02:00 committed by GitHub
commit 226748d8ff
2 changed files with 33 additions and 11 deletions

View File

@ -61,7 +61,7 @@ module GitHubChangelogGenerator
opts.on("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last| opts.on("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last|
options[:base] = last options[:base] = last
end end
opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v| opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**\"") do |v|
options[:bug_prefix] = v options[:bug_prefix] = v
end end
opts.on("--enhancement-label [LABEL]", "Setup custom label for enhancements section. Default is \"**Implemented enhancements:**\"") do |v| opts.on("--enhancement-label [LABEL]", "Setup custom label for enhancements section. Default is \"**Implemented enhancements:**\"") do |v|
@ -213,24 +213,31 @@ module GitHubChangelogGenerator
# 2) in 2 params: repo name project # 2) in 2 params: repo name project
def self.fetch_user_and_project(options) def self.fetch_user_and_project(options)
if options[:user].nil? || options[:project].nil? if options[:user].nil? || options[:project].nil?
user_and_project_from_git(options, ARGV[0], ARGV[1]) user, project = user_and_project_from_git(options, ARGV[0], ARGV[1])
options[:user] ||= user
options[:project] ||= project
end end
end end
# Sets `:user` and `:project` in `options` from CLI arguments or `git remote` # Sets `:user` and `:project` in `options` from CLI arguments or `git remote`
# @param [String] arg0 first argument in cli
# @param [String] arg1 second argument in cli
# @return [Array<String>] user and project, or nil if unsuccessful
def self.user_and_project_from_git(options, arg0 = nil, arg1 = nil) def self.user_and_project_from_git(options, arg0 = nil, arg1 = nil)
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site]) user, project = user_project_from_option(arg0, arg1, options[:github_site])
return if options[:user] && options[:project] unless user && project
if ENV["RUBYLIB"] =~ /ruby-debug-ide/ if ENV["RUBYLIB"] =~ /ruby-debug-ide/
options[:user] = "skywinder" user = "skywinder"
options[:project] = "changelog_test" project = "changelog_test"
else else
remote = `git config --get remote.#{options[:git_remote]}.url` remote = `git config --get remote.#{options[:git_remote]}.url`
options[:user], options[:project] = user_project_from_remote(remote) user, project = user_project_from_remote(remote)
end end
end end
[user, project]
end
# Returns GitHub username and project from CLI arguments # Returns GitHub username and project from CLI arguments
# #
# @param arg0 [String] This parameter takes two forms: Either a full # @param arg0 [String] This parameter takes two forms: Either a full

View File

@ -62,4 +62,19 @@ describe GitHubChangelogGenerator::Parser do
it { is_expected.to match_array([nil, nil]) } it { is_expected.to match_array([nil, nil]) }
end end
end end
describe ".fetch_user_and_project" do
before :each do
ARGV = ["https://github.com/skywinder/github-changelog-generator"]
end
context do
let(:valid_user) { "initialized_user" }
let(:options) { { user: valid_user } }
let(:options_before_change) { options.dup }
it "should leave user unchanged" do
expect { GitHubChangelogGenerator::Parser.fetch_user_and_project(options) }.to change { options }
.from(options_before_change)
.to(options_before_change.merge(project: "github-changelog-generator"))
end
end
end
end end