agile-cli 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/agile/commands/init.rb +4 -8
- data/lib/agile/commands/login.rb +34 -13
- data/lib/agile/commands/projects.rb +17 -24
- data/lib/agile/commands/remotes.rb +10 -14
- data/lib/agile/constants.rb +3 -9
- data/spec/agile/init_spec.rb +36 -0
- data/spec/agile/remote_spec.rb +94 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2dbfc91b566b6a16cea9bf61b50fb084bca009860b8abeba522d2aae66223c05
|
4
|
+
data.tar.gz: 76768f714d22d45b2c98b038e56d7ed457e84126e8b3f834334449573a918013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ecfd2115cba80ebe0053a8bfb4a358b38330fe41cb724d9d98270747eba9e6f98dc405330468cddd80bc160170c72f4a0dd07162eb7bc1768e2a196a8937b3
|
7
|
+
data.tar.gz: cac2c09e124c17a1b74932fe7f3a8e870c45359aad5e4aa13fdcfb1a48f496e80b1ad54cc7fe801fba2c0c6c440ae2c793c22369f0f24019eef9b2a112626df4
|
data/lib/agile/commands/init.rb
CHANGED
@@ -5,18 +5,14 @@ module Agile
|
|
5
5
|
desc Rainbow("init REMOTE_URL").cornflower, Rainbow("Add default remote").darkgoldenrod
|
6
6
|
|
7
7
|
def init(remote)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
say "Successfully added new remote!"
|
12
|
-
else
|
13
|
-
say "It's not a url!"
|
14
|
-
end
|
8
|
+
error_checking_init
|
9
|
+
write_remote_to_config(remote)
|
10
|
+
say "Successfully added new remote!"
|
15
11
|
end
|
16
12
|
|
17
13
|
private
|
18
14
|
|
19
|
-
def
|
15
|
+
def error_checking_init
|
20
16
|
abort "You've already did init! Try to add more remotes" if CONFIG["current_remote"]
|
21
17
|
end
|
22
18
|
|
data/lib/agile/commands/login.rb
CHANGED
@@ -1,31 +1,52 @@
|
|
1
|
-
# :reek:InstanceVariableAssumption
|
1
|
+
# :reek:InstanceVariableAssumption:TooManyStatements
|
2
|
+
|
2
3
|
module Agile
|
3
4
|
class CLI < Thor
|
4
5
|
desc Rainbow("login").cornflower, Rainbow("Sign in github.").darkgoldenrod
|
5
6
|
def login
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
say "Hello, #{login[0]}!"
|
7
|
+
error_checking_login
|
8
|
+
open_link
|
9
|
+
@secret_node = call_cli
|
10
|
+
@response = RestClient.get "#{CONFIG['current_remote']}/api/v1/users/#{@secret_node}"
|
11
|
+
if JSON.parse(@response)["data"]["attributes"]
|
12
|
+
parse_login
|
13
13
|
else
|
14
|
-
say "
|
14
|
+
say "Something went wrong"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def write_to_config(
|
21
|
-
CONFIG["current_user"] = login
|
22
|
-
CONFIG["user_node"] = secret_node
|
20
|
+
def write_to_config(login)
|
21
|
+
CONFIG["current_user"] = login
|
22
|
+
CONFIG["user_node"] = @secret_node
|
23
23
|
File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
|
24
24
|
end
|
25
25
|
|
26
|
+
def parse_login
|
27
|
+
login = JSON.parse(@response)["data"]["attributes"]["github_login"]
|
28
|
+
write_to_config(login)
|
29
|
+
say "Hello, #{login}!"
|
30
|
+
end
|
31
|
+
|
26
32
|
def call_cli
|
27
33
|
cli = HighLine.new
|
28
|
-
cli.ask("Enter your secret code: ")
|
34
|
+
cli.ask("Enter your secret code: ", String)
|
35
|
+
end
|
36
|
+
|
37
|
+
def open_link
|
38
|
+
link = "#{GITHUB_URL}/oauth/authorize?client_id=#{CLIENT_ID}"
|
39
|
+
if RbConfig::CONFIG["host_os"].match?(/mswin|mingw|cygwin/)
|
40
|
+
system "start #{link}"
|
41
|
+
elsif RbConfig::CONFIG["host_os"].match?(/darwin/)
|
42
|
+
system "open #{link}"
|
43
|
+
elsif RbConfig::CONFIG["host_os"].match?(/linux|bsd/)
|
44
|
+
system "xdg-open #{link}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def error_checking_login
|
49
|
+
abort "You haven't done init yet!" unless CONFIG["current_remote"]
|
29
50
|
end
|
30
51
|
end
|
31
52
|
end
|
@@ -3,9 +3,9 @@ module Agile
|
|
3
3
|
class Projects < Thor
|
4
4
|
desc "create <project>", "Create new project"
|
5
5
|
def create(project_name)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
error_checking_projects
|
7
|
+
if RestClient.post "#{CONFIG['current_remote']}/api/v1/projects/",
|
8
|
+
name: project_name, current_user: CONFIG["current_user"]
|
9
9
|
say "Successfully created project #{project_name}"
|
10
10
|
else
|
11
11
|
say "Try again"
|
@@ -14,44 +14,37 @@ module Agile
|
|
14
14
|
|
15
15
|
desc "list", "Show projects"
|
16
16
|
def list
|
17
|
-
|
18
|
-
response = RestClient.get "#{CONFIG['current_remote']}/api/v1/
|
17
|
+
error_checking_projects
|
18
|
+
response = RestClient.get "#{CONFIG['current_remote']}/api/v1/userproject/#{CONFIG['current_user']}"
|
19
19
|
say Rainbow("<<Your Projects>>").cornflower
|
20
|
-
JSON.parse(response).
|
20
|
+
JSON.parse(response).each do |proj|
|
21
|
+
say proj.first.values[1]
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
desc "use <project>", "Select current project"
|
24
26
|
def use(project)
|
25
|
-
|
27
|
+
error_checking_projects
|
26
28
|
response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
|
27
29
|
project_search(response, project)
|
28
30
|
end
|
29
31
|
|
30
|
-
desc "delete <project>", "Delete project"
|
31
|
-
def delete(project)
|
32
|
-
error_checking
|
33
|
-
response = RestClient.delete "#{CONFIG['current_remote']}/api/v1/projects/#{project}", name: project
|
34
|
-
if response.body
|
35
|
-
say "Successfully deleted project #{project}"
|
36
|
-
else
|
37
|
-
say "Try again"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
32
|
desc "update <project_name> <new_project_name>", "Update project name"
|
42
33
|
def update(project, new_project)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
error_checking_projects
|
35
|
+
resp = RestClient.get "#{CONFIG['current_remote']}/api/v1/userproject/#{CONFIG['current_user']}"
|
36
|
+
pr_list = JSON.parse(resp).map { |array| array.map { |hash| hash.values_at("name").include?(project) } }
|
37
|
+
if pr_list.include?([true])
|
38
|
+
RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}", name: project, new_name: new_project
|
39
|
+
say "Updated from #{project} to #{new_project}"
|
47
40
|
else
|
48
|
-
say "
|
41
|
+
say "Error"
|
49
42
|
end
|
50
43
|
end
|
51
44
|
|
52
45
|
private
|
53
46
|
|
54
|
-
def
|
47
|
+
def error_checking_projects
|
55
48
|
abort "You haven't done init yet!" unless CONFIG["current_remote"]
|
56
49
|
abort "Please, log in!" unless CONFIG["current_user"]
|
57
50
|
end
|
@@ -2,11 +2,11 @@ module Agile
|
|
2
2
|
class Remotes < Thor
|
3
3
|
desc "use <remotes url>", "Use remote"
|
4
4
|
def use(remote)
|
5
|
-
|
5
|
+
error_checking_remotes
|
6
6
|
if CONFIG["remotes"].include?(remote)
|
7
7
|
CONFIG["current_remote"] = remote
|
8
8
|
File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
|
9
|
-
say "Successfully
|
9
|
+
say "Successfully changed current remote!"
|
10
10
|
else
|
11
11
|
say "Try again"
|
12
12
|
end
|
@@ -14,31 +14,27 @@ module Agile
|
|
14
14
|
|
15
15
|
desc "add <remotes url>", "Add remote url"
|
16
16
|
def add(remote)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
say "Successfully added new remote!"
|
22
|
-
else
|
23
|
-
say "It's not a url!"
|
24
|
-
end
|
17
|
+
error_checking_remotes
|
18
|
+
CONFIG["remotes"].push(remote)
|
19
|
+
File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
|
20
|
+
say "Successfully added new remote!"
|
25
21
|
end
|
26
22
|
|
27
23
|
desc "list", "Remotes list"
|
28
24
|
def list
|
29
|
-
|
25
|
+
error_checking_remotes
|
30
26
|
CONFIG["remotes"].each do |name|
|
31
27
|
if name == CONFIG["current_remote"]
|
32
|
-
|
28
|
+
say "* #{name}"
|
33
29
|
else
|
34
|
-
|
30
|
+
say name
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
39
35
|
private
|
40
36
|
|
41
|
-
def
|
37
|
+
def error_checking_remotes
|
42
38
|
abort "You haven't done init yet!" unless CONFIG["current_remote"]
|
43
39
|
abort "Please, log in!" unless CONFIG["current_user"]
|
44
40
|
abort "You have no remotes. Try to init!" unless CONFIG["remotes"]
|
data/lib/agile/constants.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
# rubocop:disable Style/RegexpLiteral
|
2
|
-
|
3
1
|
module Agile
|
4
|
-
VERSION = "0.0.
|
5
|
-
GITHUB_URL = %(https://github.com/login)
|
2
|
+
VERSION = "0.0.13".freeze
|
3
|
+
GITHUB_URL = %(https://github.com/login).freeze
|
6
4
|
TERMINAL_STYLE = { border_x: "=", border_i: "x", padding_left: 3 }.freeze
|
7
|
-
CLIENT_ID = "8bf42da7e4f9032ac5d8"
|
8
|
-
CLIENT_SECRET = "cfef987b3839a1a846ba3f0707aa036240d2d625"
|
9
|
-
URL_PATTERN = /[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$}/
|
10
|
-
LOCALHOST_PATTERN = /localhost:/
|
5
|
+
CLIENT_ID = "8bf42da7e4f9032ac5d8".freeze
|
11
6
|
end
|
12
|
-
# rubocop:enable Style/RegexpLiteral
|
@@ -0,0 +1,36 @@
|
|
1
|
+
RSpec.describe Agile::CLI do
|
2
|
+
describe "#init" do
|
3
|
+
subject(:cli) { described_class.new }
|
4
|
+
|
5
|
+
before do
|
6
|
+
allow(cli).to receive(:say)
|
7
|
+
allow(cli).to receive(:abort)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "gives error" do
|
11
|
+
Agile::CONFIG["current_remote"] = "smth"
|
12
|
+
cli.init("smth")
|
13
|
+
expect(cli).to have_received(:abort).with("You've already did init! Try to add more remotes")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "set current remote" do
|
17
|
+
cli.init("remote")
|
18
|
+
expect(Agile::CONFIG["current_remote"]).to eq("remote")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates array of remotes" do
|
22
|
+
cli.init("remote")
|
23
|
+
expect(Agile::CONFIG["remotes"]).to eq(["remote"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "create config file" do
|
27
|
+
cli.init("remote")
|
28
|
+
expect(File.exist?("#{Agile::GEM_PATH}/.config.json")).to eq(true)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Successfully finish" do
|
32
|
+
cli.init("remote")
|
33
|
+
expect(cli).to have_received(:say).with("Successfully added new remote!")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
RSpec.describe Agile::Remotes do
|
2
|
+
subject(:remote) { described_class.new }
|
3
|
+
|
4
|
+
before do
|
5
|
+
Agile::CONFIG["remotes"].clear
|
6
|
+
Agile::CONFIG["current_user"] = "smone"
|
7
|
+
allow(remote).to receive(:error_checking_remotes)
|
8
|
+
allow(remote).to receive(:say)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#use" do
|
12
|
+
it "check for error" do
|
13
|
+
remote.use("remote")
|
14
|
+
expect(remote).to have_received(:error_checking_remotes)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "aborts when remote wasn't added" do
|
18
|
+
remote.use("remote")
|
19
|
+
expect(remote).to have_received(:say).with("Try again")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "changes remote" do
|
23
|
+
Agile::CONFIG["remotes"] << "another_remote"
|
24
|
+
remote.use("another_remote")
|
25
|
+
expect(Agile::CONFIG["current_remote"]).to eq("another_remote")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "writes to config" do
|
29
|
+
remote.use("like_a_remote")
|
30
|
+
expect(File.exist?("#{Agile::GEM_PATH}/.config.json")).to eq(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "successfully finishes" do
|
34
|
+
Agile::CONFIG["remotes"] << "remote"
|
35
|
+
remote.use("remote")
|
36
|
+
expect(remote).to have_received(:say).with("Successfully changed current remote!")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec.describe Agile::Remotes do
|
42
|
+
subject(:remote) { described_class.new }
|
43
|
+
|
44
|
+
before do
|
45
|
+
Agile::CONFIG["remotes"].clear
|
46
|
+
Agile::CONFIG["current_user"] = "smone"
|
47
|
+
allow(remote).to receive(:error_checking_remotes)
|
48
|
+
allow(remote).to receive(:say)
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#add" do
|
52
|
+
it "check for error" do
|
53
|
+
remote.add("remote")
|
54
|
+
expect(remote).to have_received(:error_checking_remotes)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "add new remote" do
|
58
|
+
remote.add("new_remote")
|
59
|
+
expect(Agile::CONFIG["remotes"].include?("new_remote")).to eq(true)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "writes to config" do
|
63
|
+
remote.add("new_remote")
|
64
|
+
expect(File.exist?("#{Agile::GEM_PATH}/.config.json")).to eq(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "successfully finishes" do
|
68
|
+
remote.add("new_remote")
|
69
|
+
expect(remote).to have_received(:say).with("Successfully added new remote!")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
RSpec.describe Agile::Remotes do
|
75
|
+
subject(:remote) { described_class.new }
|
76
|
+
|
77
|
+
before do
|
78
|
+
Agile::CONFIG["current_user"] = "smone"
|
79
|
+
allow(remote).to receive(:error_checking_remotes)
|
80
|
+
allow(remote).to receive(:say)
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#list" do
|
84
|
+
it "check for error" do
|
85
|
+
remote.list
|
86
|
+
expect(remote).to have_received(:error_checking_remotes)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "shows all remotes" do
|
90
|
+
remote.list
|
91
|
+
expect(remote).to have_received(:say).exactly(Agile::CONFIG["remotes"].count).times
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agile-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rubizza-camp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -249,7 +249,9 @@ files:
|
|
249
249
|
- spec/agile/dod_spec.rb
|
250
250
|
- spec/agile/dor_spec.rb
|
251
251
|
- spec/agile/hello_spec.rb
|
252
|
+
- spec/agile/init_spec.rb
|
252
253
|
- spec/agile/principles_spec.rb
|
254
|
+
- spec/agile/remote_spec.rb
|
253
255
|
- spec/agile/values_spec.rb
|
254
256
|
- spec/agile/version_spec.rb
|
255
257
|
- spec/spec_helper.rb
|