agile-cli 0.0.11 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8343b20f864b9087c903e2bdf4a0c7dbc879dbd0675e98918c235d4fa88b18ef
4
- data.tar.gz: 07bdd7283c5ec3f56f6b6556da4aa27df85a88cf08dd69e907ab0103ce32eb80
3
+ metadata.gz: e4a0fc2a675123cfb741925947c8bfb324d8df7cb82c561c3d9c671a4c84c3ef
4
+ data.tar.gz: cfa82e1635468ef2f176fae5185a582799f460930992d28ef2a3b3b1840ba84c
5
5
  SHA512:
6
- metadata.gz: 5714b3d98508a8a58c8c255d3e0e7ece917eb2f1b793c458dd864b92ee1ba01c46d9181d3a2b94888ab2c083beeaf7dd16af81d16370af0b21f7e7cee4009abb
7
- data.tar.gz: 5d94825a5ce075551dbdd5691813ffd15549cc17a45d0440a1216e483ca4506805f8147ca2f27397cbb32df8dd7662261dc844208614bb97032adbc1c3b26155
6
+ metadata.gz: 936274daaa02999b806b3cb925aa0b120e81dfbab226e05126db3bb9ef5674d4d9734e30625475733bad637ecd663b767c872108bb3e5c70bcddc8ed55b02d0c
7
+ data.tar.gz: 6a34fe8113bda4a70ecfb223a55a9b0783baa542390991499f3ca637e9e8e7993a934c0982df1fd54365f47a1f057c47173152a697d5f3a3926ec090e3aa873a
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
9
+ lib/.config.json
10
+ Gemfile.lock
11
+ .idea/
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agile-cli (0.0.10)
4
+ agile-cli (0.0.11)
5
+ highline (~> 2.0.2)
5
6
  rainbow (~> 3.0.0)
6
7
  rest-client (~> 2.0.2)
7
8
  terminal-table (~> 1.8.0)
@@ -35,6 +36,7 @@ GEM
35
36
  equalizer (0.0.11)
36
37
  factory_bot (5.0.2)
37
38
  activesupport (>= 4.2.0)
39
+ highline (2.0.2)
38
40
  http-cookie (1.0.3)
39
41
  domain_name (~> 0.5)
40
42
  i18n (1.6.0)
data/agile-cli.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.require_paths = ["lib"]
14
14
  spec.executables = ["agile"]
15
15
 
16
+ spec.add_dependency "highline", "~> 2.0.2"
16
17
  spec.add_dependency "rainbow", "~> 3.0.0"
17
18
  spec.add_dependency "rest-client", "~> 2.0.2"
18
19
  spec.add_dependency "terminal-table", "~> 1.8.0"
@@ -5,16 +5,25 @@ module Agile
5
5
  desc Rainbow("init REMOTE_URL").cornflower, Rainbow("Add default remote").darkgoldenrod
6
6
 
7
7
  def init(remote)
8
- create_config_file
9
- CONFIG["current_remote"] = remote
10
- File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
11
- say "Successfully added new remote!"
8
+ error_checking
9
+ if remote =~ URL_PATTERN || remote =~ LOCALHOST_PATTERN
10
+ write_remote_to_config(remote)
11
+ say "Successfully added new remote!"
12
+ else
13
+ say "It's not a url!"
14
+ end
12
15
  end
13
16
 
14
17
  private
15
-
16
- def create_config_file
17
- `touch #{GEM_PATH}.config.json` if `find "#{GEM_PATH}" -name .config.json`.empty?
18
+
19
+ def error_checking
20
+ abort "You've already did init! Try to add more remotes" if CONFIG["current_remote"]
21
+ end
22
+
23
+ def write_remote_to_config(remote)
24
+ CONFIG["current_remote"] = remote
25
+ CONFIG["remotes"] = [remote]
26
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
18
27
  end
19
28
  end
20
29
  end
@@ -1,30 +1,31 @@
1
1
  # :reek:InstanceVariableAssumption
2
2
  module Agile
3
3
  class CLI < Thor
4
- desc Rainbow("login LOGIN_FROM_GITHUB").cornflower, Rainbow("Sign in github.").darkgoldenrod
5
- def login(username)
4
+ desc Rainbow("login").cornflower, Rainbow("Sign in github.").darkgoldenrod
5
+ def login
6
6
  if CONFIG
7
- write_to_config(username)
8
- authorize
7
+ `open "#{GITHUB_URL}/oauth/authorize?client_id=#{CLIENT_ID}"`
8
+ secret_node = call_cli
9
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/users/#{secret_node}"
10
+ login = JSON.parse(response).map { |hash| hash[1]["attributes"]["github_login"] }
11
+ write_to_config(secret_node, login)
12
+ say "Hello, #{login[0]}!"
9
13
  else
10
- say "You need to add a remote!"
14
+ say "You need to init!"
11
15
  end
12
16
  end
13
17
 
14
18
  private
15
19
 
16
- def github_user_login(username)
17
- @curr_user = JSON.parse(`curl -s -u "#{username}" "#{GITHUB_URL}"`)["login"]
18
- end
19
-
20
- def authorize
21
- RestClient.get "#{CONFIG['current_remote']}/api/v1/users/#{@curr_user}"
22
- say "Hello, #{@curr_user}" if @curr_user
20
+ def write_to_config(secret_node, login)
21
+ CONFIG["current_user"] = login[0]
22
+ CONFIG["user_node"] = secret_node
23
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
23
24
  end
24
25
 
25
- def write_to_config(username)
26
- CONFIG["current_user"] = github_user_login(username)
27
- File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
26
+ def call_cli
27
+ cli = HighLine.new
28
+ cli.ask("Enter your secret code: ")
28
29
  end
29
30
  end
30
- end
31
+ end
@@ -2,10 +2,11 @@
2
2
  module Agile
3
3
  class Projects < Thor
4
4
  desc "create <project>", "Create new project"
5
- def create(project_name)
5
+ def create(project_name)
6
+ error_checking
6
7
  response = RestClient.post "#{CONFIG['current_remote']}/api/v1/projects/", { name: project_name }
7
8
  if response.body
8
- say "Successelly create project #{project_name}"
9
+ say "Successfully created project #{project_name}"
9
10
  else
10
11
  say "Try again"
11
12
  end
@@ -13,29 +14,25 @@ module Agile
13
14
 
14
15
  desc "list", "Show projects"
15
16
  def list
17
+ error_checking
16
18
  response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
17
- data = JSON.parse(response)
18
- array = data.map { |hash| hash.values }
19
- info = array.map { |hash| hash[1]}
20
19
  say Rainbow("<<Your Projects>>").cornflower
21
- info.map { |name| p name }
20
+ JSON.parse(response).map { |hash| p hash.values[1] }
22
21
  end
23
22
 
24
23
  desc "use <project>", "Select current project"
25
24
  def use(project)
26
- if CONFIG
27
- response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
28
- else
29
- say "You need to add a remote!"
30
- end
25
+ error_checking
26
+ response = RestClient.get "#{CONFIG['current_remote']}/api/v1/projects/"
31
27
  project_search(response, project)
32
28
  end
33
29
 
34
30
  desc "delete <project>", "Delete project"
35
31
  def delete(project)
36
- response = RestClient.delete "#{CONFIG['current_remote']}/api/v1/projects/#{project}", { name: project}
32
+ error_checking
33
+ response = RestClient.delete "#{CONFIG['current_remote']}/api/v1/projects/#{project}", name: project
37
34
  if response.body
38
- say "Successelly delete project #{project}"
35
+ say "Successfully deleted project #{project}"
39
36
  else
40
37
  say "Try again"
41
38
  end
@@ -43,26 +40,30 @@ module Agile
43
40
 
44
41
  desc "update <project_name> <new_project_name>", "Update project name"
45
42
  def update(project, new_project)
43
+ error_checking
46
44
  response = RestClient.put "#{CONFIG['current_remote']}/api/v1/projects/#{project}", name: project, new_name: new_project
47
45
  if response.body
48
- say "Successelly update project #{project}"
46
+ say "Successfully updated project #{project}"
49
47
  else
50
48
  say "Try again"
51
49
  end
52
50
  end
53
-
51
+
54
52
  private
55
53
 
54
+ def error_checking
55
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
56
+ abort "Please, log in!" unless CONFIG["current_user"]
57
+ end
58
+
56
59
  def project_search(response, project)
57
- array = JSON.parse(response)
58
- info = array.map { |hash| hash.values }
59
- names = info.map{ |hash| hash[1] }
60
- if names.include?(project)
60
+ info = JSON.parse(response).map { |hash| hash.values[1] }
61
+ if info.include?(project)
61
62
  CONFIG["current_project"] = project
62
63
  File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
63
64
  say "Your project: #{project}"
64
65
  else
65
- say "Such a project does not exist. Try again"
66
+ say "Such project does not exist. Try again"
66
67
  end
67
68
  end
68
69
  end
@@ -0,0 +1,52 @@
1
+ module Agile
2
+ class Remotes < Thor
3
+ desc "use <remotes url>", "Use remote"
4
+ def use(remote)
5
+ error_checking
6
+ if CONFIG["remotes"].include?(remote)
7
+ CONFIG["current_remote"] = remote
8
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
9
+ say "Successfully change remote!"
10
+ else
11
+ say "Try again"
12
+ end
13
+ end
14
+
15
+ desc "add <remotes url>", "Add remote url"
16
+ def add(remote)
17
+ error_checking
18
+ if remote =~ URL_PATTERN || remote =~ LOCALHOST_PATTERN
19
+ CONFIG["remotes"].push(remote)
20
+ File.write("#{GEM_PATH}.config.json", JSON.generate(CONFIG))
21
+ say "Successfully added new remote!"
22
+ else
23
+ say "It's not a url!"
24
+ end
25
+ end
26
+
27
+ desc "list", "Remotes list"
28
+ def list
29
+ error_checking
30
+ CONFIG["remotes"].each do |name|
31
+ if name == CONFIG["current_remote"]
32
+ p "* #{name}"
33
+ else
34
+ p name
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def error_checking
42
+ abort "You haven't done init yet!" unless CONFIG["current_remote"]
43
+ abort "Please, log in!" unless CONFIG["current_user"]
44
+ abort "You have no remotes. Try to init!" unless CONFIG["remotes"]
45
+ end
46
+ end
47
+
48
+ class CLI < Thor
49
+ desc Rainbow("remotes SUBCOMMAND ...ARGS").cornflower, Rainbow("Command for work with remotes").darkgoldenrod
50
+ subcommand "remotes", Remotes
51
+ end
52
+ end
@@ -1,7 +1,12 @@
1
- # frozen_string_literal: true
1
+ # rubocop:disable Style/RegexpLiteral
2
2
 
3
3
  module Agile
4
- VERSION = "0.0.11"
5
- GITHUB_URL = %(https://api.github.com/user)
4
+ VERSION = "0.0.12"
5
+ GITHUB_URL = %(https://github.com/login)
6
6
  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:/
7
11
  end
12
+ # rubocop:enable Style/RegexpLiteral
data/lib/agile.rb CHANGED
@@ -4,10 +4,16 @@ require "agile/constants"
4
4
  require "json"
5
5
  require "rest-client"
6
6
  require "terminal-table"
7
+ require "highline"
7
8
  Dir[File.join(__dir__, "agile/commands", "*.rb")].each { |file| require file }
8
9
 
9
10
  module Agile
10
11
  GEM_PATH = `gem which agile`.chomp.chomp("agile.rb")
12
+ if `find "#{GEM_PATH}" -name .config.json`.empty?
13
+ `touch #{GEM_PATH}.config.json`
14
+ File.write("#{GEM_PATH}.config.json", {})
15
+ end
16
+
11
17
  CONFIG = JSON.parse(File.read("#{GEM_PATH}.config.json"))
12
18
 
13
19
  class CLI < Thor
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agile-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
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-17 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rainbow
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -213,7 +227,6 @@ files:
213
227
  - agile-cli.gemspec
214
228
  - bin/agile
215
229
  - bin/setup
216
- - lib/.config.json
217
230
  - lib/agile.rb
218
231
  - lib/agile/assets/agile_principles.txt
219
232
  - lib/agile/assets/agile_values.txt
@@ -229,6 +242,7 @@ files:
229
242
  - lib/agile/commands/manifesto.rb
230
243
  - lib/agile/commands/principles.rb
231
244
  - lib/agile/commands/projects.rb
245
+ - lib/agile/commands/remotes.rb
232
246
  - lib/agile/commands/values.rb
233
247
  - lib/agile/commands/version.rb
234
248
  - lib/agile/constants.rb
data/lib/.config.json DELETED
@@ -1 +0,0 @@
1
- {"current_remote":"localhost:3000","current_user":"nieisnuje","current_project":"AgileCli"}