mortar 0.15.25 → 0.15.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mortar/auth.rb +11 -3
- data/lib/mortar/command/base.rb +29 -1
- data/lib/mortar/command/projects.rb +4 -0
- data/lib/mortar/helpers.rb +11 -0
- data/lib/mortar/version.rb +1 -1
- data/spec/mortar/auth_spec.rb +2 -2
- data/spec/mortar/command/projects_spec.rb +54 -1
- metadata +7 -7
data/lib/mortar/auth.rb
CHANGED
@@ -180,9 +180,9 @@ class Mortar::Auth
|
|
180
180
|
|
181
181
|
def ask_for_github_username
|
182
182
|
puts
|
183
|
-
puts "Please enter your
|
183
|
+
puts "Please enter your GitHub username (not email address)."
|
184
184
|
|
185
|
-
print "
|
185
|
+
print "GitHub Username: "
|
186
186
|
github_username = ask
|
187
187
|
github_username
|
188
188
|
end
|
@@ -250,11 +250,15 @@ class Mortar::Auth
|
|
250
250
|
task_id = api.update_user(@mortar_user['user_id'], {'user_github_username' => @github_username}).body['task_id']
|
251
251
|
|
252
252
|
task_result = nil
|
253
|
+
user_result = nil
|
253
254
|
ticking(polling_interval) do |ticks|
|
254
255
|
task_result = api.get_task(task_id).body
|
255
256
|
is_finished =
|
256
257
|
Mortar::API::Task::STATUSES_COMPLETE.include?(task_result["status_code"])
|
257
|
-
|
258
|
+
if is_finished
|
259
|
+
user_result = api.get_user().body
|
260
|
+
end
|
261
|
+
|
258
262
|
redisplay("Setting github username: %s" %
|
259
263
|
[is_finished ? " Done!" : spinner(ticks)],
|
260
264
|
is_finished) # only display newline on last message
|
@@ -272,6 +276,10 @@ class Mortar::Auth
|
|
272
276
|
raise Mortar::CLI::Errors::InvalidGithubUsername.new
|
273
277
|
when Mortar::API::Task::STATUS_SUCCESS
|
274
278
|
display "Successfully set github username."
|
279
|
+
|
280
|
+
if user_result['github_team_state'] == 'pending'
|
281
|
+
display pending_github_team_state_message(user_result['github_accept_invite_url'])
|
282
|
+
end
|
275
283
|
else
|
276
284
|
#Raise error so .netrc file is wiped out.
|
277
285
|
raise RuntimeError, "Unknown task status: #{task_result['status_code']}"
|
data/lib/mortar/command/base.rb
CHANGED
@@ -451,6 +451,34 @@ protected
|
|
451
451
|
pigscript
|
452
452
|
end
|
453
453
|
|
454
|
+
def validate_github_username()
|
455
|
+
user_result = api.get_user().body
|
456
|
+
task_id = api.update_user(user_result['user_id'], {'github_team_state' => true}).body['task_id']
|
457
|
+
|
458
|
+
task_result = nil
|
459
|
+
user_result = nil
|
460
|
+
ticking(polling_interval) do |ticks|
|
461
|
+
task_result = api.get_task(task_id).body
|
462
|
+
is_finished =
|
463
|
+
Mortar::API::Task::STATUSES_COMPLETE.include?(task_result["status_code"])
|
464
|
+
if is_finished
|
465
|
+
user_result = api.get_user().body
|
466
|
+
end
|
467
|
+
|
468
|
+
redisplay("Verifying GitHub username: %s" %
|
469
|
+
[is_finished ? " Done!" : spinner(ticks)],
|
470
|
+
is_finished) # only display newline on last message
|
471
|
+
if is_finished
|
472
|
+
display
|
473
|
+
break
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
if user_result['github_team_state'] == 'pending'
|
478
|
+
error(pending_github_team_state_message(user_result['github_accept_invite_url']))
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
454
482
|
def extract_project_in_dir_no_git()
|
455
483
|
current_dirs = Dir.glob("*/")
|
456
484
|
missing_dir = Mortar::Project::Project.required_directories.find do |required_dir|
|
@@ -534,7 +562,7 @@ protected
|
|
534
562
|
def default_git_organization
|
535
563
|
"mortarcode"
|
536
564
|
end
|
537
|
-
|
565
|
+
|
538
566
|
def polling_interval
|
539
567
|
(options[:polling_interval] || 2.0).to_f
|
540
568
|
end
|
@@ -102,6 +102,8 @@ class Mortar::Command::Projects < Mortar::Command::Base
|
|
102
102
|
ask_public(is_public)
|
103
103
|
end
|
104
104
|
validate_project_name(name)
|
105
|
+
validate_github_username
|
106
|
+
|
105
107
|
project_id = register_api_call(name,is_public)
|
106
108
|
Mortar::Command::run("generate:project", [name])
|
107
109
|
FileUtils.cd(name)
|
@@ -195,6 +197,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
|
|
195
197
|
error("Usage: mortar projects:clone PROJECT\nMust specify PROJECT.")
|
196
198
|
end
|
197
199
|
validate_arguments!
|
200
|
+
validate_github_username
|
198
201
|
projects = api.get_projects().body["projects"]
|
199
202
|
project = projects.find{|p| p['name'] == name}
|
200
203
|
unless project
|
@@ -226,6 +229,7 @@ class Mortar::Command::Projects < Mortar::Command::Base
|
|
226
229
|
end
|
227
230
|
validate_arguments!
|
228
231
|
validate_project_name(name)
|
232
|
+
validate_github_username
|
229
233
|
|
230
234
|
if git.has_dot_git?
|
231
235
|
begin
|
data/lib/mortar/helpers.rb
CHANGED
@@ -526,6 +526,17 @@ module Mortar
|
|
526
526
|
end
|
527
527
|
end
|
528
528
|
|
529
|
+
def pending_github_team_state_message(invite_url)
|
530
|
+
"""
|
531
|
+
\nYour GitHub username has been set, but you must accept GitHub's invitation to
|
532
|
+
join the Mortar GitHub organization. If you have not received an email you
|
533
|
+
can visit #{invite_url} to view and accept your invitation.
|
534
|
+
|
535
|
+
You will need to accept this invitation to start using Mortar projects.
|
536
|
+
"""
|
537
|
+
end
|
538
|
+
|
539
|
+
|
529
540
|
private
|
530
541
|
|
531
542
|
def create_display_method(name, colour_code, new_line=true)
|
data/lib/mortar/version.rb
CHANGED
data/spec/mortar/auth_spec.rb
CHANGED
@@ -106,7 +106,7 @@ module Mortar
|
|
106
106
|
|
107
107
|
mock(@cli).ask_for_credentials.returns("username", "apikey")
|
108
108
|
stub(@cli).write_credentials
|
109
|
-
mock(@cli.api).get_user() {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com"})}
|
109
|
+
mock(@cli.api).get_user().times(2) {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com"})}
|
110
110
|
mock(@cli).ask_for_github_username.returns(new_github_username)
|
111
111
|
|
112
112
|
mock(@cli.api).update_user(user_id,{"user_github_username" => new_github_username}) {Excon::Response.new(:body => {"task_id" => task_id})}
|
@@ -128,7 +128,7 @@ module Mortar
|
|
128
128
|
|
129
129
|
mock(@cli).ask_for_credentials.returns("username", "apikey")
|
130
130
|
stub(@cli).write_credentials
|
131
|
-
mock(@cli.api).get_user() {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com"})}
|
131
|
+
mock(@cli.api).get_user().times(2) {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com", "github_team_state" => "active"})}
|
132
132
|
mock(@cli).ask_for_github_username.returns(new_github_username)
|
133
133
|
|
134
134
|
mock(@cli.api).update_user(user_id,{"user_github_username" => new_github_username}) {Excon::Response.new(:body => {"task_id" => task_id})}
|
@@ -18,7 +18,7 @@ require 'spec_helper'
|
|
18
18
|
require 'fakefs/spec_helpers'
|
19
19
|
require 'mortar/command/projects'
|
20
20
|
require 'launchy'
|
21
|
-
require
|
21
|
+
require 'mortar/api'
|
22
22
|
|
23
23
|
|
24
24
|
module Mortar::Command
|
@@ -92,8 +92,36 @@ STDOUT
|
|
92
92
|
end
|
93
93
|
|
94
94
|
context("create") do
|
95
|
+
it "tries to create a project with pending github_team_state" do
|
96
|
+
task_id = "1a2b3c4d5e"
|
97
|
+
user_id = "abcdef"
|
98
|
+
project_name = "some_new_project"
|
99
|
+
|
100
|
+
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
101
|
+
|
102
|
+
mock(Mortar::Auth.api).get_user().times(2) {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com", "github_team_state" => "pending"})}
|
103
|
+
|
104
|
+
mock(Mortar::Auth.api).update_user(user_id,{"github_team_state" => true}) {Excon::Response.new(:body => {"task_id" => task_id})}
|
105
|
+
mock(Mortar::Auth.api).get_task(task_id).returns(Excon::Response.new(:body => {"task_id" => task_id, "status_code" => "SUCCESS"})).ordered
|
106
|
+
|
107
|
+
stderr, stdout = execute("projects:create #{project_name}", nil, @git)
|
108
|
+
stdout.should == <<-STDOUT
|
109
|
+
\r\e[0KVerifying GitHub username: Done!
|
110
|
+
|
111
|
+
STDOUT
|
112
|
+
end
|
95
113
|
|
96
114
|
it "registers and generates a project" do
|
115
|
+
task_id = "1a2b3c4d5e"
|
116
|
+
user_id = "abcdef"
|
117
|
+
mock(Mortar::Auth.api).get_user().times(2) {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com", "github_team_state" => "active"})}
|
118
|
+
|
119
|
+
mock(Mortar::Auth.api).update_user(user_id,{"github_team_state" => true}) {Excon::Response.new(:body => {"task_id" => task_id})}
|
120
|
+
|
121
|
+
mock(Mortar::Auth.api).get_task(task_id).returns(Excon::Response.new(:body => {"task_id" => task_id, "status_code" => "QUEUED"})).ordered
|
122
|
+
mock(Mortar::Auth.api).get_task(task_id).returns(Excon::Response.new(:body => {"task_id" => task_id, "status_code" => "PROGRESS"})).ordered
|
123
|
+
mock(Mortar::Auth.api).get_task(task_id).returns(Excon::Response.new(:body => {"task_id" => task_id, "status_code" => "SUCCESS"})).ordered
|
124
|
+
|
97
125
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
98
126
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
99
127
|
project_id = "1234abcd1234abcd1234"
|
@@ -130,6 +158,8 @@ STDOUT
|
|
130
158
|
File.read("pigscripts/some_new_project.pig").each_line { |line| line.match(/<%.*%>/).should be_nil }
|
131
159
|
|
132
160
|
stdout.should == <<-STDOUT
|
161
|
+
\r\e[0KVerifying GitHub username: /\r\e[0KVerifying GitHub username: -\r\e[0KVerifying GitHub username: Done!
|
162
|
+
|
133
163
|
Sending request to register project: some_new_project... done
|
134
164
|
\e[1;32m create\e[0m
|
135
165
|
\e[1;32m create\e[0m README.md
|
@@ -165,6 +195,13 @@ STDOUT
|
|
165
195
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
166
196
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
167
197
|
|
198
|
+
task_id = "1a2b3c4d5e"
|
199
|
+
user_id = "abcdef"
|
200
|
+
mock(Mortar::Auth.api).get_user().times(2) {Excon::Response.new(:body => {"user_id" => user_id, "user_email" => "foo@foo.com", "github_team_state" => "active"})}
|
201
|
+
mock(Mortar::Auth.api).update_user(user_id,{"github_team_state" => true}) {Excon::Response.new(:body => {"task_id" => task_id})}
|
202
|
+
mock(Mortar::Auth.api).get_task(task_id).returns(Excon::Response.new(:body => {"task_id" => task_id, "status_code" => "SUCCESS"})).ordered
|
203
|
+
|
204
|
+
|
168
205
|
project_id = "1234abcd1234abcd1234"
|
169
206
|
project_name = "some_new_project"
|
170
207
|
project_git_url = "git@github.com:mortarcode-dev/#{project_name}"
|
@@ -426,6 +463,9 @@ STDERR
|
|
426
463
|
end
|
427
464
|
|
428
465
|
it "shows appropriate error message when user tries to clone non-existent project" do
|
466
|
+
any_instance_of(Mortar::Command::Base) do |b|
|
467
|
+
mock(b).validate_github_username.returns(true)
|
468
|
+
end
|
429
469
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
430
470
|
|
431
471
|
stderr, stdout = execute('projects:clone sillyProjectName')
|
@@ -438,6 +478,9 @@ STDERR
|
|
438
478
|
|
439
479
|
it "shows appropriate error message when user tries to clone into existing directory" do
|
440
480
|
with_no_git_directory do
|
481
|
+
any_instance_of(Mortar::Command::Base) do |b|
|
482
|
+
mock(b).validate_github_username.returns(true)
|
483
|
+
end
|
441
484
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
442
485
|
starting_dir = Dir.pwd
|
443
486
|
project_dir = File.join(Dir.pwd, project1['name'])
|
@@ -452,6 +495,9 @@ STDERR
|
|
452
495
|
end
|
453
496
|
|
454
497
|
it "calls git clone when existing project is cloned" do
|
498
|
+
any_instance_of(Mortar::Command::Base) do |b|
|
499
|
+
mock(b).validate_github_username.returns(true)
|
500
|
+
end
|
455
501
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
456
502
|
mock(@git).clone(project1['git_url'], project1['name'])
|
457
503
|
|
@@ -483,6 +529,9 @@ STDERR
|
|
483
529
|
end
|
484
530
|
|
485
531
|
it "shows error when in git repo already" do
|
532
|
+
any_instance_of(Mortar::Command::Base) do |b|
|
533
|
+
mock(b).validate_github_username.returns(true)
|
534
|
+
end
|
486
535
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
487
536
|
|
488
537
|
with_git_initialized_project do |p|
|
@@ -494,6 +543,10 @@ STDERR
|
|
494
543
|
end
|
495
544
|
|
496
545
|
it "calls correct git commands on success" do
|
546
|
+
any_instance_of(Mortar::Command::Base) do |b|
|
547
|
+
mock(b).validate_github_username.returns(true)
|
548
|
+
end
|
549
|
+
|
497
550
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
498
551
|
mock(Mortar::Auth.api).get_projects().returns(Excon::Response.new(:body => {"projects" => [project1, project2]}))
|
499
552
|
project_id = "1234abcd1234abcd1234"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mortar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 15
|
9
|
-
-
|
10
|
-
version: 0.15.
|
9
|
+
- 26
|
10
|
+
version: 0.15.26
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mortar Data
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2014-09-
|
18
|
+
date: 2014-09-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rdoc
|
@@ -41,12 +41,12 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 49
|
45
45
|
segments:
|
46
46
|
- 0
|
47
47
|
- 8
|
48
|
-
-
|
49
|
-
version: 0.8.
|
48
|
+
- 7
|
49
|
+
version: 0.8.7
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|