tinybucket 0.1.7 → 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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +2 -1
- data/Gemfile +4 -4
- data/README.md +48 -20
- data/Rakefile +7 -0
- data/lib/tinybucket.rb +7 -4
- data/lib/tinybucket/api/base_api.rb +2 -19
- data/lib/tinybucket/api/branch_restrictions_api.rb +35 -11
- data/lib/tinybucket/api/comments_api.rb +38 -4
- data/lib/tinybucket/api/commits_api.rb +60 -10
- data/lib/tinybucket/api/diff_api.rb +22 -0
- data/lib/tinybucket/api/helper/api_helper.rb +0 -11
- data/lib/tinybucket/api/helper/commits_helper.rb +7 -0
- data/lib/tinybucket/api/pull_requests_api.rb +79 -22
- data/lib/tinybucket/api/repo_api.rb +37 -17
- data/lib/tinybucket/api/repos_api.rb +13 -6
- data/lib/tinybucket/api/team_api.rb +54 -29
- data/lib/tinybucket/api/user_api.rb +43 -23
- data/lib/tinybucket/api_factory.rb +2 -4
- data/lib/tinybucket/client.rb +39 -20
- data/lib/tinybucket/config.rb +1 -1
- data/lib/tinybucket/connection.rb +3 -3
- data/lib/tinybucket/enumerator.rb +44 -0
- data/lib/tinybucket/error.rb +2 -0
- data/lib/tinybucket/error/conflict.rb +6 -0
- data/lib/tinybucket/error/not_found.rb +6 -0
- data/lib/tinybucket/error/service_error.rb +8 -4
- data/lib/tinybucket/iterator.rb +77 -0
- data/lib/tinybucket/model/base.rb +6 -6
- data/lib/tinybucket/model/branch_restriction.rb +27 -0
- data/lib/tinybucket/model/comment.rb +32 -6
- data/lib/tinybucket/model/commit.rb +63 -9
- data/lib/tinybucket/model/concerns.rb +1 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +18 -0
- data/lib/tinybucket/model/error_response.rb +16 -1
- data/lib/tinybucket/model/page.rb +25 -49
- data/lib/tinybucket/model/profile.rb +56 -8
- data/lib/tinybucket/model/pull_request.rb +114 -18
- data/lib/tinybucket/model/repository.rb +177 -36
- data/lib/tinybucket/model/team.rb +70 -10
- data/lib/tinybucket/request.rb +2 -0
- data/lib/tinybucket/response.rb +1 -1
- data/lib/tinybucket/response/handler.rb +21 -0
- data/lib/tinybucket/version.rb +1 -1
- data/spec/fixtures/repositories/test_owner/test_repo/commit/1/approve/post.json +16 -0
- data/spec/lib/tinybucket/api/branch_restrictions_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/comments_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/commits_api_spec.rb +92 -3
- data/spec/lib/tinybucket/api/pull_requests_api_spec.rb +34 -4
- data/spec/lib/tinybucket/api/repo_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/repos_api_spec.rb +1 -2
- data/spec/lib/tinybucket/api/team_api_spec.rb +1 -6
- data/spec/lib/tinybucket/api/user_api_spec.rb +15 -2
- data/spec/lib/tinybucket/api_factory_spec.rb +2 -7
- data/spec/lib/tinybucket/client_spec.rb +10 -25
- data/spec/lib/tinybucket/error/service_error_spec.rb +23 -0
- data/spec/lib/tinybucket/model/commit_spec.rb +27 -4
- data/spec/lib/tinybucket/model/page_spec.rb +0 -30
- data/spec/lib/tinybucket/model/profile_spec.rb +3 -3
- data/spec/lib/tinybucket/model/pull_request_spec.rb +11 -5
- data/spec/lib/tinybucket/model/repository_spec.rb +5 -5
- data/spec/lib/tinybucket/model/team_spec.rb +4 -4
- data/spec/lib/tinybucket_spec.rb +10 -27
- data/spec/spec_helper.rb +3 -2
- data/spec/support/api_response_macros.rb +2 -2
- metadata +12 -3
- data/lib/tinybucket/response/error_handler.rb +0 -14
@@ -1,96 +1,237 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Model
|
3
|
+
# Repository
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/repositories-endpoint-423626330.html#repositoriesEndpoint-Overview
|
6
|
+
# Repository Endpoint - Bitbucket Cloud REST API document
|
7
|
+
#
|
8
|
+
# @!attribute [rw] scm
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [rw] has_wiki
|
11
|
+
# @return [true, false]
|
12
|
+
# @!attribute [rw] description
|
13
|
+
# @return [String]
|
14
|
+
# @!attribute [rw] links
|
15
|
+
# @return [Hash]
|
16
|
+
# @!attribute [rw] updated_on
|
17
|
+
# @return [String]
|
18
|
+
# @!attribute [rw] fork_policy
|
19
|
+
# @return [String]
|
20
|
+
# @!attribute [rw] created_on
|
21
|
+
# @return [String]
|
22
|
+
# @!attribute [rw] owner
|
23
|
+
# @return [Hash]
|
24
|
+
# @!attribute [rw] size
|
25
|
+
# @return [Fixnum]
|
26
|
+
# @!attribute [rw] parent
|
27
|
+
# @return [Hash, NillClass]
|
28
|
+
# @!attribute [rw] uuid
|
29
|
+
# @return [String]
|
30
|
+
# @!attribute [rw] has_issues
|
31
|
+
# @return [true, false]
|
32
|
+
# @!attribute [rw] is_private
|
33
|
+
# @return [true, false]
|
34
|
+
# @!attribute [rw] full_name
|
35
|
+
# @return [String]
|
36
|
+
# @!attribute [rw] name
|
37
|
+
# @return [String]
|
38
|
+
# @!attribute [rw] language
|
39
|
+
# @return [String]
|
40
|
+
# @!attribute [rw] website
|
41
|
+
# @return [String]
|
42
|
+
# @!attribute [rw] type
|
43
|
+
# @return [String]
|
3
44
|
class Repository < Base
|
4
45
|
include Tinybucket::Model::Concerns::RepositoryKeys
|
5
|
-
include Tinybucket::Model::Concerns::Reloadable
|
6
46
|
|
7
47
|
acceptable_attributes \
|
8
48
|
:scm, :has_wiki, :description, :links, :updated_on,
|
9
49
|
:fork_policy, :created_on, :owner, :size, :parent, :uuid,
|
10
|
-
:has_issues, :is_private, :full_name, :name, :language
|
50
|
+
:has_issues, :is_private, :full_name, :name, :language,
|
51
|
+
:website, :type
|
11
52
|
|
53
|
+
def initialize(json)
|
54
|
+
super(json)
|
55
|
+
|
56
|
+
if full_name && full_name.split('/').size == 2
|
57
|
+
@repo_owner, @repo_slug = full_name.split('/')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create a new repository.
|
62
|
+
#
|
63
|
+
# @todo to be implemented.
|
64
|
+
# @raise [NotImplementedError] to be implemented.
|
12
65
|
def create(_params)
|
13
66
|
raise NotImplementedError
|
14
67
|
end
|
15
68
|
|
69
|
+
# Remove this repository
|
70
|
+
#
|
71
|
+
# @todo to be implemented.
|
72
|
+
# @raise [NotImplementedError] to be implemented.
|
16
73
|
def destroy
|
17
74
|
raise NotImplementedError
|
18
75
|
end
|
19
76
|
|
77
|
+
# Get pull requests on thie repository.
|
78
|
+
#
|
79
|
+
# @param options [Hash]
|
80
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate
|
81
|
+
# pull requests as {Tinybucket::Model::PullRequest} instance.
|
20
82
|
def pull_requests(options = {})
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
83
|
+
enumerator(
|
84
|
+
pull_requests_api,
|
85
|
+
:list,
|
86
|
+
options
|
87
|
+
) do |m|
|
88
|
+
inject_repo_keys(m)
|
89
|
+
block_given? ? yield(m) : m
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Get the specific pull request on this repository.
|
94
|
+
#
|
95
|
+
# @param pullrequest_id [String]
|
96
|
+
# @param options [Hash]
|
97
|
+
# @return [Tinybucket::Model::PullRequest]
|
25
98
|
def pull_request(pullrequest_id = nil, options = {})
|
26
99
|
m = if pullrequest_id.present?
|
27
|
-
pull_requests_api
|
100
|
+
pull_requests_api.find(pullrequest_id, options)
|
28
101
|
else
|
29
102
|
Tinybucket::Model::PullRequest.new({})
|
30
103
|
end
|
31
104
|
inject_repo_keys(m)
|
32
105
|
end
|
33
106
|
|
107
|
+
# Get watchers on this repository.
|
108
|
+
#
|
109
|
+
# @param options [Hash]
|
110
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate watchers
|
111
|
+
# as {Tinybucket::Model::Profile} instance.
|
34
112
|
def watchers(options = {})
|
35
|
-
|
36
|
-
|
37
|
-
|
113
|
+
enumerator(
|
114
|
+
repo_api,
|
115
|
+
:watchers,
|
116
|
+
options
|
117
|
+
) do |m|
|
118
|
+
inject_repo_keys(m)
|
119
|
+
block_given? ? yield(m) : m
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Get repository forks.
|
124
|
+
#
|
125
|
+
# @param options [Hash]
|
126
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate forks
|
127
|
+
# as {Tinybucket::Model::Repository} instance.
|
38
128
|
def forks(options = {})
|
39
|
-
|
40
|
-
|
41
|
-
|
129
|
+
enumerator(
|
130
|
+
repo_api,
|
131
|
+
:forks,
|
132
|
+
options
|
133
|
+
) do |m|
|
134
|
+
inject_repo_keys(m)
|
135
|
+
block_given? ? yield(m) : m
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Get commits on this repository.
|
140
|
+
#
|
141
|
+
# @param options [Hash]
|
142
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate commits
|
143
|
+
# as {Tinybucket::Model::Commit} instance.
|
42
144
|
def commits(options = {})
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
145
|
+
enumerator(
|
146
|
+
commits_api,
|
147
|
+
:list,
|
148
|
+
options
|
149
|
+
) do |m|
|
150
|
+
inject_repo_keys(m)
|
151
|
+
block_given? ? yield(m) : m
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Get the specific commit on this repository.
|
156
|
+
#
|
157
|
+
# @param revision [String]
|
158
|
+
# @param options [Hash]
|
159
|
+
# @return [Tinybucket::Model::Commit]
|
47
160
|
def commit(revision, options = {})
|
48
|
-
m = commits_api
|
161
|
+
m = commits_api.find(revision, options)
|
49
162
|
inject_repo_keys(m)
|
50
163
|
end
|
51
164
|
|
165
|
+
# Get the branch restriction information associated with this repository.
|
166
|
+
#
|
167
|
+
# @param options [Hash]
|
168
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate
|
169
|
+
# branch restriction information as
|
170
|
+
# {Tinybucket::Model::BranchRestriction} instance.
|
52
171
|
def branch_restrictions(options = {})
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
172
|
+
enumerator(
|
173
|
+
restrictions_api,
|
174
|
+
:list,
|
175
|
+
options
|
176
|
+
) do |m|
|
177
|
+
inject_repo_keys(m)
|
178
|
+
block_given? ? yield(m) : m
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# Get the specific branch restriction information on this repository.
|
183
|
+
#
|
184
|
+
# @param restriction_id [String]
|
185
|
+
# @param options [Hash]
|
186
|
+
# @return [Tinybucket::Model::BranchRestriction]
|
57
187
|
def branch_restriction(restriction_id, options = {})
|
58
|
-
m = restrictions_api
|
188
|
+
m = restrictions_api.find(restriction_id, options)
|
59
189
|
inject_repo_keys(m)
|
60
190
|
end
|
61
191
|
|
192
|
+
# Get the diff for this repository.
|
193
|
+
#
|
194
|
+
# @param spec [String] A specification such as a branch name,
|
195
|
+
# revision, or commit SHA.
|
196
|
+
# @param options [Hash]
|
197
|
+
# @return [String] diff as raw text.
|
62
198
|
def diff(spec, options = {})
|
63
|
-
diff_api
|
199
|
+
diff_api.find(spec, options)
|
64
200
|
end
|
65
201
|
|
202
|
+
# Get the patch for the specification.
|
203
|
+
#
|
204
|
+
# @param spec [String] A specification such as a branch name,
|
205
|
+
# revision, or commit SHA.
|
206
|
+
# @return [String] patch as raw text.
|
66
207
|
def patch(spec, options = {})
|
67
|
-
diff_api
|
208
|
+
diff_api.find_patch(spec, options)
|
68
209
|
end
|
69
210
|
|
70
211
|
private
|
71
212
|
|
72
|
-
def pull_requests_api
|
73
|
-
create_api('PullRequests', repo_keys
|
213
|
+
def pull_requests_api
|
214
|
+
create_api('PullRequests', repo_keys)
|
74
215
|
end
|
75
216
|
|
76
|
-
def repo_api
|
77
|
-
create_api('Repo', repo_keys
|
217
|
+
def repo_api
|
218
|
+
create_api('Repo', repo_keys)
|
78
219
|
end
|
79
220
|
|
80
|
-
def commits_api
|
81
|
-
create_api('Commits', repo_keys
|
221
|
+
def commits_api
|
222
|
+
create_api('Commits', repo_keys)
|
82
223
|
end
|
83
224
|
|
84
|
-
def restrictions_api
|
85
|
-
create_api('BranchRestrictions', repo_keys
|
225
|
+
def restrictions_api
|
226
|
+
create_api('BranchRestrictions', repo_keys)
|
86
227
|
end
|
87
228
|
|
88
|
-
def diff_api
|
89
|
-
create_api('Diff', repo_keys
|
229
|
+
def diff_api
|
230
|
+
create_api('Diff', repo_keys)
|
90
231
|
end
|
91
232
|
|
92
233
|
def load_model
|
93
|
-
repo_api
|
234
|
+
repo_api.find()
|
94
235
|
end
|
95
236
|
end
|
96
237
|
end
|
@@ -1,38 +1,98 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Model
|
3
|
+
# Team
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/teams-endpoint-423626335.html#teamsEndpoint-Overview
|
6
|
+
# teams Endpoint - Bitbucket Cloud REST API document
|
7
|
+
#
|
8
|
+
# @!attribute [rw] username
|
9
|
+
# @return [String]
|
10
|
+
# @!attribute [rw] kind
|
11
|
+
# @return [String, NillClass]
|
12
|
+
# @!attribute [rw] website
|
13
|
+
# @return [String, NillClass]
|
14
|
+
# @!attribute [rw] display_name
|
15
|
+
# @return [String]
|
16
|
+
# @!attribute [rw] uuid
|
17
|
+
# @return [String]
|
18
|
+
# @!attribute [rw] links
|
19
|
+
# @return [Hash]
|
20
|
+
# @!attribute [rw] created_on
|
21
|
+
# @return [String]
|
22
|
+
# @!attribute [rw] location
|
23
|
+
# @return [String, NillClass]
|
24
|
+
# @!attribute [rw] type
|
25
|
+
# @return [String]
|
3
26
|
class Team < Base
|
4
|
-
include Tinybucket::Model::Concerns::Reloadable
|
5
|
-
|
6
27
|
acceptable_attributes \
|
7
28
|
:username, :kind, :website, :display_name, :uuid,
|
8
29
|
:links, :created_on, :location, :type
|
9
30
|
|
31
|
+
# Get this team's members.
|
32
|
+
#
|
33
|
+
# @param options [Hash]
|
34
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate members
|
35
|
+
# as {Tinybucket::Model::Team} instance.
|
10
36
|
def members(options = {})
|
11
|
-
|
37
|
+
enumerator(
|
38
|
+
team_api,
|
39
|
+
:members,
|
40
|
+
username,
|
41
|
+
options
|
42
|
+
) { |m| block_given? ? yield(m) : m }
|
12
43
|
end
|
13
44
|
|
45
|
+
# Get this team's followers.
|
46
|
+
#
|
47
|
+
# @param options [Hash]
|
48
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate followers
|
49
|
+
# as {Tinybucket::Model::Team} instance.
|
14
50
|
def followers(options = {})
|
15
|
-
|
51
|
+
enumerator(
|
52
|
+
team_api,
|
53
|
+
:followers,
|
54
|
+
username,
|
55
|
+
options
|
56
|
+
) { |m| block_given? ? yield(m) : m }
|
16
57
|
end
|
17
58
|
|
59
|
+
# Get users which this team is following.
|
60
|
+
#
|
61
|
+
# @param options [Hash]
|
62
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate followings
|
63
|
+
# as {Tinybucket::Model::Team} instance.
|
18
64
|
def following(options = {})
|
19
|
-
|
65
|
+
enumerator(
|
66
|
+
team_api,
|
67
|
+
:following,
|
68
|
+
username,
|
69
|
+
options
|
70
|
+
) { |m| block_given? ? yield(m) : m }
|
20
71
|
end
|
21
72
|
|
73
|
+
# Get this team's repositories.
|
74
|
+
#
|
75
|
+
# @param options [Hash]
|
76
|
+
# @return [Tinybucket::Enumerator] an enumerator to enumerate repositories
|
77
|
+
# as {Tinybucket::Model::Repository} instance.
|
22
78
|
def repos(options = {})
|
23
|
-
|
79
|
+
enumerator(
|
80
|
+
team_api,
|
81
|
+
:repos,
|
82
|
+
username,
|
83
|
+
options
|
84
|
+
) { |m| block_given? ? yield(m) : m }
|
24
85
|
end
|
25
86
|
|
26
87
|
private
|
27
88
|
|
28
|
-
def team_api
|
89
|
+
def team_api
|
29
90
|
return @team if @team
|
30
|
-
|
31
|
-
@team = create_instance 'Team', options
|
91
|
+
@team = create_instance('Team')
|
32
92
|
end
|
33
93
|
|
34
94
|
def load_model
|
35
|
-
team_api
|
95
|
+
team_api.find(username)
|
36
96
|
end
|
37
97
|
end
|
38
98
|
end
|
data/lib/tinybucket/request.rb
CHANGED
data/lib/tinybucket/response.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tinybucket
|
2
|
+
module Response
|
3
|
+
class Handler < Faraday::Response::Middleware
|
4
|
+
def on_complete(env)
|
5
|
+
status_code = env[:status].to_i
|
6
|
+
|
7
|
+
return if status_code < 400
|
8
|
+
|
9
|
+
case status_code
|
10
|
+
when 404
|
11
|
+
raise Tinybucket::Error::NotFound.new(env)
|
12
|
+
when 409
|
13
|
+
raise Tinybucket::Error::Conflict.new(env)
|
14
|
+
else
|
15
|
+
Tinybucket.logger.error "Invalid response code:#{status_code}"
|
16
|
+
raise Tinybucket::Error::ServiceError.new(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/tinybucket/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"role": "PARTICIPANT",
|
3
|
+
"user": {
|
4
|
+
"username": "evzijst",
|
5
|
+
"display_name": "Erik van Zijst",
|
6
|
+
"links": {
|
7
|
+
"self": {
|
8
|
+
"href": "https://api.bitbucket.org/2.0/users/evzijst"
|
9
|
+
},
|
10
|
+
"avatar": {
|
11
|
+
"href": "https://bitbucket-staging-assetroot.s3.amazonaws.com/c/photos/2013/Oct/28/evzijst-avatar-3454044670-3_avatar.png"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
},
|
15
|
+
"approved": true
|
16
|
+
}
|
@@ -7,9 +7,8 @@ RSpec.describe Tinybucket::Api::BranchRestrictionsApi do
|
|
7
7
|
let(:slug) { 'test_repo' }
|
8
8
|
let(:request_path) { nil }
|
9
9
|
|
10
|
-
let(:api_config) { {} }
|
11
10
|
let(:api) do
|
12
|
-
api = Tinybucket::Api::BranchRestrictionsApi.new
|
11
|
+
api = Tinybucket::Api::BranchRestrictionsApi.new
|
13
12
|
api.repo_owner = owner
|
14
13
|
api.repo_slug = slug
|
15
14
|
api
|