stash-api 1.0.11.0 → 1.1.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/stash-api.rb +1 -1
- data/lib/stash-api/client.rb +183 -0
- data/lib/stash-api/dsl.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzgyY2I2NGFjZGFiY2M4NTExYjBjOGY2ODc3ZDMyODk0ZDllMTgyYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWRhMGY4ZDIxYzliZWY5YTI2MTM3ODkzMjYzZjFkYzEyMzgxYWY5Mg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTU1ZTFhYjA0M2Q3ODM1ODhlYmMzYmJhNGI0NWQwNjE3OWFkYmJhOGRmNjkw
|
10
|
+
MTYxNGMyMjE1MmYxMzljMDE1MTQwNzFjMjQzODk0Mjk2YmRkZWY0NGIyNjlj
|
11
|
+
YzM5YmZkNDhkOWE4OWZmZjA3YzUyNjE4MzBlZDRhMTljNzZlNjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTY4ZmU2NjY3Yjc3NTQ3YTBiNDYyMzBmZmFhMzMyMThmYTI5NzAyZWU5ZDg2
|
14
|
+
ZGE0MjhhYzMzNjg0OTg0MzIyOWJiN2ViOTFiY2Q2ZjU2OGZiZGU5ODZjMGY1
|
15
|
+
NmIzZWMyYzRmOGU3MGVlNTE4YzgwY2YzOTQ5MjFmZmQ5ZWFmNjM=
|
data/lib/stash-api.rb
CHANGED
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Stash
|
5
|
+
class Client
|
6
|
+
attr_accessor :server, :project, :repository_name
|
7
|
+
|
8
|
+
def initialize(username, password, config = {:follow_fork => true, :url => nil, :verify_ssl => true})
|
9
|
+
raise 'API username must be specified' if !username
|
10
|
+
raise 'API password must be specified' if !password
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
|
14
|
+
remote_origin_url = config[:url] || %x[git config --get remote.origin.url]
|
15
|
+
raise "Repository URL is not set and cannot be inferred from the git config." if !remote_origin_url
|
16
|
+
|
17
|
+
match = remote_origin_url.match(/(ssh|https?):\/\/([^@]*@)?(?<server>[^\:\/]*)[^\/]*\/(scm\/)?(?<project>[^\/].*)\/(?<repository_name>[^\/]*)\.git$/)
|
18
|
+
raise "Remote origin cannot be inferred from the url: #{remote_origin_url}. Run `git remote add origin URL` to add an origin." if !match
|
19
|
+
@server = match[:server]
|
20
|
+
@project = match[:project]
|
21
|
+
@repository_name = match[:repository_name]
|
22
|
+
|
23
|
+
@remote_api_url = File.join("https://#{@server}", 'rest', 'api', '1.0', 'projects', @project, 'repos', @repository_name)
|
24
|
+
@branch_permissions_url = File.join("https://#{@server}", 'rest', 'branch-permissions', '2.0', 'projects', @project, 'repos', @repository_name, 'restrictions')
|
25
|
+
@branchring_model_url = File.join("https://#{@server}", 'rest', 'branch-utils', '1.0', 'projects', @project, 'repos', @repository_name)
|
26
|
+
@pull_request_settings = File.join("https://#{@server}", 'rest', 'pullrequest-settings', '1.0', 'projects', @project, 'repos', @repository_name)
|
27
|
+
json = RestClient::Resource.new(@remote_api_url, {:user => @username, :password => @password, :verify_ssl => config[:verify_ssl]}).get
|
28
|
+
repository_information = JSON::pretty_generate(JSON.parse(json))
|
29
|
+
|
30
|
+
#If the repository is a fork, use it's forked source to get this information
|
31
|
+
if repository_information['origin'] && config[:follow_fork]
|
32
|
+
@project = repository_information['origin']['project']['key']
|
33
|
+
@repository_name = repository_information['origin']['slug']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
SETTINGS_HOOKS_URL = File.join('settings', 'hooks')
|
38
|
+
|
39
|
+
def set_hooks(hooks)
|
40
|
+
hooks.keys.each do |hook|
|
41
|
+
RestClient::Request.new(
|
42
|
+
:method => :put,
|
43
|
+
:url => URI::encode("#{File.join(@remote_api_url, SETTINGS_HOOKS_URL)}/#{hook}/enabled"),
|
44
|
+
:user => @username,
|
45
|
+
:password => @password,
|
46
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
47
|
+
raise "Could not enable hook: #{hook} - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
48
|
+
end
|
49
|
+
|
50
|
+
config = hooks[hook][:config]
|
51
|
+
if config
|
52
|
+
RestClient::Request.new(
|
53
|
+
:method => :put,
|
54
|
+
:url => URI::encode("#{File.join(@remote_api_url, SETTINGS_HOOKS_URL)}/#{hook}/settings"),
|
55
|
+
:user => @username,
|
56
|
+
:password => @password,
|
57
|
+
:payload => config.to_json,
|
58
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
59
|
+
raise "Could not configure hook: #{hook} - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_hooks()
|
66
|
+
config = {}
|
67
|
+
RestClient::Request.new(
|
68
|
+
:method => :get,
|
69
|
+
:url => URI::encode("#{File.join(@remote_api_url, SETTINGS_HOOKS_URL)}?limit=1000"),
|
70
|
+
:user => @username,
|
71
|
+
:password => @password,
|
72
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
73
|
+
raise "Could not get hooks - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
74
|
+
JSON::parse(response)['values'].map do |h|
|
75
|
+
hook = h['details']['key']
|
76
|
+
config[hook] = {:config => nil, :enabled => h['enabled']}
|
77
|
+
|
78
|
+
RestClient::Request.new(
|
79
|
+
:method => :get,
|
80
|
+
:url => URI::encode(File.join(@remote_api_url, SETTINGS_HOOKS_URL, hook, 'settings')),
|
81
|
+
:user => @username,
|
82
|
+
:password => @password,
|
83
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
84
|
+
config[hook][:config] = JSON::parse(response != '' ? response : '{}') if response.code.to_s.match(/^2\d{2}$/)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
config
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_branch_permissions(permissions)
|
92
|
+
raise "permissions list is required" if !permissions
|
93
|
+
[permissions].flatten.each do |permission|
|
94
|
+
RestClient::Request.new(
|
95
|
+
:method => :post,
|
96
|
+
:url => URI::encode("#{@branch_permissions_url}?"),
|
97
|
+
:user => @username,
|
98
|
+
:password => @password,
|
99
|
+
:payload => permission.to_json,
|
100
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
101
|
+
raise "Could not set branch permissions - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def get_branch_permissions()
|
107
|
+
RestClient::Request.new(
|
108
|
+
:method => :get,
|
109
|
+
:url => URI::encode("#{@branch_permissions_url}?limit=1000"),
|
110
|
+
:user => @username,
|
111
|
+
:password => @password,
|
112
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
113
|
+
raise "Could not get branch permissions - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
114
|
+
return JSON::parse(response)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def set_pull_request_settings(settings)
|
119
|
+
RestClient::Request.new(
|
120
|
+
:method => :put,
|
121
|
+
:url => URI::encode(File.join(@pull_request_settings, 'requiredBuildsCount', settings[:builds].to_s)),
|
122
|
+
:user => @username,
|
123
|
+
:password => @password,
|
124
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
125
|
+
raise "Could not get set required builds - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
126
|
+
end if settings[:builds]
|
127
|
+
RestClient::Request.new(
|
128
|
+
:method => :put,
|
129
|
+
:url => URI::encode(File.join(@pull_request_settings, 'requiredApproversCount', settings[:approvers].to_s)),
|
130
|
+
:user => @username,
|
131
|
+
:password => @password,
|
132
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
133
|
+
raise "Could not get set pull request approvers - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
134
|
+
end if settings[:approvers]
|
135
|
+
end
|
136
|
+
|
137
|
+
def get_pull_request_settings()
|
138
|
+
settings = {}
|
139
|
+
RestClient::Request.new(
|
140
|
+
:method => :get,
|
141
|
+
:url => URI::encode(File.join(@pull_request_settings, 'requiredBuildsCount')),
|
142
|
+
:user => @username,
|
143
|
+
:password => @password,
|
144
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
145
|
+
settings[:builds] = response.body if response.code.to_s.match(/^2\d{2}$/)
|
146
|
+
end
|
147
|
+
RestClient::Request.new(
|
148
|
+
:method => :get,
|
149
|
+
:url => URI::encode(File.join(@pull_request_settings, 'requiredApproversCount')),
|
150
|
+
:user => @username,
|
151
|
+
:password => @password,
|
152
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
153
|
+
settings[:approvers] = response.body if response.code.to_s.match(/^2\d{2}$/)
|
154
|
+
end
|
155
|
+
settings
|
156
|
+
end
|
157
|
+
|
158
|
+
BRANCHING_MODEL_URL = File.join('automerge', 'enabled')
|
159
|
+
def set_automatic_merging()
|
160
|
+
RestClient::Request.new(
|
161
|
+
:method => :put,
|
162
|
+
:url => URI::encode(File.join(@branchring_model_url, BRANCHING_MODEL_URL)),
|
163
|
+
:user => @username,
|
164
|
+
:password => @password,
|
165
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
166
|
+
raise "Could not get branchig model - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_automatic_merging()
|
171
|
+
RestClient::Request.new(
|
172
|
+
:method => :get,
|
173
|
+
:url => URI::encode(File.join(@branchring_model_url, BRANCHING_MODEL_URL)),
|
174
|
+
:user => @username,
|
175
|
+
:password => @password,
|
176
|
+
:headers => { :accept => :json, :content_type => :json }).execute do |response, request, result|
|
177
|
+
raise "Could not get branchig model - #{JSON::pretty_generate(JSON::parse(response.body))}" if !response.code.to_s.match(/^2\d{2}$/)
|
178
|
+
return response.code == 204
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
data/lib/stash-api/dsl.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Warren Parad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- lib/stash-api.rb
|
63
|
+
- lib/stash-api/client.rb
|
63
64
|
- lib/stash-api/dsl.rb
|
64
65
|
homepage: https://github.com/wparad/Stash-API
|
65
66
|
licenses:
|