stash-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/lib/stash/client/version.rb +5 -0
- data/lib/stash/client.rb +86 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/stash/client_spec.rb +34 -0
- data/stash-client.gemspec +30 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f5d893da5b3af5c6329b34b3f085ca6209a04d6
|
4
|
+
data.tar.gz: ab13f2e467f079a67a4e9c1669fcdf5c74ccb392
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a677f8cb989bd133359b311c123166c3248cf5f8c96241a42a6550aa0d5fcd97f5276f94e70eff7e29f304785a5df6c6620b36681a82dc056c916a6544038eaf
|
7
|
+
data.tar.gz: ecf05691ce5667374e7ac7b35d4c4f3b794a368c4a610e9096244dffb2a3e7bdf25dce023cb7823d08f31b7718d8ab7ad388e6a5390c7ff31d71cc7836af2ac2
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jari Bakken
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
![Travis Status](https://travis-ci.org/finn-no/stash-client.png)
|
2
|
+
|
3
|
+
# Stash::Client
|
4
|
+
|
5
|
+
Very basic client for the Atlassian Stash REST API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'stash-client'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install stash-client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = Stash::Client.new(host: 'git.example.com', credentials: 'user:pass')
|
25
|
+
client.projects #=> [{'name' => 'foo', ...}]
|
26
|
+
|
27
|
+
repo = client.repositories.first #=> {'name' => 'bar', ...}
|
28
|
+
commits = client.commits_for(repo, since: 'e6c0a79734b3c1fa5c30c4c83cd3220e36d7e246')
|
29
|
+
commits = client.commits_for(repo, limit: 100)
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Make your changes and add tests for it. This is important so we don't break it in a future version unintentionally.
|
37
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/stash/client.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "stash/client/version"
|
2
|
+
require "restclient"
|
3
|
+
require 'addressable/uri'
|
4
|
+
require 'json'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
module Stash
|
8
|
+
class Client
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
if opts[:host]
|
12
|
+
@url = Addressable::URI.parse('http://' + opts[:host] + '/rest/api/1.0/')
|
13
|
+
elsif opts[:url]
|
14
|
+
@url = Addressable::URI.parse(opts[:url])
|
15
|
+
elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI)
|
16
|
+
@url = opts[:uri]
|
17
|
+
else
|
18
|
+
raise ArgumentError, "must provie :url or :host"
|
19
|
+
end
|
20
|
+
|
21
|
+
@url.userinfo = opts[:credentials] if opts[:credentials]
|
22
|
+
end
|
23
|
+
|
24
|
+
def projects
|
25
|
+
fetch_all @url.join('projects')
|
26
|
+
end
|
27
|
+
|
28
|
+
def repositories
|
29
|
+
projects.flat_map do |project|
|
30
|
+
relative_project_path = project.fetch('link').fetch('url') + '/repos'
|
31
|
+
fetch_all @url.join(remove_leading_slash(relative_project_path))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def project_named(name)
|
36
|
+
projects.find { |e| e['name'] == name }
|
37
|
+
end
|
38
|
+
|
39
|
+
def repository_named(name)
|
40
|
+
repositories.find { |e| e['name'] == name }
|
41
|
+
end
|
42
|
+
|
43
|
+
def commits_for(repo, opts = {})
|
44
|
+
query_values = {}
|
45
|
+
|
46
|
+
path = remove_leading_slash repo.fetch('link').fetch('url').sub('browse', 'commits')
|
47
|
+
uri = @url.join(path)
|
48
|
+
|
49
|
+
query_values['since'] = opts[:since] if opts[:since]
|
50
|
+
query_values['until'] = opts[:until] if opts[:until]
|
51
|
+
query_values['limit'] = Integer(opts[:limit]) if opts[:limit]
|
52
|
+
|
53
|
+
if query_values.empty?
|
54
|
+
# default limit to 100 commits
|
55
|
+
query_values['limit'] = 100
|
56
|
+
end
|
57
|
+
|
58
|
+
fetch_all(uri)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def fetch_all(uri)
|
64
|
+
response, result = {}, []
|
65
|
+
|
66
|
+
until response['isLastPage']
|
67
|
+
response = fetch(uri)
|
68
|
+
result += response['values']
|
69
|
+
|
70
|
+
next_page_start = response['nextPageStart'] || (response['start'] + response['size'])
|
71
|
+
uri.query_values = (uri.query_values || {}).merge('start' => next_page_start)
|
72
|
+
end
|
73
|
+
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
def fetch(uri)
|
78
|
+
JSON.parse(RestClient.get(uri.to_s, :accept => "application/json"))
|
79
|
+
end
|
80
|
+
|
81
|
+
def remove_leading_slash(str)
|
82
|
+
str.sub(/\A\//, '')
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
describe Client do
|
5
|
+
let(:client) { Client.new(host: 'git.example.com', credentials: 'foo:bar') }
|
6
|
+
|
7
|
+
def response_with_value(params)
|
8
|
+
{
|
9
|
+
'values' => [params],
|
10
|
+
'isLastPage' => true,
|
11
|
+
'start' => 0,
|
12
|
+
'size' => 1
|
13
|
+
}.to_json
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'fetches projects' do
|
17
|
+
stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects").to_return(body: response_with_value('key' => 'value'))
|
18
|
+
client.projects.should == [{"key" => "value"}]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'fetches repositories' do
|
22
|
+
stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects").to_return(body: response_with_value('link' => {'url' => '/projects/foo'}))
|
23
|
+
stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects/foo/repos").to_return(body: response_with_value('key' => 'value'))
|
24
|
+
|
25
|
+
client.repositories.should == [{'key' => 'value'}]
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'fetches commits' do
|
29
|
+
stub_request(:get, 'foo:bar@git.example.com/rest/api/1.0/repos/foo/commits').to_return(body: response_with_value('key' => 'value'))
|
30
|
+
client.commits_for({'link' => {'url' => '/repos/foo/browse'}}).should == [{'key' => 'value'}]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stash/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "stash-client"
|
8
|
+
spec.version = Stash::Client::VERSION
|
9
|
+
spec.authors = ["Jari Bakken"]
|
10
|
+
spec.email = ["jari.bakken@gmail.com"]
|
11
|
+
spec.description = %q{Atlassian Stash Client}
|
12
|
+
spec.summary = %q{Atlassian Stash Client}
|
13
|
+
spec.homepage = "http://github.com/finn-no/stash-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
|
28
|
+
spec.add_dependency 'rest-client'
|
29
|
+
spec.add_dependency 'addressable'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stash-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jari Bakken
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: addressable
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Atlassian Stash Client
|
98
|
+
email:
|
99
|
+
- jari.bakken@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .travis.yml
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/stash/client.rb
|
111
|
+
- lib/stash/client/version.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/stash/client_spec.rb
|
114
|
+
- stash-client.gemspec
|
115
|
+
homepage: http://github.com/finn-no/stash-client
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.9.2
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.1.10
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Atlassian Stash Client
|
139
|
+
test_files:
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/stash/client_spec.rb
|
142
|
+
has_rdoc:
|