thorium 0.1.1 → 0.2.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/thorium +29 -12
  3. data/lib/thorium.rb +29 -12
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea7ce0f2b1656f58246d0e8ddd6b5773563d35e8
4
- data.tar.gz: a9a20275e2dee472020c31e1b38f70682e30fcbd
3
+ metadata.gz: 20252bee2e328a24c6615c68f8f8abc14cacab00
4
+ data.tar.gz: ea4b7bbcb0e19778c1db0c4ef144bc3525166d0f
5
5
  SHA512:
6
- metadata.gz: 08c5e81d2816599a0944cccb7ce754a0bfe3a19e0dd24168a18dc23e8ae652dbedff59561bd822f179630f1cc5eeb3eca26d983f821ea5ee5420e564842f9c6a
7
- data.tar.gz: bbbfa3b6aac513acaf8e918c825c9c8afda69b0226556b82f090d9cca20db4a699fc192c38d6ed276f941a8e9dbc71ea58e37602bde84c2f2d69b0358e625934
6
+ metadata.gz: 08bf16d89a1b80708129f7f166a8f66ad2f90cb5869c94d6d0c0734d13c058bd8f6046cbcbcc66cfca620ba797ee43c28241299457a47f483e7a962d20b5fd00
7
+ data.tar.gz: a2e04d20c39a04ddd83e5dec67115c203dcb59212202c025e75fca8317f17fddf928ac8ae18501d316a1d928ccb56355ae7866c38e8dd36ac67323c783bbdec0
data/bin/thorium CHANGED
@@ -40,24 +40,41 @@ module GitCLI
40
40
 
41
41
  include Thor::Actions
42
42
 
43
+ @@gh_api_url = "https://api.github.com"
44
+
43
45
  class_option :verbose, :type => :boolean, :default => 1
44
46
 
45
- desc "list", "List Github repositories"
47
+ desc "list", "Lists Github repositories"
46
48
  def list
47
49
  require 'json'
48
- username = ask("Github username: ")
49
- github_url = "https://api.github.com/users/#{username}/repos"
50
- github_repos_filepath = ENV['HOME'] + "/.thorium/github_repos_#{username}.json"
51
- # Get repos from github api
52
- get github_url, github_repos_filepath
53
- # Save response in a file
54
- response_json = File.read(github_repos_filepath)
55
- response_hash = JSON.parse(response_json)
56
- puts "#{username}'s repositories (name, ssh url, clone url)"
57
- puts "====================================================="
58
- print_table response_hash.map { |e| e.values_at("name", "ssh_url", "clone_url") }
50
+ require 'pp'
51
+ gh_uname = ask("Enter Github username: ")
52
+ puts "\nFetching Github repositories (#{gh_uname})..."
53
+ puts "------------------------------------------"
54
+ @repos = get_gh_repos(gh_uname).each_with_index.map do |e, i|
55
+ e.values_at("name", "ssh_url", "clone_url").unshift("[#{i+1}]")
56
+ end
57
+ print_table @repos
58
+ end
59
+
60
+ desc "clone", "Clones a repository from the list"
61
+ def clone
62
+ list
63
+ index = ask("Which repository would you like to clone?", :limited_to => ("1".."#{@repos.size}").to_a).to_i
64
+ protocol = ask("Select a protocol (ssh or https)?", :limited_to => ["s", "h"])
65
+ url = protocol == "s" ? @repos[index-1][2] : @repos[index-1][3]
66
+ run("git clone #{url}")
59
67
  end
60
68
 
69
+ no_commands {
70
+ def get_gh_repos(uname)
71
+ url = "#{@@gh_api_url}/users/#{uname}/repos"
72
+ gh_repos_filepath = ENV['HOME'] + "/.thorium/gh_repos_#{uname}.json"
73
+ get url, gh_repos_filepath, :verbose => false
74
+ JSON.parse File.read(gh_repos_filepath)
75
+ end
76
+ }
77
+
61
78
  end
62
79
  end
63
80
 
data/lib/thorium.rb CHANGED
@@ -40,24 +40,41 @@ module GitCLI
40
40
 
41
41
  include Thor::Actions
42
42
 
43
+ @@gh_api_url = "https://api.github.com"
44
+
43
45
  class_option :verbose, :type => :boolean, :default => 1
44
46
 
45
- desc "list", "List Github repositories"
47
+ desc "list", "Lists Github repositories"
46
48
  def list
47
49
  require 'json'
48
- username = ask("Github username: ")
49
- github_url = "https://api.github.com/users/#{username}/repos"
50
- github_repos_filepath = ENV['HOME'] + "/.thorium/github_repos_#{username}.json"
51
- # Get repos from github api
52
- get github_url, github_repos_filepath
53
- # Save response in a file
54
- response_json = File.read(github_repos_filepath)
55
- response_hash = JSON.parse(response_json)
56
- puts "#{username}'s repositories (name, ssh url, clone url)"
57
- puts "====================================================="
58
- print_table response_hash.map { |e| e.values_at("name", "ssh_url", "clone_url") }
50
+ require 'pp'
51
+ gh_uname = ask("Enter Github username: ")
52
+ puts "\nFetching Github repositories (#{gh_uname})..."
53
+ puts "------------------------------------------"
54
+ @repos = get_gh_repos(gh_uname).each_with_index.map do |e, i|
55
+ e.values_at("name", "ssh_url", "clone_url").unshift("[#{i+1}]")
56
+ end
57
+ print_table @repos
58
+ end
59
+
60
+ desc "clone", "Clones a repository from the list"
61
+ def clone
62
+ list
63
+ index = ask("Which repository would you like to clone?", :limited_to => ("1".."#{@repos.size}").to_a).to_i
64
+ protocol = ask("Select a protocol (ssh or https)?", :limited_to => ["s", "h"])
65
+ url = protocol == "s" ? @repos[index-1][2] : @repos[index-1][3]
66
+ run("git clone #{url}")
59
67
  end
60
68
 
69
+ no_commands {
70
+ def get_gh_repos(uname)
71
+ url = "#{@@gh_api_url}/users/#{uname}/repos"
72
+ gh_repos_filepath = ENV['HOME'] + "/.thorium/gh_repos_#{uname}.json"
73
+ get url, gh_repos_filepath, :verbose => false
74
+ JSON.parse File.read(gh_repos_filepath)
75
+ end
76
+ }
77
+
61
78
  end
62
79
  end
63
80
 
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thorium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Stankevich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-19 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Workflow automation gem
@@ -43,12 +43,12 @@ require_paths:
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []