sah 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -1
- data/lib/sah/api.rb +2 -2
- data/lib/sah/cli.rb +94 -4
- data/lib/sah/version.rb +1 -1
- data/sah.gemspec +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85cfb48185d77cfdf34454c470f4d14df0203560
|
4
|
+
data.tar.gz: 987c0914aac82355669847a655c874dfc9852756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f0e19c6a6f6190b6c039ed82f09c3d4fce3e373bb18c343c965ce53d1f961bee459d2b3e6561dcb2fbe7750bae745fb79d9e153d4749447344fe39bdcda2b0e
|
7
|
+
data.tar.gz: 99b8e840fe8f9cd86f4faaaa25d38ead9968c8f6de29a69494d101683747872210d4b185928da848824bbb68e1bf1e4e483425e82d4400c61b1add755cbdc80d
|
data/README.md
CHANGED
@@ -27,6 +27,32 @@ If you use multiple stash, define profile(s) and specify it.
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
+
### browse
|
31
|
+
|
32
|
+
sah browse
|
33
|
+
# browse current repository
|
34
|
+
|
35
|
+
sah browse REPO
|
36
|
+
# browse ~YOUR_NAME/REPO
|
37
|
+
|
38
|
+
sah browse PROJECT/REPO
|
39
|
+
# browse PROJECT/REPO
|
40
|
+
|
41
|
+
sah browse --branch
|
42
|
+
# browse branch list in current repository
|
43
|
+
|
44
|
+
sah browse --branch BRANCH
|
45
|
+
# browse BRANCH in current repository
|
46
|
+
|
47
|
+
sah browse --commit COMMITHASH
|
48
|
+
# browse COMMITHASH in current repository
|
49
|
+
|
50
|
+
sah browse --pull-request
|
51
|
+
# browse pull request list in current repository
|
52
|
+
|
53
|
+
sah browse --pull-request PULL_REQUEST
|
54
|
+
# browse PULL_REQUEST in current repository
|
55
|
+
|
30
56
|
### clone
|
31
57
|
|
32
58
|
sah clone PROJECT/REPO
|
@@ -66,7 +92,7 @@ If you use multiple stash, define profile(s) and specify it.
|
|
66
92
|
sah fork ~USERNAME/REPO
|
67
93
|
# fork from ~USERNAME/REPO to ~YOUR_NAME/REPO
|
68
94
|
|
69
|
-
|
95
|
+
### help
|
70
96
|
|
71
97
|
sah help [COMMAND]
|
72
98
|
# Describe available commands or one specific command
|
data/lib/sah/api.rb
CHANGED
@@ -18,7 +18,7 @@ module Sah
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
21
|
+
def fork_repository(project, repo, name=nil)
|
22
22
|
body = {slug: repo}
|
23
23
|
body = body.merge(name: name) if name
|
24
24
|
|
@@ -29,7 +29,7 @@ module Sah
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def create_repository(project, repo)
|
33
33
|
@conn.post do |req|
|
34
34
|
req.url @config.url.path + "/rest/api/1.0/projects/#{project}/repos"
|
35
35
|
req.headers['Content-Type'] = 'application/json'
|
data/lib/sah/cli.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "sah"
|
2
2
|
require "thor"
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "hirb"
|
4
|
+
require "hirb-unicode"
|
5
|
+
require "launchy"
|
5
6
|
|
6
7
|
module Sah
|
7
8
|
class CLI < Thor
|
@@ -12,6 +13,88 @@ module Sah
|
|
12
13
|
type: :boolean, default: false,
|
13
14
|
desc: "Turn on/off verbose mode"
|
14
15
|
|
16
|
+
############### browse ###################
|
17
|
+
desc "browse [REPO]", "Browse repository"
|
18
|
+
long_desc <<-LONG_DESCRIPTION
|
19
|
+
sah browse
|
20
|
+
\x5# browse current repository
|
21
|
+
|
22
|
+
sah browse REPO
|
23
|
+
\x5# browse ~YOUR_NAME/REPO
|
24
|
+
|
25
|
+
sah browse PROJECT/REPO
|
26
|
+
\x5# browse PROJECT/REPO
|
27
|
+
|
28
|
+
sah browse --branch
|
29
|
+
\x5# browse branch list in current repository
|
30
|
+
|
31
|
+
sah browse --branch BRANCH
|
32
|
+
\x5# browse BRANCH in current repository
|
33
|
+
|
34
|
+
sah browse --commit COMMITHASH
|
35
|
+
\x5# browse COMMITHASH in current repository
|
36
|
+
|
37
|
+
sah browse --pull-request
|
38
|
+
\x5# browse pull request list in current repository
|
39
|
+
|
40
|
+
sah browse --pull-request PULL_REQUEST
|
41
|
+
\x5# browse PULL_REQUEST in current repository
|
42
|
+
LONG_DESCRIPTION
|
43
|
+
method_option :branch, aliases: "-b", desc: "Show branch(es)"
|
44
|
+
method_option :commit, aliases: "-c", desc: "Show commit"
|
45
|
+
method_option :"pull-request", aliases: "-r", desc: "Show pull request(s)"
|
46
|
+
def browse(arg=nil)
|
47
|
+
if arg
|
48
|
+
repository_slug, project_key = arg.split("/").reverse
|
49
|
+
project_key ||= "~#{config.user}"
|
50
|
+
else
|
51
|
+
remote_url = `git config --get remote.origin.url`.chomp
|
52
|
+
remote_url.match %r%/([^/]+)/([^/]+?)(?:\.git)?$%
|
53
|
+
project_key, repository_slug = $1, $2
|
54
|
+
end
|
55
|
+
res = api.show_repository(project_key, repository_slug)
|
56
|
+
if res.body.key? "errors"
|
57
|
+
abort res.body["errors"].first["message"]
|
58
|
+
end
|
59
|
+
|
60
|
+
url = config.url + res.body["link"]["url"]
|
61
|
+
|
62
|
+
if [options[:branch], options[:commit], options[:'pull-request']].compact.count > 1
|
63
|
+
abort "Multiple options (--branch, --commit, --pull-request) cannot be handled."
|
64
|
+
end
|
65
|
+
|
66
|
+
case options[:branch]
|
67
|
+
when nil
|
68
|
+
# skip
|
69
|
+
when "branch"
|
70
|
+
url.path = url.path.sub('/browse', '/branches')
|
71
|
+
else
|
72
|
+
url.path = url.path.sub('/browse', '/commits')
|
73
|
+
url.query =
|
74
|
+
URI.encode_www_form([["until", "refs/heads/#{options['branch']}"]])
|
75
|
+
end
|
76
|
+
|
77
|
+
case options[:commit]
|
78
|
+
when nil
|
79
|
+
# skip
|
80
|
+
when "commit"
|
81
|
+
abort 'You must specify commit hash.'
|
82
|
+
else
|
83
|
+
url.path = url.path.sub('/browse', "/commits/#{options['commit']}")
|
84
|
+
end
|
85
|
+
|
86
|
+
case options[:"pull-request"]
|
87
|
+
when nil
|
88
|
+
# skip
|
89
|
+
when "pull-request"
|
90
|
+
url.path = url.path.sub('/browse', "/pull-requests")
|
91
|
+
else
|
92
|
+
url.path = url.path.sub('/browse', "/pull-requests/#{options[:'pull-request']}/overview")
|
93
|
+
end
|
94
|
+
|
95
|
+
Launchy.open(url, debug: config.verbose)
|
96
|
+
end
|
97
|
+
|
15
98
|
desc "clone REPOS", "Clone repository"
|
16
99
|
long_desc <<-LONG_DESCRIPTION
|
17
100
|
sah clone PROJECT/REPO
|
@@ -55,7 +138,7 @@ module Sah
|
|
55
138
|
repository_slug = (
|
56
139
|
options[:name] || File.basename(`git rev-parse --show-toplevel`).chomp
|
57
140
|
)
|
58
|
-
res = api.
|
141
|
+
res = api.create_repository(project_key, repository_slug)
|
59
142
|
if res.body.key? "errors"
|
60
143
|
abort res.body["errors"].first["message"]
|
61
144
|
end
|
@@ -88,7 +171,7 @@ module Sah
|
|
88
171
|
remote_url.match %r%/([^/]+)/([^/]+?)(?:\.git)?$%
|
89
172
|
project_key, repository_slug = $1, $2
|
90
173
|
end
|
91
|
-
res = api.
|
174
|
+
res = api.fork_repository(project_key, repository_slug, options[:name])
|
92
175
|
if res.body.key? "errors"
|
93
176
|
abort res.body["errors"].first["message"]
|
94
177
|
end
|
@@ -163,13 +246,20 @@ module Sah
|
|
163
246
|
remote_url = `git config --get remote.origin.url`.chomp
|
164
247
|
remote_url.match %r%/([^/]+)/([^/]+?)(?:\.git)?$%
|
165
248
|
project, repository = $1, $2
|
249
|
+
|
166
250
|
res = api.show_repository(project, repository)
|
167
251
|
if res.body.key? "errors"
|
168
252
|
abort res.body["errors"].first["message"]
|
169
253
|
end
|
254
|
+
|
170
255
|
repository = res.body
|
256
|
+
unless repository.key? "origin"
|
257
|
+
abort "Upstream repos does not exist."
|
258
|
+
end
|
259
|
+
|
171
260
|
upstream_url =
|
172
261
|
repository["origin"]["links"]["clone"].find{ |e| e["name"] == config.protocol }["href"]
|
262
|
+
|
173
263
|
if options[:"add-remote"]
|
174
264
|
system "git", "remote", "add", "upstream", upstream_url
|
175
265
|
if config.upstream_fetch_pull_request || options[:"fetch-pull-request"]
|
data/lib/sah/version.rb
CHANGED
data/sah.gemspec
CHANGED
@@ -24,7 +24,8 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "faraday", "~> 0.9.1"
|
25
25
|
spec.add_dependency "faraday_middleware", "~> 0.10.0"
|
26
26
|
spec.add_dependency "hirb", "~> 0.7.3"
|
27
|
-
spec.add_dependency
|
27
|
+
spec.add_dependency "hirb-unicode", "~> 0.0.5"
|
28
|
+
spec.add_dependency "launchy", "~> 2.4.3"
|
28
29
|
|
29
30
|
spec.add_development_dependency "bundler", "~> 1.10"
|
30
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f440
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.0.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: launchy
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.4.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.4.3
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|