stash-client 0.0.7 → 0.0.8
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 +4 -4
- data/.gitignore +2 -1
- data/lib/stash/client.rb +38 -4
- data/lib/stash/client/version.rb +1 -1
- data/spec/spec_helper.rb +8 -1
- data/spec/stash/client_spec.rb +66 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa99f385373b098da9cac5fdf9048414f94ff456
|
4
|
+
data.tar.gz: af52892fa50a703ca751a00db2f2b252e24d6821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2a1b9ece11d5ea77ee5ee6c354d63cd6f1b5ca79a55e96395e9e27a6600c68d2d514bae58f267b0f784808631340a2bba451f81b27b38de29d13ebf5fae3101
|
7
|
+
data.tar.gz: ed15abae04ca094ac48cf5d6fc3cdbd55bd15d8cac054cff123849765913a3e3da11e446d3745b5723001cd658bafa8cec84b172abd425db863362bcd8b59b56
|
data/.gitignore
CHANGED
data/lib/stash/client.rb
CHANGED
@@ -18,7 +18,7 @@ module Stash
|
|
18
18
|
elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI)
|
19
19
|
@url = opts[:uri]
|
20
20
|
else
|
21
|
-
raise ArgumentError, "must
|
21
|
+
raise ArgumentError, "must provide :url or :host"
|
22
22
|
end
|
23
23
|
|
24
24
|
@url.userinfo = opts[:credentials] if opts[:credentials]
|
@@ -28,11 +28,25 @@ module Stash
|
|
28
28
|
fetch_all @url.join('projects')
|
29
29
|
end
|
30
30
|
|
31
|
+
def create_project(opts={})
|
32
|
+
post @url.join('projects'), opts
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_project(project, opts={})
|
36
|
+
relative_project_path = project.fetch('link').fetch('url')
|
37
|
+
put @url.join(remove_leading_slash(relative_project_path)), opts
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_project(project)
|
41
|
+
relative_project_path = project.fetch('link').fetch('url')
|
42
|
+
delete @url.join(remove_leading_slash(relative_project_path))
|
43
|
+
end
|
44
|
+
|
31
45
|
def repositories
|
32
|
-
projects.
|
46
|
+
projects.map do |project|
|
33
47
|
relative_project_path = project.fetch('link').fetch('url') + '/repos'
|
34
48
|
fetch_all @url.join(remove_leading_slash(relative_project_path))
|
35
|
-
end
|
49
|
+
end.flatten
|
36
50
|
end
|
37
51
|
|
38
52
|
def project_named(name)
|
@@ -101,7 +115,27 @@ module Stash
|
|
101
115
|
end
|
102
116
|
|
103
117
|
def fetch(uri)
|
104
|
-
JSON.parse(RestClient.get(uri.to_s, :accept =>
|
118
|
+
JSON.parse(RestClient.get(uri.to_s, :accept => :json))
|
119
|
+
end
|
120
|
+
|
121
|
+
def post(uri, data)
|
122
|
+
JSON.parse(
|
123
|
+
RestClient.post(
|
124
|
+
uri.to_s, data.to_json, :accept => :json, :content_type => :json
|
125
|
+
)
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
def put(uri, data)
|
130
|
+
JSON.parse(
|
131
|
+
RestClient.put(
|
132
|
+
uri.to_s, data.to_json, :accept => :json, :content_type => :json
|
133
|
+
)
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
def delete(uri)
|
138
|
+
RestClient.delete(uri.to_s, :accept => :json)
|
105
139
|
end
|
106
140
|
|
107
141
|
def remove_leading_slash(str)
|
data/lib/stash/client/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/stash/client_spec.rb
CHANGED
@@ -18,6 +18,71 @@ module Stash
|
|
18
18
|
client.projects.should == [{"key" => "value"}]
|
19
19
|
end
|
20
20
|
|
21
|
+
it 'creates projects' do
|
22
|
+
stub_request(:post, "foo:bar@git.example.com/rest/api/1.0/projects").
|
23
|
+
with(:body => {:key => 'FOO', :name => 'Foobar', :description => 'bar'}).
|
24
|
+
to_return(:body => {
|
25
|
+
'id' => 1,
|
26
|
+
'key' => 'FOO',
|
27
|
+
'name' => 'Foobar',
|
28
|
+
'description' => 'bar',
|
29
|
+
'public' => true,
|
30
|
+
'type' => 'NORMAL',
|
31
|
+
'link' => {
|
32
|
+
'url' => 'http://git.example.com/projects/FOO',
|
33
|
+
'rel' => 'self',
|
34
|
+
},
|
35
|
+
'links' => {
|
36
|
+
'self' => [
|
37
|
+
{ 'href' => 'http://git.example.com/projects/FOO' },
|
38
|
+
],
|
39
|
+
},
|
40
|
+
}.to_json)
|
41
|
+
|
42
|
+
client.create_project({
|
43
|
+
:key => 'FOO', :name => 'Foobar', :description => 'bar'
|
44
|
+
}).should == {
|
45
|
+
'id' => 1,
|
46
|
+
'key' => 'FOO',
|
47
|
+
'name' => 'Foobar',
|
48
|
+
'description' => 'bar',
|
49
|
+
'public' => true,
|
50
|
+
'type' => 'NORMAL',
|
51
|
+
'link' => {
|
52
|
+
'url' => 'http://git.example.com/projects/FOO',
|
53
|
+
'rel' => 'self',
|
54
|
+
},
|
55
|
+
'links' => {
|
56
|
+
'self' => [
|
57
|
+
{ 'href' => 'http://git.example.com/projects/FOO' },
|
58
|
+
],
|
59
|
+
},
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'updates projects' do
|
64
|
+
stub_request(:put, "foo:bar@git.example.com/rest/api/1.0/projects/foo").
|
65
|
+
with(:body => {:description => 'new description'}).
|
66
|
+
to_return(:body => {
|
67
|
+
'description' => 'new description',
|
68
|
+
}.to_json)
|
69
|
+
|
70
|
+
project = { 'link' => {'url' => '/projects/foo'} }
|
71
|
+
client.update_project(project, {
|
72
|
+
:description => 'new description'
|
73
|
+
}).should == {
|
74
|
+
'description' => 'new description',
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'deletes projects' do
|
79
|
+
stub_request(:delete, "foo:bar@git.example.com/rest/api/1.0/projects/foo").
|
80
|
+
to_return(:status => 200, :body => "")
|
81
|
+
|
82
|
+
project = { 'link' => {'url' => '/projects/foo'} }
|
83
|
+
client.delete_project(project).should == ""
|
84
|
+
end
|
85
|
+
|
21
86
|
it 'fetches repositories' do
|
22
87
|
stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects").to_return(body: response_with_value('link' => {'url' => '/projects/foo'}))
|
23
88
|
stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects/foo/repos").to_return(body: response_with_value('key' => 'value'))
|
@@ -30,7 +95,7 @@ module Stash
|
|
30
95
|
client.commits_for({'link' => {'url' => '/repos/foo/browse'}}).should == [{'key' => 'value'}]
|
31
96
|
end
|
32
97
|
|
33
|
-
it '
|
98
|
+
it 'fetches changes' do
|
34
99
|
stub_request(:get, 'foo:bar@git.example.com/rest/api/1.0/projects/foo/repos/bar/changes?limit=100&until=deadbeef').to_return(body: response_with_value('key' => 'value'))
|
35
100
|
|
36
101
|
repo = {'link' => {'url' => '/projects/foo/repos/bar/browse'}}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jari Bakken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|