singularity_client 0.3.0 → 1.0.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/lib/singularity_client/api.rb +41 -23
- data/lib/singularity_client/cli.rb +20 -13
- data/lib/singularity_client/request.rb +10 -0
- data/lib/singularity_client/version.rb +1 -1
- data/spec/singularity_client/api_spec.rb +63 -46
- data/spec/vcr_cassettes/{addPush.yml → addChange.yml} +2 -2
- data/spec/vcr_cassettes/{addPull.yml → addProposal.yml} +2 -2
- data/spec/vcr_cassettes/removeRepo.yml +30 -0
- metadata +10 -8
@@ -8,27 +8,28 @@ require 'singularity_client/request'
|
|
8
8
|
module SingularityClient
|
9
9
|
# Handles the singularity api
|
10
10
|
class API
|
11
|
-
def self.config(config)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
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
19
|
|
20
20
|
##
|
21
21
|
# Add to the singularity config
|
22
22
|
# the 'type' parameter can be pull_request or push
|
23
23
|
#
|
24
24
|
def self.add(config, repo, project, type)
|
25
|
-
|
26
|
-
|
25
|
+
unless type == 'proposal' || type == 'change'
|
26
|
+
fail("ERROR invalid type: #{type}. \
|
27
|
+
Valid types are \'proposal\' or \'change\'")
|
28
|
+
end
|
27
29
|
|
28
|
-
endpoint =
|
30
|
+
endpoint = "config/#{type}"
|
29
31
|
post_data = {
|
30
|
-
|
31
|
-
repo: repo,
|
32
|
+
repository: "#{config.organization}/#{repo}",
|
32
33
|
project: project
|
33
34
|
}
|
34
35
|
|
@@ -38,23 +39,40 @@ module SingularityClient
|
|
38
39
|
puts('success!')
|
39
40
|
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
##
|
43
|
+
# Remove a repository from the singularity config
|
44
|
+
#
|
45
|
+
def self.remove(config, repo)
|
46
|
+
endpoint = 'config/repo'
|
45
47
|
|
46
|
-
endpoint = 'comment'
|
47
48
|
post_data = {
|
48
|
-
|
49
|
-
repo: repo,
|
50
|
-
pull_request: pr,
|
51
|
-
message: comment
|
49
|
+
repository: "#{config.organization}/#{repo}"
|
52
50
|
}
|
53
51
|
|
54
52
|
request = SingularityClient::Request.new(config)
|
55
|
-
request.
|
53
|
+
request.delete(endpoint, post_data)
|
56
54
|
|
57
55
|
puts('success!')
|
58
56
|
end
|
57
|
+
|
58
|
+
# Does this still exist?
|
59
|
+
# def self.comment(config, repo, pr, comment)
|
60
|
+
# # if pr is not a number, pr.to_i will return 0
|
61
|
+
# # zero is not a valid pull-request identifier
|
62
|
+
# fail('ERROR invalid pull-request provided') if pr.to_i == 0
|
63
|
+
#
|
64
|
+
# endpoint = 'comment'
|
65
|
+
# post_data = {
|
66
|
+
# organization: config.organization,
|
67
|
+
# repo: repo,
|
68
|
+
# pull_request: pr,
|
69
|
+
# message: comment
|
70
|
+
# }
|
71
|
+
#
|
72
|
+
# request = SingularityClient::Request.new(config)
|
73
|
+
# request.post(endpoint, post_data)
|
74
|
+
#
|
75
|
+
# puts('success!')
|
76
|
+
# end
|
59
77
|
end
|
60
78
|
end
|
@@ -23,41 +23,48 @@ module SingularityClient
|
|
23
23
|
class_option :debug, aliases: '-d', type: :boolean,
|
24
24
|
desc: 'Turn on debug mode'
|
25
25
|
|
26
|
-
desc 'config', 'Get the current singularity config object'
|
27
|
-
def config
|
28
|
-
|
29
|
-
end
|
26
|
+
# desc 'config', 'Get the current singularity config object'
|
27
|
+
# def config
|
28
|
+
# run(:config)
|
29
|
+
# end
|
30
30
|
|
31
31
|
desc 'add REPO_NAME PROJECT_NAME', 'Add a github repository to singularity'
|
32
32
|
long_desc 'This will add both pull requests, and pushes, to singularity'
|
33
33
|
method_option :github_organization, aliases: '-o', type: :string,
|
34
34
|
desc: 'Override the default github organization'
|
35
35
|
def add(repo, project)
|
36
|
-
run(:add, repo, project, '
|
37
|
-
run(:add, repo, project, '
|
36
|
+
run(:add, repo, project, 'proposal')
|
37
|
+
run(:add, repo, project, 'change')
|
38
38
|
end
|
39
39
|
|
40
|
-
desc '
|
40
|
+
desc 'add_pull REPO_NAME PROJECT_NAME', 'Add repo pulls to singularity'
|
41
41
|
method_option :github_organization, aliases: '-o', type: :string,
|
42
42
|
desc: 'Override the default github organization'
|
43
43
|
def add_pull(repo, project)
|
44
|
-
run(:add, repo, project, '
|
44
|
+
run(:add, repo, project, 'proposal')
|
45
45
|
end
|
46
46
|
|
47
|
-
desc '
|
47
|
+
desc 'add_push REPO_NAME PROJECT_NAME', 'Add repo pushes to singularity'
|
48
48
|
method_option :github_organization, aliases: '-o', type: :string,
|
49
49
|
desc: 'Override the default github organization'
|
50
50
|
def add_push(repo, project)
|
51
|
-
run(:add, repo, project, '
|
51
|
+
run(:add, repo, project, 'change')
|
52
52
|
end
|
53
53
|
|
54
|
-
desc '
|
54
|
+
desc 'remove_repo REPO_NAME', 'Remove a repository from the config'
|
55
55
|
method_option :github_organization, aliases: '-o', type: :string,
|
56
56
|
desc: 'Override the default github organization'
|
57
|
-
def
|
58
|
-
run(:
|
57
|
+
def remove_repo(repo)
|
58
|
+
run(:remove, repo)
|
59
59
|
end
|
60
60
|
|
61
|
+
# desc 'comment REPO_NAME PR_NUM COMMENT', 'Write comment to a pull request'
|
62
|
+
# method_option :github_organization, aliases: '-o', type: :string,
|
63
|
+
# desc: 'Override the default github organization'
|
64
|
+
# def comment(repo, pr, comment)
|
65
|
+
# run(:comment, repo, pr, comment)
|
66
|
+
# end
|
67
|
+
|
61
68
|
private
|
62
69
|
|
63
70
|
def run(action, *args)
|
@@ -31,6 +31,16 @@ module SingularityClient
|
|
31
31
|
response.code == 200 ? response : error(response)
|
32
32
|
end
|
33
33
|
|
34
|
+
def delete(endpoint, data = {})
|
35
|
+
request = "#{@base_uri}/#{endpoint}"
|
36
|
+
puts "DEBUG: sending delete request to #{request}" if @debug
|
37
|
+
puts "DEBUG: with data #{data}" if @debug
|
38
|
+
|
39
|
+
response = self.class.delete(request, body: data)
|
40
|
+
|
41
|
+
response.code == 200 ? response : error(response)
|
42
|
+
end
|
43
|
+
|
34
44
|
private
|
35
45
|
|
36
46
|
def error(response)
|
@@ -12,37 +12,37 @@ describe SingularityClient::API do
|
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '.config' do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
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
46
|
|
47
47
|
describe '.add' do
|
48
48
|
|
@@ -51,13 +51,13 @@ describe SingularityClient::API do
|
|
51
51
|
SingularityClient::API.add(config_obj,
|
52
52
|
'test_repo',
|
53
53
|
'test_project',
|
54
|
-
'
|
54
|
+
'proposal'
|
55
55
|
)
|
56
56
|
end
|
57
57
|
|
58
58
|
describe 'when it receives a succesful response' do
|
59
59
|
it 'it returns success!' do
|
60
|
-
VCR.use_cassette('
|
60
|
+
VCR.use_cassette('addProposal') do
|
61
61
|
expect(STDOUT).to receive(:puts).with('success!')
|
62
62
|
add
|
63
63
|
end
|
@@ -70,34 +70,51 @@ describe SingularityClient::API do
|
|
70
70
|
SingularityClient::API.add(config_obj,
|
71
71
|
'test_repo',
|
72
72
|
'test_project',
|
73
|
-
'
|
73
|
+
'change'
|
74
74
|
)
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'when it receives a succesful response' do
|
78
78
|
it 'it returns success!' do
|
79
|
-
VCR.use_cassette('
|
79
|
+
VCR.use_cassette('addChange') do
|
80
80
|
expect(STDOUT).to receive(:puts).with('success!')
|
81
81
|
add
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
-
end
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
describe '.remove' do
|
88
|
+
subject(:remove) do
|
89
|
+
SingularityClient::API.remove(config_obj,
|
90
|
+
'test_repo'
|
91
|
+
)
|
92
|
+
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
describe 'Delete a repo' do
|
95
|
+
it 'returns success!' do
|
96
|
+
VCR.use_cassette('removeRepo') do
|
97
|
+
expect(STDOUT).to receive(:puts).with('success!')
|
98
|
+
remove
|
99
|
+
end
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
102
103
|
end
|
104
|
+
|
105
|
+
# describe '.comment' do
|
106
|
+
# subject(:comment) do
|
107
|
+
# comment = 'This is some test comment'
|
108
|
+
# SingularityClient::API.comment(config_obj, 'test_repo', '12', comment)
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# describe 'when it receives a succesful response' do
|
112
|
+
# it 'it returns success!' do
|
113
|
+
# VCR.use_cassette('comment') do
|
114
|
+
# expect(STDOUT).to receive(:puts).with('success!')
|
115
|
+
# comment
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# end
|
119
|
+
# end
|
103
120
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://mergeatron.dev-be-aws.net:3306/config/
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/config/change
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
|
-
string:
|
8
|
+
string: repository=some_org/test_repo&project=test_project
|
9
9
|
headers: {}
|
10
10
|
response:
|
11
11
|
status:
|
@@ -2,10 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: http://mergeatron.dev-be-aws.net:3306/config/
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/config/proposal
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
|
-
string:
|
8
|
+
string: repository=some_org/test_repo&project=test_project
|
9
9
|
headers: {}
|
10
10
|
response:
|
11
11
|
status:
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: http://mergeatron.dev-be-aws.net:3306/config/repo
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: repository=some_org/test_repo
|
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
|
+
- Wed, 18 Jun 2014 22:58:24 GMT
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"success":true}'
|
28
|
+
http_version:
|
29
|
+
recorded_at: Wed, 18 Jun 2014 22:58:23 GMT
|
30
|
+
recorded_with: VCR 2.9.2
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singularity_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -184,12 +184,13 @@ files:
|
|
184
184
|
- spec/singularity_client/config_spec.rb
|
185
185
|
- spec/singularity_client/request_spec.rb
|
186
186
|
- spec/spec_helper.rb
|
187
|
-
- spec/vcr_cassettes/
|
188
|
-
- spec/vcr_cassettes/
|
187
|
+
- spec/vcr_cassettes/addChange.yml
|
188
|
+
- spec/vcr_cassettes/addProposal.yml
|
189
189
|
- spec/vcr_cassettes/comment.yml
|
190
190
|
- spec/vcr_cassettes/config.yml
|
191
191
|
- spec/vcr_cassettes/error-get.yml
|
192
192
|
- spec/vcr_cassettes/error-post.yml
|
193
|
+
- spec/vcr_cassettes/removeRepo.yml
|
193
194
|
homepage: ''
|
194
195
|
licenses:
|
195
196
|
- MIT
|
@@ -205,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
206
|
version: '0'
|
206
207
|
segments:
|
207
208
|
- 0
|
208
|
-
hash:
|
209
|
+
hash: 1881409474290039325
|
209
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
211
|
none: false
|
211
212
|
requirements:
|
@@ -214,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
215
|
version: '0'
|
215
216
|
segments:
|
216
217
|
- 0
|
217
|
-
hash:
|
218
|
+
hash: 1881409474290039325
|
218
219
|
requirements: []
|
219
220
|
rubyforge_project:
|
220
221
|
rubygems_version: 1.8.23
|
@@ -227,9 +228,10 @@ test_files:
|
|
227
228
|
- spec/singularity_client/config_spec.rb
|
228
229
|
- spec/singularity_client/request_spec.rb
|
229
230
|
- spec/spec_helper.rb
|
230
|
-
- spec/vcr_cassettes/
|
231
|
-
- spec/vcr_cassettes/
|
231
|
+
- spec/vcr_cassettes/addChange.yml
|
232
|
+
- spec/vcr_cassettes/addProposal.yml
|
232
233
|
- spec/vcr_cassettes/comment.yml
|
233
234
|
- spec/vcr_cassettes/config.yml
|
234
235
|
- spec/vcr_cassettes/error-get.yml
|
235
236
|
- spec/vcr_cassettes/error-post.yml
|
237
|
+
- spec/vcr_cassettes/removeRepo.yml
|