ghs 0.1.5 → 0.1.6
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/bin/ghs +33 -20
- metadata +19 -3
data/bin/ghs
CHANGED
@@ -1,37 +1,51 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
require "
|
3
|
+
require "json"
|
4
4
|
require 'trollop'
|
5
5
|
require 'open-uri'
|
6
|
+
require 'contracts'
|
6
7
|
|
8
|
+
def Contract.failure_callback(data)
|
9
|
+
puts "Oops: expected #{data[:contract]}, got #{data[:arg]} in #{data[:method].name}. Exiting."
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
include Contracts
|
14
|
+
use_contracts self
|
15
|
+
|
16
|
+
Repo = Or[Hash, nil]
|
17
|
+
|
18
|
+
Contract String
|
7
19
|
def find_user
|
8
20
|
x = `git config github.user`
|
9
21
|
x.chomp
|
10
22
|
end
|
11
23
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rescue
|
24
|
+
Contract String, Repo
|
25
|
+
def req(url)
|
26
|
+
JSON.parse(open("https://api.github.com#{url}").read)
|
27
|
+
rescue OpenURI::HTTPError => e
|
16
28
|
nil
|
17
|
-
end
|
18
29
|
end
|
19
30
|
|
31
|
+
Contract String, String, Repo
|
32
|
+
def get_repo(user, repo)
|
33
|
+
req "/repos/#{user}/#{repo}"
|
34
|
+
end
|
35
|
+
|
36
|
+
Contract String, Repo
|
20
37
|
def find_user_repo(repo)
|
21
38
|
user = find_user
|
22
39
|
return nil if user == ""
|
23
|
-
|
24
|
-
if repo_info
|
25
|
-
repo_info["repository"][:url] = "git@github.com:#{user}/#{repo}"
|
26
|
-
end
|
27
|
-
repo_info
|
40
|
+
get_repo(user, repo)
|
28
41
|
end
|
29
42
|
|
43
|
+
Contract String, Repo
|
30
44
|
def find_generic_repo(repo)
|
31
|
-
results =
|
45
|
+
results = req "/legacy/repos/search/#{repo}"
|
32
46
|
Trollop::die "Couldn't find a url" if results["repositories"].empty?
|
33
47
|
Trollop::die "Multiple repos found, not sure which one you wanted.\nTo let me make the choice, rerun with the --best flag" unless results["repositories"].size == 1 || OPTS[:best]
|
34
|
-
user = results["repositories"][0][
|
48
|
+
user = results["repositories"][0]["username"]
|
35
49
|
get_repo(user, repo)
|
36
50
|
end
|
37
51
|
|
@@ -39,7 +53,7 @@ OPTS = Trollop::options do
|
|
39
53
|
banner <<-EOS
|
40
54
|
Find the clone url for any repo on github, quickly.
|
41
55
|
Usage: #{$0} [repo name]
|
42
|
-
Use it to clone a repo: git clone `ghs [
|
56
|
+
Use it to clone a repo: git clone `ghs [repo name]`
|
43
57
|
EOS
|
44
58
|
opt :best, "If multiple repos are found, choose the first one."
|
45
59
|
end
|
@@ -47,15 +61,14 @@ end
|
|
47
61
|
Trollop::die("no repo specified") if ARGV.empty?
|
48
62
|
result = find_user_repo(ARGV[0]) || find_generic_repo(ARGV[0])
|
49
63
|
Trollop::die "couldn't find a url." unless result
|
50
|
-
result = result["repository"]
|
51
64
|
|
52
|
-
STDERR.puts
|
65
|
+
STDERR.puts %{
|
53
66
|
==
|
54
67
|
|
55
|
-
Matched repository: #{result[
|
56
|
-
Description: #{result[
|
68
|
+
Matched repository: #{result["name"]}
|
69
|
+
Description: #{result["description"]}
|
57
70
|
|
58
71
|
==
|
59
|
-
|
72
|
+
}
|
60
73
|
|
61
|
-
puts
|
74
|
+
puts result["ssh_url"]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ghs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aditya Bhargava
|
@@ -32,6 +32,22 @@ dependencies:
|
|
32
32
|
version: "0"
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: contracts
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 17
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
- 7
|
48
|
+
version: 0.0.7
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
35
51
|
description: Find the clone url for repos on Github
|
36
52
|
email: bluemangroupie@gmail.com
|
37
53
|
executables:
|