tb-bjb 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +86 -0
- data/Gemfile +32 -0
- data/LICENSE +21 -0
- data/README.md +387 -0
- data/Rakefile +47 -0
- data/lib/faraday_middleware/follow_oauth_redirects.rb +71 -0
- data/lib/tinybucket.rb +76 -0
- data/lib/tinybucket/api.rb +25 -0
- data/lib/tinybucket/api/base_api.rb +44 -0
- data/lib/tinybucket/api/branch_restrictions_api.rb +51 -0
- data/lib/tinybucket/api/branches_api.rb +48 -0
- data/lib/tinybucket/api/build_status_api.rb +69 -0
- data/lib/tinybucket/api/comments_api.rb +81 -0
- data/lib/tinybucket/api/commits_api.rb +97 -0
- data/lib/tinybucket/api/diff_api.rb +40 -0
- data/lib/tinybucket/api/helper.rb +27 -0
- data/lib/tinybucket/api/helper/api_helper.rb +39 -0
- data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +29 -0
- data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
- data/lib/tinybucket/api/helper/build_status_helper.rb +46 -0
- data/lib/tinybucket/api/helper/comments_helper.rb +51 -0
- data/lib/tinybucket/api/helper/commits_helper.rb +42 -0
- data/lib/tinybucket/api/helper/diff_helper.rb +31 -0
- data/lib/tinybucket/api/helper/projects_helper.rb +28 -0
- data/lib/tinybucket/api/helper/pull_requests_helper.rb +67 -0
- data/lib/tinybucket/api/helper/repo_helper.rb +31 -0
- data/lib/tinybucket/api/helper/repos_helper.rb +23 -0
- data/lib/tinybucket/api/helper/team_helper.rb +45 -0
- data/lib/tinybucket/api/helper/user_helper.rb +33 -0
- data/lib/tinybucket/api/projects_api.rb +26 -0
- data/lib/tinybucket/api/pull_requests_api.rb +139 -0
- data/lib/tinybucket/api/repo_api.rb +56 -0
- data/lib/tinybucket/api/repos_api.rb +28 -0
- data/lib/tinybucket/api/team_api.rb +91 -0
- data/lib/tinybucket/api/user_api.rb +66 -0
- data/lib/tinybucket/api_factory.rb +21 -0
- data/lib/tinybucket/client.rb +107 -0
- data/lib/tinybucket/config.rb +10 -0
- data/lib/tinybucket/connection.rb +84 -0
- data/lib/tinybucket/constants.rb +7 -0
- data/lib/tinybucket/enumerator.rb +47 -0
- data/lib/tinybucket/error.rb +12 -0
- data/lib/tinybucket/error/base_error.rb +14 -0
- data/lib/tinybucket/error/conflict.rb +8 -0
- data/lib/tinybucket/error/not_found.rb +8 -0
- data/lib/tinybucket/error/service_error.rb +26 -0
- data/lib/tinybucket/iterator.rb +79 -0
- data/lib/tinybucket/model.rb +25 -0
- data/lib/tinybucket/model/base.rb +45 -0
- data/lib/tinybucket/model/branch.rb +48 -0
- data/lib/tinybucket/model/branch_restriction.rb +46 -0
- data/lib/tinybucket/model/build_status.rb +57 -0
- data/lib/tinybucket/model/comment.rb +67 -0
- data/lib/tinybucket/model/commit.rb +114 -0
- data/lib/tinybucket/model/concerns.rb +19 -0
- data/lib/tinybucket/model/concerns/acceptable_attributes.rb +34 -0
- data/lib/tinybucket/model/concerns/api_callable.rb +21 -0
- data/lib/tinybucket/model/concerns/enumerable.rb +20 -0
- data/lib/tinybucket/model/concerns/reloadable.rb +41 -0
- data/lib/tinybucket/model/concerns/repository_keys.rb +45 -0
- data/lib/tinybucket/model/error_response.rb +24 -0
- data/lib/tinybucket/model/page.rb +45 -0
- data/lib/tinybucket/model/profile.rb +70 -0
- data/lib/tinybucket/model/project.rb +44 -0
- data/lib/tinybucket/model/pull_request.rb +162 -0
- data/lib/tinybucket/model/repository.rb +219 -0
- data/lib/tinybucket/model/team.rb +96 -0
- data/lib/tinybucket/null_logger.rb +37 -0
- data/lib/tinybucket/parser.rb +15 -0
- data/lib/tinybucket/parser/collection_parser.rb +17 -0
- data/lib/tinybucket/parser/object_parser.rb +17 -0
- data/lib/tinybucket/request.rb +61 -0
- data/lib/tinybucket/resource.rb +75 -0
- data/lib/tinybucket/resource/base.rb +35 -0
- data/lib/tinybucket/resource/branch_restrictions.rb +47 -0
- data/lib/tinybucket/resource/branches.rb +35 -0
- data/lib/tinybucket/resource/commit/base.rb +14 -0
- data/lib/tinybucket/resource/commit/build_statuses.rb +50 -0
- data/lib/tinybucket/resource/commit/comments.rb +34 -0
- data/lib/tinybucket/resource/commits.rb +46 -0
- data/lib/tinybucket/resource/forks.rb +24 -0
- data/lib/tinybucket/resource/projects.rb +49 -0
- data/lib/tinybucket/resource/pull_request/base.rb +20 -0
- data/lib/tinybucket/resource/pull_request/comments.rb +32 -0
- data/lib/tinybucket/resource/pull_request/commits.rb +19 -0
- data/lib/tinybucket/resource/pull_requests.rb +52 -0
- data/lib/tinybucket/resource/repos.rb +40 -0
- data/lib/tinybucket/resource/team/base.rb +24 -0
- data/lib/tinybucket/resource/team/followers.rb +15 -0
- data/lib/tinybucket/resource/team/following.rb +15 -0
- data/lib/tinybucket/resource/team/members.rb +15 -0
- data/lib/tinybucket/resource/team/repos.rb +15 -0
- data/lib/tinybucket/resource/teams.rb +22 -0
- data/lib/tinybucket/resource/user/base.rb +26 -0
- data/lib/tinybucket/resource/user/followers.rb +15 -0
- data/lib/tinybucket/resource/user/following.rb +15 -0
- data/lib/tinybucket/resource/user/repos.rb +15 -0
- data/lib/tinybucket/resource/watchers.rb +24 -0
- data/lib/tinybucket/response.rb +9 -0
- data/lib/tinybucket/response/handler.rb +23 -0
- data/lib/tinybucket/version.rb +5 -0
- data/tinybucket.gemspec +30 -0
- metadata +244 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module ProjectsHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_list(owner)
|
12
|
+
build_path(base_path(owner), '/')
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_to_find(owner, project_key)
|
16
|
+
build_path(base_path(owner),
|
17
|
+
[project_key, 'project_key'])
|
18
|
+
end
|
19
|
+
|
20
|
+
def base_path(owner)
|
21
|
+
build_path('/teams',
|
22
|
+
[owner, 'owner'],
|
23
|
+
'projects')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module PullRequestsHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_list
|
12
|
+
base_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_to_create
|
16
|
+
base_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def path_to_update(pr_id)
|
20
|
+
build_path(base_path,
|
21
|
+
[pr_id, 'pullrequest_id'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def path_to_find(pr_id)
|
25
|
+
build_path(base_path,
|
26
|
+
[pr_id, 'pullrequest_id'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def path_to_commits(pr_id)
|
30
|
+
build_path(base_path,
|
31
|
+
[pr_id, 'pullrequest_id'],
|
32
|
+
'commits')
|
33
|
+
end
|
34
|
+
|
35
|
+
def path_to_approve(pr_id)
|
36
|
+
build_path(base_path,
|
37
|
+
[pr_id, 'pullrequest_id'],
|
38
|
+
'approve')
|
39
|
+
end
|
40
|
+
|
41
|
+
def path_to_diff(pr_id)
|
42
|
+
build_path(path_to_find(pr_id),
|
43
|
+
'diff')
|
44
|
+
end
|
45
|
+
|
46
|
+
def path_to_decline(pr_id)
|
47
|
+
build_path(base_path,
|
48
|
+
[pr_id, 'pullrequest_id'],
|
49
|
+
'decline')
|
50
|
+
end
|
51
|
+
|
52
|
+
def path_to_merge(pr_id)
|
53
|
+
build_path(base_path,
|
54
|
+
[pr_id, 'pullrequest_id'],
|
55
|
+
'merge')
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_path
|
59
|
+
build_path('/repositories',
|
60
|
+
[repo_owner, 'repo_owner'],
|
61
|
+
[repo_slug, 'repo_slug'],
|
62
|
+
'pullrequests')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module RepoHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_find
|
12
|
+
base_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_to_watchers
|
16
|
+
build_path(base_path, '/watchers')
|
17
|
+
end
|
18
|
+
|
19
|
+
def path_to_forks
|
20
|
+
build_path(base_path, '/forks')
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_path
|
24
|
+
build_path('/repositories',
|
25
|
+
[repo_owner, 'repo_owner'],
|
26
|
+
[repo_slug, 'repo_slug'])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module ReposHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_list(options)
|
12
|
+
owner = options[:owner]
|
13
|
+
return base_path if owner.blank?
|
14
|
+
build_path(base_path, [owner, 'owner'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_path
|
18
|
+
'/repositories'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module TeamHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_list
|
12
|
+
base_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_to_find(name)
|
16
|
+
team_path(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def path_to_members(name)
|
20
|
+
build_path(team_path(name), 'members')
|
21
|
+
end
|
22
|
+
|
23
|
+
def path_to_followers(name)
|
24
|
+
build_path(team_path(name), 'followers')
|
25
|
+
end
|
26
|
+
|
27
|
+
def path_to_following(name)
|
28
|
+
build_path(team_path(name), 'following')
|
29
|
+
end
|
30
|
+
|
31
|
+
def path_to_repos(name)
|
32
|
+
build_path(team_path(name), 'repositories')
|
33
|
+
end
|
34
|
+
|
35
|
+
def base_path
|
36
|
+
build_path('/teams')
|
37
|
+
end
|
38
|
+
|
39
|
+
def team_path(name)
|
40
|
+
build_path(base_path, [name, 'teamname'])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
module Helper
|
6
|
+
module UserHelper
|
7
|
+
include ::Tinybucket::Api::Helper::ApiHelper
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def path_to_find
|
12
|
+
base_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def path_to_followers
|
16
|
+
build_path(base_path, 'followers')
|
17
|
+
end
|
18
|
+
|
19
|
+
def path_to_following
|
20
|
+
build_path(base_path, 'following')
|
21
|
+
end
|
22
|
+
|
23
|
+
def path_to_repos
|
24
|
+
build_path('/repositories', [username, 'username'])
|
25
|
+
end
|
26
|
+
|
27
|
+
def base_path
|
28
|
+
build_path('/users', [username, 'username'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
class ProjectsApi < BaseApi
|
6
|
+
include Tinybucket::Api::Helper::ProjectsHelper
|
7
|
+
attr_accessor :owner
|
8
|
+
|
9
|
+
def list(options = {})
|
10
|
+
get_path(
|
11
|
+
path_to_list(owner),
|
12
|
+
options,
|
13
|
+
get_parser(:collection, Tinybucket::Model::Project)
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(project_key, options = {})
|
18
|
+
get_path(
|
19
|
+
path_to_find(owner, project_key),
|
20
|
+
options,
|
21
|
+
get_parser(:object, Tinybucket::Model::Project)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# PullRequests Api client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests
|
8
|
+
# pullrequests Resource
|
9
|
+
#
|
10
|
+
# @!attribute [rw] repo_owner
|
11
|
+
# @return [String] repository owner name.
|
12
|
+
# @!attribute [rw] repo_slug
|
13
|
+
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repository slug}.
|
14
|
+
class PullRequestsApi < BaseApi
|
15
|
+
include Tinybucket::Api::Helper::PullRequestsHelper
|
16
|
+
|
17
|
+
attr_accessor :repo_owner, :repo_slug
|
18
|
+
|
19
|
+
# Send 'GET a list of open pull requests' request
|
20
|
+
#
|
21
|
+
# @param options [Hash]
|
22
|
+
# @return [Tinybucket::Model::Page]
|
23
|
+
def list(options = {})
|
24
|
+
get_path(
|
25
|
+
path_to_list,
|
26
|
+
options,
|
27
|
+
get_parser(:collection, Tinybucket::Model::PullRequest)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Send 'POST a specific pull request' request
|
32
|
+
#
|
33
|
+
# @param attrs [Hash]
|
34
|
+
# @return [true]
|
35
|
+
def create(attrs)
|
36
|
+
post_path(
|
37
|
+
path_to_create,
|
38
|
+
attrs,
|
39
|
+
get_parser(:object, Tinybucket::Model::PullRequest)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send 'PUT a specific pull request' request
|
44
|
+
#
|
45
|
+
# @param pr_id [String] The pull request identifier
|
46
|
+
# @param options [Hash]
|
47
|
+
# @return [true]
|
48
|
+
def update(pr_id, options = {})
|
49
|
+
put_path(path_to_update(pr_id), options)
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
# Send 'GET a specific pull request' request
|
54
|
+
#
|
55
|
+
# @param pr_id [String] The pull request identifier
|
56
|
+
# @param options [Hash]
|
57
|
+
# @return [Tinybucket::Model::PullRequest]
|
58
|
+
def find(pr_id, options = {})
|
59
|
+
get_path(
|
60
|
+
path_to_find(pr_id),
|
61
|
+
options,
|
62
|
+
get_parser(:object, Tinybucket::Model::PullRequest)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Send 'GET the commits for a pull request' request
|
67
|
+
#
|
68
|
+
# @param pr_id [String] The pull request identifier
|
69
|
+
# @param options [Hash]
|
70
|
+
# @return [Tinybucket::Model::PullRequest]
|
71
|
+
def commits(pr_id, options = {})
|
72
|
+
get_path(
|
73
|
+
path_to_commits(pr_id),
|
74
|
+
options,
|
75
|
+
get_parser(:collection, Tinybucket::Model::Commit)
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Send 'POST a pull request approval' request
|
80
|
+
#
|
81
|
+
# @note This method return true if this pull request already approved.
|
82
|
+
#
|
83
|
+
# @param pr_id [String] The pull request identifier
|
84
|
+
# @param options [Hash]
|
85
|
+
# @return [true, false]
|
86
|
+
def approve(pr_id, options = {})
|
87
|
+
result = post_path(path_to_approve(pr_id), options)
|
88
|
+
(result['approved'] == true)
|
89
|
+
rescue Tinybucket::Error::Conflict => e
|
90
|
+
logger.debug 'Already approved: ' + e.inspect
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
# Send 'DELETE a pull request approval' request
|
95
|
+
#
|
96
|
+
# @note This method return true if this pull request is not approved yet.
|
97
|
+
#
|
98
|
+
# @param pr_id [String] The pull request identifier
|
99
|
+
# @param options [Hash]
|
100
|
+
# @return [true]
|
101
|
+
def unapprove(pr_id, options = {})
|
102
|
+
delete_path(path_to_approve(pr_id), options)
|
103
|
+
true
|
104
|
+
rescue Tinybucket::Error::NotFound => e
|
105
|
+
logger.debug 'Already unapproved: ' + e.inspect
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
# Send 'Decline or reject a pull request' request
|
110
|
+
#
|
111
|
+
# @param pr_id [String] The pull request identifier
|
112
|
+
# @param options [Hash]
|
113
|
+
# @return [true, false]
|
114
|
+
def decline(pr_id, options = {})
|
115
|
+
result = post_path(path_to_decline(pr_id), options)
|
116
|
+
(result['state'] == 'DECLINED')
|
117
|
+
end
|
118
|
+
|
119
|
+
# Send 'Accept and merge a pull request' request
|
120
|
+
#
|
121
|
+
# @param pr_id [String] The pull request identifier
|
122
|
+
# @param options [Hash]
|
123
|
+
# @return [true, false]
|
124
|
+
def merge(pr_id, options = {})
|
125
|
+
result = post_path(path_to_merge(pr_id), options)
|
126
|
+
(result['state'] == 'MERGED')
|
127
|
+
end
|
128
|
+
|
129
|
+
# Send 'GET the diff for a pull request' request
|
130
|
+
#
|
131
|
+
# @param pr_id [String] The pull request identifier
|
132
|
+
# @param options [Hash]
|
133
|
+
# @return [String] diff as raw text.
|
134
|
+
def diff(pr_id, options = {})
|
135
|
+
get_path(path_to_diff(pr_id), options)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Repo Api client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories
|
8
|
+
# repository Resource
|
9
|
+
#
|
10
|
+
# @!attribute [rw] repo_owner
|
11
|
+
# @return [String] repository owner name.
|
12
|
+
# @!attribute [rw] repo_slug
|
13
|
+
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repository slug}.
|
14
|
+
class RepoApi < BaseApi
|
15
|
+
include Tinybucket::Api::Helper::RepoHelper
|
16
|
+
|
17
|
+
attr_accessor :repo_owner, :repo_slug
|
18
|
+
|
19
|
+
# Send 'GET a repository' request
|
20
|
+
#
|
21
|
+
# @param options [Hash]
|
22
|
+
# @return [Tinybucket::Model::Repository]
|
23
|
+
def find(options = {})
|
24
|
+
get_path(
|
25
|
+
path_to_find,
|
26
|
+
options,
|
27
|
+
get_parser(:object, Tinybucket::Model::Repository)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Send 'GET a list of watchers' request
|
32
|
+
#
|
33
|
+
# @param options [Hash]
|
34
|
+
# @return [Tinybucket::Model::Page]
|
35
|
+
def watchers(options = {})
|
36
|
+
get_path(
|
37
|
+
path_to_watchers,
|
38
|
+
options,
|
39
|
+
get_parser(:collection, Tinybucket::Model::Profile)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send 'GET a list of forks' request
|
44
|
+
#
|
45
|
+
# @param options [Hash]
|
46
|
+
# @return [Tinybucket::Model::Page]
|
47
|
+
def forks(options = {})
|
48
|
+
get_path(
|
49
|
+
path_to_forks,
|
50
|
+
options,
|
51
|
+
get_parser(:collection, Tinybucket::Model::Repository)
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|