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,14 +1,36 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# Diff Api client
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/diff-resource-425462484.html
|
6
|
+
# diff Resource
|
7
|
+
#
|
8
|
+
# @!attribute [rw] repo_owner
|
9
|
+
# @return [String] repository owner name.
|
10
|
+
# @!attribute [rw] repo_slug
|
11
|
+
# @return [String] repository slug. (about {https://confluence.atlassian.com/bitbucket/repositories-endpoint-423626330.html#repositoriesEndpoint-Overview
|
12
|
+
# repo_slug})
|
3
13
|
class DiffApi < BaseApi
|
4
14
|
include Tinybucket::Api::Helper::DiffHelper
|
5
15
|
|
6
16
|
attr_accessor :repo_owner, :repo_slug
|
7
17
|
|
18
|
+
# Send 'GET a diff' request
|
19
|
+
#
|
20
|
+
# @param spec [String] A specification such as a branch name,
|
21
|
+
# revision, or commit SHA.
|
22
|
+
# @param options [Hash]
|
23
|
+
# @return [String] diff as raw text
|
8
24
|
def find(spec, options = {})
|
9
25
|
get_path(path_to_find(spec), options)
|
10
26
|
end
|
11
27
|
|
28
|
+
# Send 'GET a patch' request
|
29
|
+
#
|
30
|
+
# @param spec [String] A specification such as a branch name,
|
31
|
+
# revision, or commit SHA.
|
32
|
+
# @param options [Hash]
|
33
|
+
# @return [String] patch as raw text
|
12
34
|
def find_patch(spec, options = {})
|
13
35
|
get_path(path_to_patch(spec), options)
|
14
36
|
end
|
@@ -10,17 +10,6 @@ module Tinybucket
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def inject_api_config(result)
|
14
|
-
case result
|
15
|
-
when Tinybucket::Model::Page
|
16
|
-
result.items.map { |m| m.api_config = @config.dup }
|
17
|
-
when Tinybucket::Model::Base
|
18
|
-
result.api_config = @config.dup
|
19
|
-
end
|
20
|
-
|
21
|
-
result
|
22
|
-
end
|
23
|
-
|
24
13
|
def urlencode(v, key)
|
25
14
|
if v.blank? || (escaped = CGI.escape(v.to_s)).blank?
|
26
15
|
msg = "Invalid #{key} parameter. (#{v})"
|
@@ -16,6 +16,13 @@ module Tinybucket
|
|
16
16
|
[revision, 'revision'])
|
17
17
|
end
|
18
18
|
|
19
|
+
def path_to_approve(revision)
|
20
|
+
build_path(base_path,
|
21
|
+
'commit',
|
22
|
+
[revision, 'revision'],
|
23
|
+
'approve')
|
24
|
+
end
|
25
|
+
|
19
26
|
def base_path
|
20
27
|
build_path('/repositories',
|
21
28
|
[repo_owner, 'repo_owner'],
|
@@ -1,56 +1,113 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# PullRequests Api client
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/pullrequests-resource-423626332.html
|
6
|
+
# pullrequests Resource
|
7
|
+
#
|
8
|
+
# @!attribute [rw] repo_owner
|
9
|
+
# @return [String] repository owner name.
|
10
|
+
# @!attribute [rw] repo_slug
|
11
|
+
# @return [String] repository slug. (about {https://confluence.atlassian.com/bitbucket/repositories-endpoint-423626330.html#repositoriesEndpoint-Overview
|
12
|
+
# repo_slug})
|
3
13
|
class PullRequestsApi < BaseApi
|
4
14
|
include Tinybucket::Api::Helper::PullRequestsHelper
|
5
15
|
|
6
16
|
attr_accessor :repo_owner, :repo_slug
|
7
17
|
|
18
|
+
# Send 'GET a list of open pull requests' request
|
19
|
+
#
|
20
|
+
# @param options [Hash]
|
21
|
+
# @return [Tinybucket::Model::Page]
|
8
22
|
def list(options = {})
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
inject_api_config(list)
|
23
|
+
get_path(
|
24
|
+
path_to_list,
|
25
|
+
options,
|
26
|
+
Tinybucket::Parser::PullRequestsParser
|
27
|
+
)
|
15
28
|
end
|
16
29
|
|
30
|
+
# Send 'GET a specific pull request' request
|
31
|
+
#
|
32
|
+
# @param pr_id [String] The pull request identifier
|
33
|
+
# @param options [Hash]
|
34
|
+
# @return [Tinybucket::Model::PullRequest]
|
17
35
|
def find(pr_id, options = {})
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
get_path(
|
37
|
+
path_to_find(pr_id),
|
38
|
+
options,
|
39
|
+
Tinybucket::Parser::PullRequestParser
|
40
|
+
)
|
23
41
|
end
|
24
42
|
|
43
|
+
# Send 'GET the commits for a pull request' request
|
44
|
+
#
|
45
|
+
# @param pr_id [String] The pull request identifier
|
46
|
+
# @param options [Hash]
|
47
|
+
# @return [Tinybucket::Model::PullRequest]
|
25
48
|
def commits(pr_id, options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
inject_api_config(list)
|
49
|
+
get_path(
|
50
|
+
path_to_commits(pr_id),
|
51
|
+
options,
|
52
|
+
Tinybucket::Parser::CommitsParser
|
53
|
+
)
|
32
54
|
end
|
33
55
|
|
56
|
+
# Send 'POST a pull request approval' request
|
57
|
+
#
|
58
|
+
# @note This method return true if this pull request already approved.
|
59
|
+
#
|
60
|
+
# @param pr_id [String] The pull request identifier
|
61
|
+
# @param options [Hash]
|
62
|
+
# @return [true, false]
|
34
63
|
def approve(pr_id, options = {})
|
35
64
|
result = post_path(path_to_approve(pr_id), options)
|
36
65
|
(result['approved'] == true)
|
66
|
+
rescue Tinybucket::Error::Conflict => e
|
67
|
+
logger.debug 'Already approved: ' + e.inspect
|
68
|
+
true
|
37
69
|
end
|
38
70
|
|
71
|
+
# Send 'DELETE a pull request approval' request
|
72
|
+
#
|
73
|
+
# @note This method return true if this pull request is not approved yet.
|
74
|
+
#
|
75
|
+
# @param pr_id [String] The pull request identifier
|
76
|
+
# @param options [Hash]
|
77
|
+
# @return [true]
|
78
|
+
def unapprove(pr_id, options = {})
|
79
|
+
delete_path(path_to_approve(pr_id), options)
|
80
|
+
true
|
81
|
+
rescue Tinybucket::Error::NotFound => e
|
82
|
+
logger.debug 'Already unapproved: ' + e.inspect
|
83
|
+
true
|
84
|
+
end
|
85
|
+
|
86
|
+
# Send 'Decline or reject a pull request' request
|
87
|
+
#
|
88
|
+
# @param pr_id [String] The pull request identifier
|
89
|
+
# @param options [Hash]
|
90
|
+
# @return [true, false]
|
39
91
|
def decline(pr_id, options = {})
|
40
92
|
result = post_path(path_to_decline(pr_id), options)
|
41
93
|
(result['state'] == 'DECLINED')
|
42
94
|
end
|
43
95
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
96
|
+
# Send 'Accept and merge a pull request' request
|
97
|
+
#
|
98
|
+
# @param pr_id [String] The pull request identifier
|
99
|
+
# @param options [Hash]
|
100
|
+
# @return [true, false]
|
49
101
|
def merge(pr_id, options = {})
|
50
102
|
result = post_path(path_to_merge(pr_id), options)
|
51
103
|
(result['state'] == 'MERGED')
|
52
104
|
end
|
53
105
|
|
106
|
+
# Send 'GET the diff for a pull request' request
|
107
|
+
#
|
108
|
+
# @param pr_id [String] The pull request identifier
|
109
|
+
# @param options [Hash]
|
110
|
+
# @return [String] diff as raw text.
|
54
111
|
def diff(pr_id, options = {})
|
55
112
|
get_path(path_to_diff(pr_id), options)
|
56
113
|
end
|
@@ -1,34 +1,54 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# Repo Api client
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html
|
6
|
+
# repository Resource
|
7
|
+
#
|
8
|
+
# @!attribute [rw] repo_owner
|
9
|
+
# @return [String] repository owner name.
|
10
|
+
# @!attribute [rw] repo_slug
|
11
|
+
# @return [String] repository slug. (about {https://confluence.atlassian.com/bitbucket/repositories-endpoint-423626330.html#repositoriesEndpoint-Overview
|
12
|
+
# repo_slug})
|
3
13
|
class RepoApi < BaseApi
|
4
14
|
include Tinybucket::Api::Helper::RepoHelper
|
5
15
|
|
6
16
|
attr_accessor :repo_owner, :repo_slug
|
7
17
|
|
18
|
+
# Send 'GET a repository' request
|
19
|
+
#
|
20
|
+
# @param options [Hash]
|
21
|
+
# @return [Tinybucket::Model::Repository]
|
8
22
|
def find(options = {})
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
23
|
+
get_path(
|
24
|
+
path_to_find,
|
25
|
+
options,
|
26
|
+
Tinybucket::Parser::RepoParser
|
27
|
+
)
|
14
28
|
end
|
15
29
|
|
30
|
+
# Send 'GET a list of watchers' request
|
31
|
+
#
|
32
|
+
# @param options [Hash]
|
33
|
+
# @return [Tinybucket::Model::Page]
|
16
34
|
def watchers(options = {})
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
inject_api_config(list)
|
35
|
+
get_path(
|
36
|
+
path_to_watchers,
|
37
|
+
options,
|
38
|
+
Tinybucket::Parser::ProfilesParser
|
39
|
+
)
|
23
40
|
end
|
24
41
|
|
42
|
+
# Send 'GET a list of forks' request
|
43
|
+
#
|
44
|
+
# @param options [Hash]
|
45
|
+
# @return [Tinybucket::Model::Page]
|
25
46
|
def forks(options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
inject_api_config(list)
|
47
|
+
get_path(
|
48
|
+
path_to_forks,
|
49
|
+
options,
|
50
|
+
Tinybucket::Parser::ReposParser
|
51
|
+
)
|
32
52
|
end
|
33
53
|
end
|
34
54
|
end
|
@@ -1,18 +1,25 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# Repos Api client
|
3
4
|
class ReposApi < BaseApi
|
4
5
|
include Tinybucket::Api::Helper::ReposHelper
|
5
6
|
|
7
|
+
# Send 'GET a list of repositories for an account' request
|
8
|
+
#
|
9
|
+
# @see https://confluence.atlassian.com/bitbucket/repositories-endpoint-423626330.html#repositoriesEndpoint-GETalistofrepositoriesforanaccount
|
10
|
+
# GET a list of repositories for an account
|
11
|
+
#
|
12
|
+
# @param options [Hash]
|
13
|
+
# @return [Tinybucket::Model::Page]
|
6
14
|
def list(options = {})
|
7
15
|
opts = options.clone
|
8
16
|
opts.delete(:owner)
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
inject_api_config(list)
|
18
|
+
get_path(
|
19
|
+
path_to_list(options),
|
20
|
+
opts,
|
21
|
+
Tinybucket::Parser::ReposParser
|
22
|
+
)
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
@@ -1,50 +1,75 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# Team Api client
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/teams-endpoint-423626335.html
|
6
|
+
# teams Endpoint
|
3
7
|
class TeamApi < BaseApi
|
4
8
|
include Tinybucket::Api::Helper::TeamHelper
|
5
9
|
|
10
|
+
# Send 'GET the team profile' request
|
11
|
+
#
|
12
|
+
# @param name [String] The team's name
|
13
|
+
# @param options [Hash]
|
14
|
+
# @return [Tinybucket::Model::Team]
|
6
15
|
def find(name, options = {})
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
get_path(
|
17
|
+
path_to_find(name),
|
18
|
+
options,
|
19
|
+
Tinybucket::Parser::TeamParser
|
20
|
+
)
|
12
21
|
end
|
13
22
|
|
23
|
+
# Send 'GET the team members' request
|
24
|
+
#
|
25
|
+
# @param name [String] The team's name
|
26
|
+
# @param options [Hash]
|
27
|
+
# @return [Tinybucket::Model::Page]
|
14
28
|
def members(name, options = {})
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
inject_api_config(list)
|
29
|
+
get_path(
|
30
|
+
path_to_members(name),
|
31
|
+
options,
|
32
|
+
Tinybucket::Parser::TeamsParser
|
33
|
+
)
|
21
34
|
end
|
22
35
|
|
36
|
+
# Send 'GET the list of followers' request
|
37
|
+
#
|
38
|
+
# @param name [String] The team's name
|
39
|
+
# @param options [Hash]
|
40
|
+
# @return [Tinybucket::Model::Page]
|
23
41
|
def followers(name, options = {})
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
inject_api_config(list)
|
42
|
+
get_path(
|
43
|
+
path_to_followers(name),
|
44
|
+
options,
|
45
|
+
Tinybucket::Parser::TeamsParser
|
46
|
+
)
|
30
47
|
end
|
31
48
|
|
49
|
+
# Send 'GET a lisf of accounts the tema is following' request
|
50
|
+
#
|
51
|
+
# @param name [String] The team's name
|
52
|
+
# @param options [Hash]
|
53
|
+
# @return [Tinybucket::Model::Page]
|
32
54
|
def following(name, options = {})
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
inject_api_config(list)
|
55
|
+
get_path(
|
56
|
+
path_to_following(name),
|
57
|
+
options,
|
58
|
+
Tinybucket::Parser::TeamsParser
|
59
|
+
)
|
39
60
|
end
|
40
61
|
|
62
|
+
# Send 'GET the team's repositories' request
|
63
|
+
#
|
64
|
+
# @param name [String] The team's name
|
65
|
+
# @param options [Hash]
|
66
|
+
# @return [Tinybucket::Model::Page]
|
41
67
|
def repos(name, options = {})
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
inject_api_config(list)
|
68
|
+
get_path(
|
69
|
+
path_to_repos(name),
|
70
|
+
options,
|
71
|
+
Tinybucket::Parser::ReposParser
|
72
|
+
)
|
48
73
|
end
|
49
74
|
end
|
50
75
|
end
|
@@ -1,43 +1,63 @@
|
|
1
1
|
module Tinybucket
|
2
2
|
module Api
|
3
|
+
# User Api client
|
4
|
+
#
|
5
|
+
# @see https://confluence.atlassian.com/bitbucket/users-endpoint-423626336.html
|
6
|
+
# users Endpoint
|
7
|
+
#
|
8
|
+
# @!attribute [rw] username
|
9
|
+
# @return [String]
|
3
10
|
class UserApi < BaseApi
|
4
11
|
include Tinybucket::Api::Helper::UserHelper
|
5
12
|
|
6
13
|
attr_accessor :username
|
7
14
|
|
15
|
+
# Send 'GET the user profile' request
|
16
|
+
#
|
17
|
+
# @param options [Hash]
|
18
|
+
# @return [Tinybucket::Model::Profile]
|
8
19
|
def profile(options = {})
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
20
|
+
get_path(
|
21
|
+
path_to_find,
|
22
|
+
options,
|
23
|
+
Tinybucket::Parser::ProfileParser
|
24
|
+
)
|
14
25
|
end
|
15
26
|
|
27
|
+
# Send 'GET the list of followers' request
|
28
|
+
#
|
29
|
+
# @param options [Hash]
|
30
|
+
# @return [Tinybucket::Model::Page]
|
16
31
|
def followers(options = {})
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
inject_api_config(list)
|
32
|
+
get_path(
|
33
|
+
path_to_followers,
|
34
|
+
options,
|
35
|
+
Tinybucket::Parser::ProfilesParser
|
36
|
+
)
|
23
37
|
end
|
24
38
|
|
39
|
+
# Send 'GET a list of accounts the user is following' request
|
40
|
+
#
|
41
|
+
# @param options [Hash]
|
42
|
+
# @return [Tinybucket::Model::Page]
|
25
43
|
def following(options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
inject_api_config(list)
|
44
|
+
get_path(
|
45
|
+
path_to_following,
|
46
|
+
options,
|
47
|
+
Tinybucket::Parser::ProfilesParser
|
48
|
+
)
|
32
49
|
end
|
33
50
|
|
51
|
+
# Send 'GET the user's repositories' request
|
52
|
+
#
|
53
|
+
# @param options [Hash]
|
54
|
+
# @return [Tinybucket::Model::Page]
|
34
55
|
def repos(options = {})
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
inject_api_config(list)
|
56
|
+
get_path(
|
57
|
+
path_to_repos,
|
58
|
+
options,
|
59
|
+
Tinybucket::Parser::ReposParser
|
60
|
+
)
|
41
61
|
end
|
42
62
|
end
|
43
63
|
end
|