Skip to content

Commit

Permalink
Merge branch 'ask-for-password'
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Shearar committed Jun 26, 2013
2 parents 1584f00 + 0d7e872 commit 38dc01c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'http://rubygems.org'
gem 'highline'
gem 'json', '~> 1.7.7'
gem 'octokit'
gem 'rake'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GEM
hamsterdam (1.0.8)
hamster
hashie (2.0.5)
highline (1.6.19)
json (1.7.7)
listen (1.1.4)
rb-fsevent (>= 0.9.3)
Expand Down Expand Up @@ -84,6 +85,7 @@ DEPENDENCIES
coveralls
guard-rspec
hamsterdam
highline
json (~> 1.7.7)
octokit
pry
Expand Down
8 changes: 7 additions & 1 deletion lib/octoherder/cli.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'octoherder'
require 'highline'
require 'trollop'


Expand All @@ -11,7 +12,7 @@ def self.parse_argv(args)
OctoHerder helps you manage your multi-repository project.
Usage:
octoherder [options]
where [options] are:
HELP
Expand All @@ -36,6 +37,11 @@ def self.parse_argv(args)

def self.run(args)
opts = parse_argv(args)
if ! opts[:password_given] then
opts[:password_given] = true
opts[:password] = HighLine.new.ask("Enter password: ") { |q| q.echo = false }
end

kitty = Octokit.new(octoauth(opts))
CLI.new.run kitty, opts
end
Expand Down
7 changes: 6 additions & 1 deletion lib/octoherder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'time'
require 'safe_yaml'

SafeYAML::OPTIONS[:default_mode] = :safe

module OctoHerder
NEUTRAL_TONE = '#cccccc'

Expand Down Expand Up @@ -111,7 +113,10 @@ def update_milestones octokit_connection
def to_octokit_opts hash
opts = hash.dup
opts.delete 'title'
opts['due_on'] = opts['due_on'].iso8601 if opts['due_on']
# Sometimes dates get read in and autoconverted to a Time and sometimes not.
if opts['due_on'] && opts['due_on'].kind_of?(String) then
opts['due_on'] = DateTime.iso8601(opts['due_on'])
end
opts
end

Expand Down
21 changes: 20 additions & 1 deletion spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def run(args, octokit_connection)
OctoHerder helps you manage your multi-repository project.
Usage:
octoherder [options]
where [options] are:
--input-file, -i <filename/uri>: Path to the canonical project setup
Expand Down Expand Up @@ -133,6 +133,25 @@ def run(args, octokit_connection)
kitty.should_receive(:password).with(password)
run(["--user", "me", "--password", password], kitty)
end

it "will prompt for a password if none given" do
orig_stdin = $stdin
begin
$stdin = StringIO.new("1234", "r")
orig_stdout = $stdout
begin
$stdout = StringIO.new("", "w+")

CLI.run(["--user", "me"])
$stdout.rewind
expect($stdout.read).to include("password")
ensure
$stdout = orig_stdout
end
ensure
$stdin = orig_stdin
end
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module OctoHerder
connection.stub(:create_milestone)

connection.should_receive(:create_milestone).with(an_instance_of(Octokit::Repository), 'milestone-1', {'state' => 'closed'}).exactly(repo_count).times
connection.should_receive(:create_milestone).with(an_instance_of(Octokit::Repository), 'milestone-2', {'due_on' => '2011-04-10T20:09:31Z'}).exactly(repo_count).times
connection.should_receive(:create_milestone).with(an_instance_of(Octokit::Repository), 'milestone-2', {'due_on' => Time.iso8601('2011-04-10T20:09:31Z')}).exactly(repo_count).times
connection.should_receive(:create_milestone).with(an_instance_of(Octokit::Repository), 'milestone-3', {'state' => 'open', 'description' => 'The third step in total world domination.'}).exactly(repo_count).times

conf.update_milestones connection
Expand All @@ -118,7 +118,7 @@ module OctoHerder
connection.stub(:update_milestone)

connection.should_receive(:update_milestone).with(an_instance_of(Octokit::Repository), 1, {'state' => 'closed'}).exactly(repo_count).times
connection.should_receive(:update_milestone).with(an_instance_of(Octokit::Repository), 2, {'due_on' => '2011-04-10T20:09:31Z'}).exactly(repo_count).times
connection.should_receive(:update_milestone).with(an_instance_of(Octokit::Repository), 2, {'due_on' => Time.iso8601('2011-04-10T20:09:31Z')}).exactly(repo_count).times
connection.should_receive(:update_milestone).with(an_instance_of(Octokit::Repository), 3, {'state' => 'open', 'description' => 'The third step in total world domination.'}).exactly(repo_count).times

conf.update_milestones connection
Expand Down

0 comments on commit 38dc01c

Please sign in to comment.