tinybucket2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +86 -0
  3. data/Gemfile +32 -0
  4. data/LICENSE +21 -0
  5. data/README.md +387 -0
  6. data/Rakefile +47 -0
  7. data/lib/faraday_middleware/follow_oauth_redirects.rb +71 -0
  8. data/lib/tinybucket.rb +76 -0
  9. data/lib/tinybucket/api.rb +26 -0
  10. data/lib/tinybucket/api/base_api.rb +44 -0
  11. data/lib/tinybucket/api/branch_restrictions_api.rb +51 -0
  12. data/lib/tinybucket/api/branches_api.rb +48 -0
  13. data/lib/tinybucket/api/build_status_api.rb +69 -0
  14. data/lib/tinybucket/api/comments_api.rb +81 -0
  15. data/lib/tinybucket/api/commits_api.rb +97 -0
  16. data/lib/tinybucket/api/diff_api.rb +40 -0
  17. data/lib/tinybucket/api/helper.rb +27 -0
  18. data/lib/tinybucket/api/helper/api_helper.rb +39 -0
  19. data/lib/tinybucket/api/helper/branch_restrictions_helper.rb +29 -0
  20. data/lib/tinybucket/api/helper/branches_helper.rb +29 -0
  21. data/lib/tinybucket/api/helper/build_status_helper.rb +46 -0
  22. data/lib/tinybucket/api/helper/comments_helper.rb +51 -0
  23. data/lib/tinybucket/api/helper/commits_helper.rb +42 -0
  24. data/lib/tinybucket/api/helper/diff_helper.rb +31 -0
  25. data/lib/tinybucket/api/helper/issues_helper.rb +29 -0
  26. data/lib/tinybucket/api/helper/projects_helper.rb +28 -0
  27. data/lib/tinybucket/api/helper/pull_requests_helper.rb +58 -0
  28. data/lib/tinybucket/api/helper/repo_helper.rb +31 -0
  29. data/lib/tinybucket/api/helper/repos_helper.rb +23 -0
  30. data/lib/tinybucket/api/helper/team_helper.rb +45 -0
  31. data/lib/tinybucket/api/helper/user_helper.rb +33 -0
  32. data/lib/tinybucket/api/issues_api.rb +48 -0
  33. data/lib/tinybucket/api/projects_api.rb +26 -0
  34. data/lib/tinybucket/api/pull_requests_api.rb +117 -0
  35. data/lib/tinybucket/api/repo_api.rb +56 -0
  36. data/lib/tinybucket/api/repos_api.rb +28 -0
  37. data/lib/tinybucket/api/team_api.rb +91 -0
  38. data/lib/tinybucket/api/user_api.rb +66 -0
  39. data/lib/tinybucket/api_factory.rb +21 -0
  40. data/lib/tinybucket/client.rb +107 -0
  41. data/lib/tinybucket/config.rb +10 -0
  42. data/lib/tinybucket/connection.rb +84 -0
  43. data/lib/tinybucket/constants.rb +7 -0
  44. data/lib/tinybucket/enumerator.rb +47 -0
  45. data/lib/tinybucket/error.rb +12 -0
  46. data/lib/tinybucket/error/base_error.rb +14 -0
  47. data/lib/tinybucket/error/conflict.rb +8 -0
  48. data/lib/tinybucket/error/not_found.rb +8 -0
  49. data/lib/tinybucket/error/service_error.rb +26 -0
  50. data/lib/tinybucket/iterator.rb +79 -0
  51. data/lib/tinybucket/model.rb +25 -0
  52. data/lib/tinybucket/model/base.rb +45 -0
  53. data/lib/tinybucket/model/branch.rb +48 -0
  54. data/lib/tinybucket/model/branch_restriction.rb +46 -0
  55. data/lib/tinybucket/model/build_status.rb +57 -0
  56. data/lib/tinybucket/model/comment.rb +67 -0
  57. data/lib/tinybucket/model/commit.rb +114 -0
  58. data/lib/tinybucket/model/concerns.rb +19 -0
  59. data/lib/tinybucket/model/concerns/acceptable_attributes.rb +34 -0
  60. data/lib/tinybucket/model/concerns/api_callable.rb +21 -0
  61. data/lib/tinybucket/model/concerns/enumerable.rb +20 -0
  62. data/lib/tinybucket/model/concerns/reloadable.rb +41 -0
  63. data/lib/tinybucket/model/concerns/repository_keys.rb +45 -0
  64. data/lib/tinybucket/model/error_response.rb +24 -0
  65. data/lib/tinybucket/model/issue.rb +48 -0
  66. data/lib/tinybucket/model/page.rb +45 -0
  67. data/lib/tinybucket/model/profile.rb +70 -0
  68. data/lib/tinybucket/model/project.rb +44 -0
  69. data/lib/tinybucket/model/pull_request.rb +160 -0
  70. data/lib/tinybucket/model/repository.rb +219 -0
  71. data/lib/tinybucket/model/team.rb +96 -0
  72. data/lib/tinybucket/null_logger.rb +37 -0
  73. data/lib/tinybucket/parser.rb +15 -0
  74. data/lib/tinybucket/parser/collection_parser.rb +17 -0
  75. data/lib/tinybucket/parser/object_parser.rb +17 -0
  76. data/lib/tinybucket/request.rb +59 -0
  77. data/lib/tinybucket/resource.rb +75 -0
  78. data/lib/tinybucket/resource/base.rb +35 -0
  79. data/lib/tinybucket/resource/branch_restrictions.rb +47 -0
  80. data/lib/tinybucket/resource/branches.rb +35 -0
  81. data/lib/tinybucket/resource/commit/base.rb +14 -0
  82. data/lib/tinybucket/resource/commit/build_statuses.rb +50 -0
  83. data/lib/tinybucket/resource/commit/comments.rb +34 -0
  84. data/lib/tinybucket/resource/commits.rb +46 -0
  85. data/lib/tinybucket/resource/forks.rb +24 -0
  86. data/lib/tinybucket/resource/issues.rb +35 -0
  87. data/lib/tinybucket/resource/projects.rb +49 -0
  88. data/lib/tinybucket/resource/pull_request/base.rb +20 -0
  89. data/lib/tinybucket/resource/pull_request/comments.rb +32 -0
  90. data/lib/tinybucket/resource/pull_request/commits.rb +19 -0
  91. data/lib/tinybucket/resource/pull_requests.rb +50 -0
  92. data/lib/tinybucket/resource/repos.rb +40 -0
  93. data/lib/tinybucket/resource/team/base.rb +24 -0
  94. data/lib/tinybucket/resource/team/followers.rb +15 -0
  95. data/lib/tinybucket/resource/team/following.rb +15 -0
  96. data/lib/tinybucket/resource/team/members.rb +15 -0
  97. data/lib/tinybucket/resource/team/repos.rb +15 -0
  98. data/lib/tinybucket/resource/teams.rb +22 -0
  99. data/lib/tinybucket/resource/user/base.rb +26 -0
  100. data/lib/tinybucket/resource/user/followers.rb +15 -0
  101. data/lib/tinybucket/resource/user/following.rb +15 -0
  102. data/lib/tinybucket/resource/user/repos.rb +15 -0
  103. data/lib/tinybucket/resource/watchers.rb +24 -0
  104. data/lib/tinybucket/response.rb +9 -0
  105. data/lib/tinybucket/response/handler.rb +23 -0
  106. data/lib/tinybucket/version.rb +5 -0
  107. data/tinybucket.gemspec +30 -0
  108. metadata +248 -0
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tinybucket
4
+ module Model
5
+ class Project < Base
6
+ acceptable_attributes \
7
+ :type, :description, :links, :uuid, :created_on,
8
+ :key, :updated_on, :is_private, :name, :owner
9
+
10
+ # Update this project
11
+ #
12
+ # @param _params [Hash]
13
+ # @raise [NotImplementedError] to be implemented
14
+ def update(_params)
15
+ raise NotImplementedError
16
+ end
17
+
18
+ # Destroy this project
19
+ #
20
+ # @raise [NotImplementedError] to be implemented.
21
+ def destroy
22
+ raise NotImplementedError
23
+ end
24
+
25
+ # Get repositories
26
+ #
27
+ # @return [Tinybucket::Resource::Repos]
28
+ def repos
29
+ repos_resource
30
+ end
31
+
32
+ private
33
+
34
+ def owner_name
35
+ raise 'This project is not loaded yet.' if (owner.nil? || owner['username'].nil?)
36
+ owner['username']
37
+ end
38
+
39
+ def repos_resource
40
+ Tinybucket::Resource::Repos.new(owner_name, q: %(project.key="#{key}"))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tinybucket
4
+ module Model
5
+ # PullRequest
6
+ #
7
+ # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests
8
+ # pullrequest Resource
9
+ #
10
+ # @!attribute [rw] state
11
+ # @return [String]
12
+ # @!attribute [rw] description
13
+ # @return [String]
14
+ # @!attribute [rw] links
15
+ # @return [Hash]
16
+ # @!attribute [rw] title
17
+ # @return [String]
18
+ # @!attribute [rw] task_count
19
+ # @return [Fixnum]
20
+ # @!attribute [rw] comment_count
21
+ # @return [Fixnum]
22
+ # @!attribute [rw] close_source_branch
23
+ # @return [true, false]
24
+ # @!attribute [rw] destination
25
+ # @return [Hash]
26
+ # @!attribute [rw] reason
27
+ # @return [String]
28
+ # @!attribute [rw] id
29
+ # @return [Fixnum]
30
+ # @!attribute [rw] source
31
+ # @return [Hash]
32
+ # @!attribute [rw] created_on
33
+ # @return [String]
34
+ # @!attribute [rw] author
35
+ # @return [Hash]
36
+ # @!attribute [rw] updated_on
37
+ # @return [String]
38
+ # @!attribute [rw] merge_commit
39
+ # @return [Hash]
40
+ # @!attribute [rw] closed_by
41
+ # @return [Hash]
42
+ # @!attribute [rw] reviewers
43
+ # @return [Array]
44
+ # @!attribute [rw] participants
45
+ # @return [Array]
46
+ # @!attribute [rw] uuid
47
+ # @return [NillClass]
48
+ # @!attribute [rw] type
49
+ # @return [String]
50
+ class PullRequest < Base
51
+ include Tinybucket::Model::Concerns::RepositoryKeys
52
+ include Tinybucket::Constants
53
+
54
+ acceptable_attributes \
55
+ :state, :description, :links, :title, :task_count, :comment_count,
56
+ :close_source_branch, :destination, :reason, :id, :source,
57
+ :created_on, :author, :updated_on, :merge_commit, :closed_by,
58
+ :reviewers, :participants, :uuid, :type
59
+
60
+ # Update this pull request.
61
+ #
62
+ # @todo to be implemented.
63
+ # @raise [NotImplementedError] to be implemented.
64
+ def update(_params)
65
+ raise NotImplementedError
66
+ end
67
+
68
+ # Decline or reject this pull request.
69
+ #
70
+ # @param options [Hash]
71
+ # @return [true,false]
72
+ def decline(options = {})
73
+ pull_request_api.decline(id, options)
74
+ end
75
+
76
+ # Give approval on this pull request.
77
+ #
78
+ # @param options [Hash]
79
+ # @return [true, false]
80
+ def approve(options = {})
81
+ pull_request_api.approve(id, options)
82
+ end
83
+
84
+ # Revoke approval on this pull request.
85
+ #
86
+ # @param options [Hash]
87
+ # @return [true, false]
88
+ def unapprove(options = {})
89
+ pull_request_api.unapprove(id, options)
90
+ end
91
+
92
+ # Get commits associated with this pull request.
93
+ #
94
+ # @param options [Hash]
95
+ # @return [Tinybucket::Resource::PullRequest::Commits]
96
+ def commits(options = {})
97
+ commits_resource(options)
98
+ end
99
+
100
+ # Get comments on this pull request.
101
+ #
102
+ # @param options [Hash]
103
+ # @return [Tinybucket::Resource::PullRequest::Comments]
104
+ def comments(options = {})
105
+ comments_resource(options)
106
+ end
107
+
108
+ # Get the specific comment on this pull request.
109
+ #
110
+ # @param comment_id [String]
111
+ # @param options [Hash]
112
+ # @return [Tinybucket::Model::Comment]
113
+ def comment(comment_id, options = {})
114
+ comments_resource.find(comment_id, options)
115
+ end
116
+
117
+ # Get the diff for this pull request.
118
+ #
119
+ # @param options [Hash]
120
+ # @return [String] diff as raw text.
121
+ def diff(options = {})
122
+ pull_request_api.diff(id, options)
123
+ end
124
+
125
+ # Accept and merge this pull request.
126
+ #
127
+ # @param options [Hash]
128
+ # @return [true, false]
129
+ def merge(options = {})
130
+ pull_request_api.merge(id, options)
131
+ end
132
+
133
+ # Get activities on this pull requests.
134
+ #
135
+ def activities(_options = {})
136
+ raise NotImplementedError
137
+ end
138
+
139
+ private
140
+
141
+ def commits_resource(options = {})
142
+ Tinybucket::Resource::PullRequest::Commits.new(self, options)
143
+ end
144
+
145
+ def comments_resource(options = {})
146
+ Tinybucket::Resource::PullRequest::Comments.new(self, options)
147
+ end
148
+
149
+ def pull_request_api
150
+ raise ArgumentError, MISSING_REPOSITORY_KEY unless repo_keys?
151
+
152
+ create_api('PullRequests', repo_keys)
153
+ end
154
+
155
+ def load_model
156
+ pull_request_api.find(id)
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,219 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tinybucket
4
+ module Model
5
+ # Repository
6
+ #
7
+ # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories
8
+ # Repository Endpoint
9
+ #
10
+ # @!attribute [rw] scm
11
+ # @return [String]
12
+ # @!attribute [rw] has_wiki
13
+ # @return [true, false]
14
+ # @!attribute [rw] description
15
+ # @return [String]
16
+ # @!attribute [rw] links
17
+ # @return [Hash]
18
+ # @!attribute [rw] updated_on
19
+ # @return [String]
20
+ # @!attribute [rw] fork_policy
21
+ # @return [String]
22
+ # @!attribute [rw] created_on
23
+ # @return [String]
24
+ # @!attribute [rw] owner
25
+ # @return [Hash]
26
+ # @!attribute [rw] size
27
+ # @return [Fixnum]
28
+ # @!attribute [rw] parent
29
+ # @return [Hash, NillClass]
30
+ # @!attribute [rw] uuid
31
+ # @return [String]
32
+ # @!attribute [rw] has_issues
33
+ # @return [true, false]
34
+ # @!attribute [rw] is_private
35
+ # @return [true, false]
36
+ # @!attribute [rw] full_name
37
+ # @return [String]
38
+ # @!attribute [rw] name
39
+ # @return [String]
40
+ # @!attribute [rw] language
41
+ # @return [String]
42
+ # @!attribute [rw] website
43
+ # @return [String]
44
+ # @!attribute [rw] type
45
+ # @return [String]
46
+ # @!attribute [rw] project
47
+ # @return [Hash]
48
+ class Repository < Base
49
+ include Tinybucket::Model::Concerns::RepositoryKeys
50
+
51
+ acceptable_attributes \
52
+ :scm, :has_wiki, :description, :links, :updated_on,
53
+ :fork_policy, :created_on, :owner, :size, :parent, :uuid,
54
+ :has_issues, :is_private, :full_name, :name, :language,
55
+ :website, :type, :project
56
+
57
+ def initialize(json)
58
+ super(json)
59
+
60
+ return unless full_name && full_name.split('/').size == 2
61
+ @repo_owner, @repo_slug = full_name.split('/')
62
+ end
63
+
64
+ # Remove this repository
65
+ #
66
+ # @todo to be implemented.
67
+ # @raise [NotImplementedError] to be implemented.
68
+ def destroy
69
+ raise NotImplementedError
70
+ end
71
+
72
+ # Get pull requests on thie repository.
73
+ #
74
+ # @param options [Hash]
75
+ # @return [Tinybucket::Enumerator] an enumerator to enumerate
76
+ # pull requests as {Tinybucket::Model::PullRequest} instance.
77
+ def pull_requests(options = {})
78
+ pull_requests_resource(options)
79
+ end
80
+
81
+ # Get the specific pull request on this repository.
82
+ #
83
+ # @param pullrequest_id [String]
84
+ # @param options [Hash]
85
+ # @return [Tinybucket::Model::PullRequest]
86
+ def pull_request(pullrequest_id, options = {})
87
+ pull_requests_resource.find(pullrequest_id, options)
88
+ end
89
+
90
+ # Get watchers on this repository.
91
+ #
92
+ # @param options [Hash]
93
+ # @return [Tinybucket::Resource::Watchers]
94
+ def watchers(options = {})
95
+ watchers_resource(options)
96
+ end
97
+
98
+ # Get repository forks.
99
+ #
100
+ # @param options [Hash]
101
+ # @return [Tinybucket::Resource::Forks]
102
+ def forks(options = {})
103
+ forks_resource(options)
104
+ end
105
+
106
+ # Get commits on this repository.
107
+ #
108
+ # @param options [Hash]
109
+ # @return [Tinybucket::Resource::Commits]
110
+ def commits(options = {})
111
+ commits_resource(options)
112
+ end
113
+
114
+ # Get the specific commit on this repository.
115
+ #
116
+ # @param revision [String]
117
+ # @param options [Hash]
118
+ # @return [Tinybucket::Model::Commit]
119
+ def commit(revision, options = {})
120
+ commits_resource.find(revision, options)
121
+ end
122
+
123
+ # Get branches on this repository
124
+ #
125
+ # @param options [Hash]
126
+ # @return [Tinybucket::Resource::Branches]
127
+ def branches(options = {})
128
+ branches_resource(options)
129
+ end
130
+
131
+ # Get the specific branch on this repository.
132
+ #
133
+ # @param branch [String]
134
+ # @param options [Hash]
135
+ # @return [Tinybucket::Model::Branches]
136
+ def branch(branch, options = {})
137
+ branches_resource.find(branch, options)
138
+ end
139
+
140
+ # Get the branch restriction information associated with this repository.
141
+ #
142
+ # @param options [Hash]
143
+ # @return [Tinybucket::Resource::BranchRestrictions]
144
+ def branch_restrictions(options = {})
145
+ branch_restrictions_resource(options)
146
+ end
147
+
148
+ # Get the specific branch restriction information on this repository.
149
+ #
150
+ # @param restriction_id [String]
151
+ # @param options [Hash]
152
+ # @return [Tinybucket::Model::BranchRestriction]
153
+ def branch_restriction(restriction_id, options = {})
154
+ branch_restrictions_resource.find(restriction_id, options)
155
+ end
156
+
157
+ # Get the diff for this repository.
158
+ #
159
+ # @param spec [String] A specification such as a branch name,
160
+ # revision, or commit SHA.
161
+ # @param options [Hash]
162
+ # @return [String] diff as raw text.
163
+ def diff(spec, options = {})
164
+ diff_api.find(spec, options)
165
+ end
166
+
167
+ # Get the patch for the specification.
168
+ #
169
+ # @param spec [String] A specification such as a branch name,
170
+ # revision, or commit SHA.
171
+ # @return [String] patch as raw text.
172
+ def patch(spec, options = {})
173
+ diff_api.find_patch(spec, options)
174
+ end
175
+
176
+ private
177
+
178
+ def branch_restrictions_resource(options = {})
179
+ Tinybucket::Resource::BranchRestrictions.new(self, options)
180
+ end
181
+
182
+ def branches_resource(options = {})
183
+ Tinybucket::Resource::Branches.new(self, options)
184
+ end
185
+
186
+ def commits_resource(options = {})
187
+ Tinybucket::Resource::Commits.new(self, options)
188
+ end
189
+
190
+ def hooks_resource(options = {})
191
+ Tinybucket::Resource::Hooks.new(self, options)
192
+ end
193
+
194
+ def pull_requests_resource(options = {})
195
+ Tinybucket::Resource::PullRequests.new(self, options)
196
+ end
197
+
198
+ def watchers_resource(options = {})
199
+ Tinybucket::Resource::Watchers.new(self, options)
200
+ end
201
+
202
+ def forks_resource(options = {})
203
+ Tinybucket::Resource::Forks.new(self, options)
204
+ end
205
+
206
+ def repo_api
207
+ create_api('Repo', repo_keys)
208
+ end
209
+
210
+ def diff_api
211
+ create_api('Diff', repo_keys)
212
+ end
213
+
214
+ def load_model
215
+ repo_api.find()
216
+ end
217
+ end
218
+ end
219
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tinybucket
4
+ module Model
5
+ # Team
6
+ #
7
+ # @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams
8
+ # teams Endpoint
9
+ #
10
+ # @!attribute [rw] username
11
+ # @return [String]
12
+ # @!attribute [rw] kind
13
+ # @return [String, NillClass]
14
+ # @!attribute [rw] website
15
+ # @return [String, NillClass]
16
+ # @!attribute [rw] display_name
17
+ # @return [String]
18
+ # @!attribute [rw] uuid
19
+ # @return [String]
20
+ # @!attribute [rw] links
21
+ # @return [Hash]
22
+ # @!attribute [rw] created_on
23
+ # @return [String]
24
+ # @!attribute [rw] location
25
+ # @return [String, NillClass]
26
+ # @!attribute [rw] type
27
+ # @return [String]
28
+ class Team < Base
29
+ acceptable_attributes \
30
+ :username, :kind, :website, :display_name, :uuid,
31
+ :links, :created_on, :location, :type
32
+
33
+ # Get this team's members.
34
+ #
35
+ # @param options [Hash]
36
+ # @return [Tinybucket::Resource::Team::Members]
37
+ def members(options = {})
38
+ Tinybucket::Resource::Team::Members.new(username, options)
39
+ end
40
+
41
+ # Get this team's followers.
42
+ #
43
+ # @param options [Hash]
44
+ # @return [Tinybucket::Resource::Team::Followers]
45
+ def followers(options = {})
46
+ Tinybucket::Resource::Team::Followers.new(username, options)
47
+ end
48
+
49
+ # Get users which this team is following.
50
+ #
51
+ # @param options [Hash]
52
+ # @return [Tinybucket::Resource::Team::Following]
53
+ def following(options = {})
54
+ Tinybucket::Resource::Team::Following.new(username, options)
55
+ end
56
+
57
+ # Get projects
58
+ #
59
+ # @param options [Hash]
60
+ # @return [Tinybucket::Resource::Team::Project]
61
+ def projects(options = {})
62
+ projects_resource(options)
63
+ end
64
+
65
+ # Get the project
66
+ #
67
+ # @param project_key [String]
68
+ # @return [Tinybucket::Model::Project]
69
+ def project(project_key, options = {})
70
+ projects_resource().find(project_key, options)
71
+ end
72
+
73
+ # Get this team's repositories.
74
+ #
75
+ # @param options [Hash]
76
+ # @return [Tinybucket::Resource::Team::Repos]
77
+ def repos(options = {})
78
+ Tinybucket::Resource::Team::Repos.new(username, options)
79
+ end
80
+
81
+ private
82
+
83
+ def projects_resource(options = {})
84
+ Tinybucket::Resource::Projects.new(username, options)
85
+ end
86
+
87
+ def team_api
88
+ create_api('Team')
89
+ end
90
+
91
+ def load_model
92
+ team_api.find(username)
93
+ end
94
+ end
95
+ end
96
+ end