singularity_client 0.2.0
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/.gitignore +23 -0
- data/.rubocop.yml +10 -0
- data/.singularity.yml +3 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +24 -0
- data/bin/singularity +5 -0
- data/lib/singularity_client/api.rb +53 -0
- data/lib/singularity_client/cli.rb +45 -0
- data/lib/singularity_client/config.rb +48 -0
- data/lib/singularity_client/request.rb +40 -0
- data/lib/singularity_client/version.rb +6 -0
- data/lib/singularity_client.rb +5 -0
- data/singularity_client.gemspec +31 -0
- data/spec/singularity_client/api_spec.rb +77 -0
- data/spec/singularity_client/config_spec.rb +103 -0
- data/spec/singularity_client/request_spec.rb +35 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/vcr_cassettes/add.yml +30 -0
- data/spec/vcr_cassettes/comment.yml +30 -0
- data/spec/vcr_cassettes/config.yml +32 -0
- data/spec/vcr_cassettes/error-get.yml +32 -0
- data/spec/vcr_cassettes/error-post.yml +32 -0
- metadata +230 -0
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
.vendor
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
data/.rubocop.yml
ADDED
data/.singularity.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nina Berg
|
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,78 @@
|
|
1
|
+
# Singularity Client
|
2
|
+
|
3
|
+
Command line tool for easy communication with your Singularity server.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'singularity_client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install singularity_client
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
The singularity client configures itself off a `.singularity.yml` file.
|
22
|
+
|
23
|
+
By default, the tool will start looking for a `.singularity.yml` in your current working directory,
|
24
|
+
and will work its way up to the root directory. Specify a path via the `--config` command line option.
|
25
|
+
|
26
|
+
### Available configurations:
|
27
|
+
|
28
|
+
<table>
|
29
|
+
<tr>
|
30
|
+
<th>Key</th>
|
31
|
+
<th>Description</th>
|
32
|
+
<th>Type</th>
|
33
|
+
<th>Example</th>
|
34
|
+
</tr>
|
35
|
+
<tr>
|
36
|
+
<td><tt>singularity_url</tt></td>
|
37
|
+
<td>URL for the singularity server</td>
|
38
|
+
<td>String</td>
|
39
|
+
<td><tt>'http://singularity.net'</tt></td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<td><tt>singularity_port</tt></td>
|
43
|
+
<td>Port the singularity server is operating on</td>
|
44
|
+
<td>String</td>
|
45
|
+
<td><tt>'9000'</tt></td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td><tt>github_organization</tt></td>
|
49
|
+
<td>Default github organization to use</td>
|
50
|
+
<td>String</td>
|
51
|
+
<td><tt>'Behance'</tt></td>
|
52
|
+
</tr>
|
53
|
+
</table>
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
```
|
58
|
+
Commands:
|
59
|
+
singularity add REPO_NAME PROJECT_NAME # Add a github repository to singularity
|
60
|
+
singularity comment REPO_NAME PR_NUM COMMENT # Write comment to a pull request
|
61
|
+
singularity config # Get the current singularity config object
|
62
|
+
singularity help [COMMAND] # Describe available commands or one specific command
|
63
|
+
|
64
|
+
Options:
|
65
|
+
-c, [--config=CONFIG] # Specify path to a .singularity.yml file
|
66
|
+
[--singularity-url=SINGULARITY_URL] # Override the default singularity url
|
67
|
+
[--singularity-port=SINGULARITY_PORT] # Override the default singularity port
|
68
|
+
-d, [--debug], [--no-debug] # Turn on debug mode
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
## Contributing
|
73
|
+
|
74
|
+
1. Fork it ( https://github.com/behance/singularity_client/fork )
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
78
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/user/bin/env rake
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
namespace :test do
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new(:rubocop)
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
13
|
+
t.rspec_opts = '--format documentation --color'
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Run RSpec with code coverage'
|
17
|
+
task :coverage do
|
18
|
+
ENV['COVERAGE'] = 'true'
|
19
|
+
Rake::Task['test:rspec'].execute
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Run rubocop and rspec test'
|
23
|
+
task all: [:rubocop, :rspec]
|
24
|
+
end
|
data/bin/singularity
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
require 'singularity_client/request'
|
7
|
+
|
8
|
+
module SingularityClient
|
9
|
+
# Handles the singularity api
|
10
|
+
class API
|
11
|
+
def self.config(config)
|
12
|
+
endpoint = 'config'
|
13
|
+
|
14
|
+
request = SingularityClient::Request.new(config)
|
15
|
+
response = request.get(endpoint)
|
16
|
+
|
17
|
+
pp(JSON.parse(response.body))
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.add(config, repo, project)
|
21
|
+
endpoint = 'config/pull_request'
|
22
|
+
post_data = {
|
23
|
+
organization: config.organization,
|
24
|
+
repo: repo,
|
25
|
+
project: project
|
26
|
+
}
|
27
|
+
|
28
|
+
request = SingularityClient::Request.new(config)
|
29
|
+
request.post(endpoint, post_data)
|
30
|
+
|
31
|
+
puts('success!')
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.comment(config, repo, pr, comment)
|
35
|
+
# if pr is not a number, pr.to_i will return 0
|
36
|
+
# zero is not a valid pull-request identifier
|
37
|
+
fail('ERROR invalid pull-request provided') if pr.to_i == 0
|
38
|
+
|
39
|
+
endpoint = 'comment'
|
40
|
+
post_data = {
|
41
|
+
organization: config.organization,
|
42
|
+
repo: repo,
|
43
|
+
pull_request: pr,
|
44
|
+
message: comment
|
45
|
+
}
|
46
|
+
|
47
|
+
request = SingularityClient::Request.new(config)
|
48
|
+
request.post(endpoint, post_data)
|
49
|
+
|
50
|
+
puts('success!')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'singularity_client'
|
5
|
+
|
6
|
+
module SingularityClient
|
7
|
+
# Handles all command line interface logic
|
8
|
+
class CLI < Thor
|
9
|
+
attr_reader :config_hash
|
10
|
+
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
@config_hash = SingularityClient::Config.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# rubocop:disable AlignHash
|
17
|
+
class_option :config, aliases: '-c', type: :string,
|
18
|
+
desc: 'Specify path to a .singularity.yml file'
|
19
|
+
class_option :singularity_url, type: :string,
|
20
|
+
desc: 'Override the default singularity url'
|
21
|
+
class_option :singularity_port, type: :string,
|
22
|
+
desc: 'Override the default singularity port'
|
23
|
+
class_option :debug, aliases: '-d', type: :boolean,
|
24
|
+
desc: 'Turn on debug mode'
|
25
|
+
|
26
|
+
desc 'config', 'Get the current singularity config object'
|
27
|
+
def config
|
28
|
+
SingularityClient::API.config(config_hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'add REPO_NAME PROJECT_NAME', 'Add a github repository to singularity'
|
32
|
+
method_option :github_organization, aliases: '-o', type: :string,
|
33
|
+
desc: 'Override the default github organization'
|
34
|
+
def add(repo, project)
|
35
|
+
SingularityClient::API.add(config_hash, repo, project)
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'comment REPO_NAME PR_NUM COMMENT', 'Write comment to a pull request'
|
39
|
+
method_option :github_organization, aliases: '-o', type: :string,
|
40
|
+
desc: 'Override the default github organization'
|
41
|
+
def comment(repo, pr, comment)
|
42
|
+
SingularityClient::API.comment(config_hash, repo, pr, comment)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module SingularityClient
|
7
|
+
# Wrapper around the config object
|
8
|
+
class Config
|
9
|
+
DOTFILE = '.singularity.yml'
|
10
|
+
|
11
|
+
attr_accessor :options
|
12
|
+
|
13
|
+
def initialize(inputs)
|
14
|
+
config_file = inputs['config'] || find_config_file('.')
|
15
|
+
@options = load_from_file(config_file).merge(inputs)
|
16
|
+
|
17
|
+
puts "DEBUG: Using configuration from #{config_file}" if debug
|
18
|
+
puts "DEBUG: Current configuration: #{@options}" if debug
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_uri
|
22
|
+
"#{@options['singularity_url']}:#{@options['singularity_port']}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def organization
|
26
|
+
@options['github_organization']
|
27
|
+
end
|
28
|
+
|
29
|
+
def debug
|
30
|
+
@options.key?('debug')
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def find_config_file(dir)
|
36
|
+
Pathname.new(File.expand_path(dir)).ascend do |path|
|
37
|
+
file = File.join(path.to_s, DOTFILE)
|
38
|
+
return file if File.exist?(file)
|
39
|
+
end
|
40
|
+
|
41
|
+
fail 'Could not find .singularity.yml'
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_from_file(file)
|
45
|
+
YAML.load_file(file)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module SingularityClient
|
6
|
+
# Wrapper around HTTParty requests
|
7
|
+
class Request
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
def initialize(config)
|
11
|
+
@base_uri = config.base_uri
|
12
|
+
@debug = config.debug
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(endpoint, query = {})
|
16
|
+
request = "#{@base_uri}/#{endpoint}"
|
17
|
+
puts "DEBUG: sending get request #{request}" if @debug
|
18
|
+
|
19
|
+
response = self.class.get(request, query)
|
20
|
+
|
21
|
+
response.code == 200 ? response : error(response)
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(endpoint, data = {})
|
25
|
+
request = "#{@base_uri}/#{endpoint}"
|
26
|
+
puts "DEBUG: sending post request to #{request}" if @debug
|
27
|
+
puts "DEBUG: with post_data #{data}" if @debug
|
28
|
+
|
29
|
+
response = self.class.post(request, body: data)
|
30
|
+
|
31
|
+
response.code == 200 ? response : error(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def error(response)
|
37
|
+
fail("ERROR #{response.code} #{response.message}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'singularity_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "singularity_client"
|
8
|
+
spec.version = SingularityClient::VERSION
|
9
|
+
spec.authors = ["Behance QeOps"]
|
10
|
+
spec.email = ["qeops-behance@adobe.com"]
|
11
|
+
spec.summary = %q{Singularity Client}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rubocop", "~> 0.23"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
|
29
|
+
spec.add_dependency "thor"
|
30
|
+
spec.add_dependency "httparty"
|
31
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SingularityClient::API do
|
6
|
+
|
7
|
+
let(:config_obj) do
|
8
|
+
double('config',
|
9
|
+
base_uri: 'http://mergeatron.dev-be-aws.net:3306',
|
10
|
+
debug: false,
|
11
|
+
organization: 'some_org'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.config' do
|
16
|
+
subject(:config) { SingularityClient::API.config(config_obj) }
|
17
|
+
|
18
|
+
describe 'when it receives a succesful response' do
|
19
|
+
it 'it parses and displays the config' do
|
20
|
+
expected_response = {
|
21
|
+
'github' => {
|
22
|
+
'ci_user' => 'bejudged',
|
23
|
+
'repositories' => %w(aws bevarnish)
|
24
|
+
},
|
25
|
+
'jenkins' => {
|
26
|
+
'has_global_trigger_token' => true,
|
27
|
+
'projects' => [{
|
28
|
+
'name' => 'branch-cookbook-aws',
|
29
|
+
'repo' => 'aws',
|
30
|
+
'has_trigger_token' => true
|
31
|
+
}, {
|
32
|
+
'name' => 'branch-cookbook-bevarnish',
|
33
|
+
'repo' => 'bevarnish',
|
34
|
+
'has_trigger_token' => false
|
35
|
+
}],
|
36
|
+
'push_projects' => []
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
VCR.use_cassette('config') do
|
41
|
+
expect(config).to eq(expected_response)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.add' do
|
48
|
+
subject(:add) do
|
49
|
+
SingularityClient::API.add(config_obj, 'test_repo', 'test_project')
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'when it receives a succesful response' do
|
53
|
+
it 'it returns success!' do
|
54
|
+
VCR.use_cassette('add') do
|
55
|
+
expect(STDOUT).to receive(:puts).with('success!')
|
56
|
+
add
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.comment' do
|
63
|
+
subject(:comment) do
|
64
|
+
comment = 'This is some test comment'
|
65
|
+
SingularityClient::API.comment(config_obj, 'test_repo', '12', comment)
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'when it receives a succesful response' do
|
69
|
+
it 'it returns success!' do
|
70
|
+
VCR.use_cassette('comment') do
|
71
|
+
expect(STDOUT).to receive(:puts).with('success!')
|
72
|
+
comment
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SingularityClient::Config do
|
6
|
+
describe '.initialize' do
|
7
|
+
describe 'when no .singularity.yml found' do
|
8
|
+
it 'raises an exception' do
|
9
|
+
expect(File).to receive(:exist?)
|
10
|
+
.at_least(:once)
|
11
|
+
.with(/.*\/.singularity.yml/)
|
12
|
+
.and_return(false)
|
13
|
+
|
14
|
+
expect { SingularityClient::Config.new({}) }
|
15
|
+
.to raise_error(RuntimeError, 'Could not find .singularity.yml')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '@options' do
|
21
|
+
describe 'merged correctly' do
|
22
|
+
it 'when no inputs' do
|
23
|
+
config = SingularityClient::Config.new({})
|
24
|
+
|
25
|
+
expect(config.options).to eql(
|
26
|
+
'singularity_url' => 'http://mergeatron.dev-be-aws.net',
|
27
|
+
'singularity_port' => '3306',
|
28
|
+
'github_organization' => 'BehanceOps'
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'when provided a config path' do
|
33
|
+
config = SingularityClient::Config.new(
|
34
|
+
'config' => './.singularity.yml'
|
35
|
+
)
|
36
|
+
|
37
|
+
expect(config.options).to eql(
|
38
|
+
'singularity_url' => 'http://mergeatron.dev-be-aws.net',
|
39
|
+
'singularity_port' => '3306',
|
40
|
+
'github_organization' => 'BehanceOps',
|
41
|
+
'config' => './.singularity.yml'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'when provided a singularity url' do
|
46
|
+
config = SingularityClient::Config.new(
|
47
|
+
'singularity_url' => 'random.com'
|
48
|
+
)
|
49
|
+
|
50
|
+
expect(config.options).to eql(
|
51
|
+
'singularity_url' => 'random.com',
|
52
|
+
'singularity_port' => '3306',
|
53
|
+
'github_organization' => 'BehanceOps'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'when provided a singularity port' do
|
58
|
+
config = SingularityClient::Config.new(
|
59
|
+
'singularity_port' => '1111'
|
60
|
+
)
|
61
|
+
|
62
|
+
expect(config.options).to eql(
|
63
|
+
'singularity_url' => 'http://mergeatron.dev-be-aws.net',
|
64
|
+
'singularity_port' => '1111',
|
65
|
+
'github_organization' => 'BehanceOps'
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
let(:config) { SingularityClient::Config.new({}) }
|
72
|
+
|
73
|
+
describe '#base_uri' do
|
74
|
+
it 'returns base_uri' do
|
75
|
+
expect(config.base_uri).to eql('http://mergeatron.dev-be-aws.net:3306')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#organization' do
|
80
|
+
it 'returns organization from file' do
|
81
|
+
expect(config.organization).to eql('BehanceOps')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns command line organization' do
|
85
|
+
config = SingularityClient::Config.new('github_organization' => 'Test')
|
86
|
+
|
87
|
+
expect(config.organization).to eql('Test')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#debug' do
|
92
|
+
it 'returns false by default' do
|
93
|
+
expect(config.debug).to eql(false)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns true when set' do
|
97
|
+
config = SingularityClient::Config.new('debug' => true)
|
98
|
+
|
99
|
+
expect(config.debug).to eql(true)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe SingularityClient::Request do
|
6
|
+
|
7
|
+
let(:config_obj) do
|
8
|
+
double('config',
|
9
|
+
base_uri: 'http://mergeatron.dev-be-aws.net:3306',
|
10
|
+
debug: false,
|
11
|
+
organization: 'some_org'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:request_obj) { SingularityClient::Request.new(config_obj) }
|
16
|
+
|
17
|
+
describe '#error' do
|
18
|
+
|
19
|
+
describe 'when a request receives a non 200 OK response' do
|
20
|
+
it 'it throws an exception (get request)' do
|
21
|
+
VCR.use_cassette('error-get') do
|
22
|
+
expect { request_obj.get('/doesnt-exist') }
|
23
|
+
.to raise_error(RuntimeError, 'ERROR 404 Not Found')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'it throws an exception (post request)' do
|
28
|
+
VCR.use_cassette('error-post') do
|
29
|
+
expect { request_obj.post('/doesnt-exist') }
|
30
|
+
.to raise_error(RuntimeError, 'ERROR 404 Not Found')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if ENV['COVERAGE']
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/spec/'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'singularity_client'
|
11
|
+
require 'vcr'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.expect_with :rspec do |c|
|
15
|
+
c.syntax = :expect
|
16
|
+
end
|
17
|
+
|
18
|
+
# config.before do
|
19
|
+
# IO.any_instance.stub(:puts)
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
|
23
|
+
VCR.configure do |c|
|
24
|
+
c.cassette_library_dir = 'spec/vcr_cassettes'
|
25
|
+
c.hook_into :webmock
|
26
|
+
c.default_cassette_options = { record: :once }
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/config/pull_request
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: organization=some_org&repo=test_repo&project=test_project
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
X-Powered-By:
|
16
|
+
- Express
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '16'
|
21
|
+
Date:
|
22
|
+
- Mon, 02 Jun 2014 20:58:24 GMT
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"success":true}'
|
28
|
+
http_version:
|
29
|
+
recorded_at: Mon, 02 Jun 2014 20:58:24 GMT
|
30
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/comment
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: organization=some_org&repo=test_repo&pull_request=12&message=test%20comment
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
X-Powered-By:
|
16
|
+
- Express
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '16'
|
21
|
+
Date:
|
22
|
+
- Mon, 02 Jun 2014 20:59:32 GMT
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"success":true}'
|
28
|
+
http_version:
|
29
|
+
recorded_at: Mon, 02 Jun 2014 20:59:32 GMT
|
30
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/config
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
X-Powered-By:
|
16
|
+
- Express
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '9019'
|
21
|
+
Etag:
|
22
|
+
- ! '"-1618218809"'
|
23
|
+
Date:
|
24
|
+
- Mon, 02 Jun 2014 20:27:17 GMT
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
body:
|
28
|
+
encoding: US-ASCII
|
29
|
+
string: ! '{"github":{"ci_user":"bejudged","repositories":["aws","bevarnish"]},"jenkins":{"has_global_trigger_token":true,"projects":[{"name":"branch-cookbook-aws","repo":"aws","has_trigger_token":true},{"name":"branch-cookbook-bevarnish","repo":"bevarnish","has_trigger_token":false}],"push_projects":[]}}'
|
30
|
+
http_version:
|
31
|
+
recorded_at: Mon, 02 Jun 2014 20:27:17 GMT
|
32
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306//doesnt-exist
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 404
|
13
|
+
message: Not Found
|
14
|
+
headers:
|
15
|
+
X-Powered-By:
|
16
|
+
- Express
|
17
|
+
Content-Type:
|
18
|
+
- text/html
|
19
|
+
Date:
|
20
|
+
- Mon, 02 Jun 2014 22:12:30 GMT
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! 'Cannot GET //doesnt-exist
|
28
|
+
|
29
|
+
'
|
30
|
+
http_version:
|
31
|
+
recorded_at: Mon, 02 Jun 2014 22:12:30 GMT
|
32
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306//doesnt-exist
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 404
|
13
|
+
message: Not Found
|
14
|
+
headers:
|
15
|
+
X-Powered-By:
|
16
|
+
- Express
|
17
|
+
Content-Type:
|
18
|
+
- text/html
|
19
|
+
Date:
|
20
|
+
- Mon, 02 Jun 2014 22:12:46 GMT
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Transfer-Encoding:
|
24
|
+
- chunked
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! 'Cannot POST //doesnt-exist
|
28
|
+
|
29
|
+
'
|
30
|
+
http_version:
|
31
|
+
recorded_at: Mon, 02 Jun 2014 22:12:46 GMT
|
32
|
+
recorded_with: VCR 2.9.2
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: singularity_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Behance QeOps
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubocop
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.23'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.23'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: vcr
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: thor
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: httparty
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: ''
|
159
|
+
email:
|
160
|
+
- qeops-behance@adobe.com
|
161
|
+
executables:
|
162
|
+
- singularity
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- .gitignore
|
167
|
+
- .rubocop.yml
|
168
|
+
- .singularity.yml
|
169
|
+
- Gemfile
|
170
|
+
- LICENSE.txt
|
171
|
+
- README.md
|
172
|
+
- Rakefile
|
173
|
+
- bin/singularity
|
174
|
+
- lib/singularity_client.rb
|
175
|
+
- lib/singularity_client/api.rb
|
176
|
+
- lib/singularity_client/cli.rb
|
177
|
+
- lib/singularity_client/config.rb
|
178
|
+
- lib/singularity_client/request.rb
|
179
|
+
- lib/singularity_client/version.rb
|
180
|
+
- singularity_client.gemspec
|
181
|
+
- spec/singularity_client/api_spec.rb
|
182
|
+
- spec/singularity_client/config_spec.rb
|
183
|
+
- spec/singularity_client/request_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
- spec/vcr_cassettes/add.yml
|
186
|
+
- spec/vcr_cassettes/comment.yml
|
187
|
+
- spec/vcr_cassettes/config.yml
|
188
|
+
- spec/vcr_cassettes/error-get.yml
|
189
|
+
- spec/vcr_cassettes/error-post.yml
|
190
|
+
homepage: ''
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
none: false
|
199
|
+
requirements:
|
200
|
+
- - ! '>='
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
segments:
|
204
|
+
- 0
|
205
|
+
hash: -4434369719159961746
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
208
|
+
requirements:
|
209
|
+
- - ! '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
segments:
|
213
|
+
- 0
|
214
|
+
hash: -4434369719159961746
|
215
|
+
requirements: []
|
216
|
+
rubyforge_project:
|
217
|
+
rubygems_version: 1.8.23
|
218
|
+
signing_key:
|
219
|
+
specification_version: 3
|
220
|
+
summary: Singularity Client
|
221
|
+
test_files:
|
222
|
+
- spec/singularity_client/api_spec.rb
|
223
|
+
- spec/singularity_client/config_spec.rb
|
224
|
+
- spec/singularity_client/request_spec.rb
|
225
|
+
- spec/spec_helper.rb
|
226
|
+
- spec/vcr_cassettes/add.yml
|
227
|
+
- spec/vcr_cassettes/comment.yml
|
228
|
+
- spec/vcr_cassettes/config.yml
|
229
|
+
- spec/vcr_cassettes/error-get.yml
|
230
|
+
- spec/vcr_cassettes/error-post.yml
|