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
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
|
6
|
+
desc 'cleanup rcov, doc directories'
|
7
|
+
task :clean do
|
8
|
+
rm_rf 'coverage'
|
9
|
+
rm_rf 'doc'
|
10
|
+
rm_rf 'measurement'
|
11
|
+
end
|
12
|
+
|
13
|
+
# https://github.com/sferik/twitter/blob/master/Rakefile
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
task :test => :spec
|
17
|
+
|
18
|
+
if Dir.exist?('./features')
|
19
|
+
RSpec::Core::RakeTask.new(:features) do |t|
|
20
|
+
t.pattern = './features/**/*_spec.rb'
|
21
|
+
t.rspec_opts = '-I ./features'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'rubocop/rake_task'
|
27
|
+
RuboCop::RakeTask.new
|
28
|
+
rescue LoadError
|
29
|
+
task :rubocop do
|
30
|
+
$stderr.puts 'Rubocop is disabled.'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'yard'
|
35
|
+
YARD::Rake::YardocTask.new
|
36
|
+
|
37
|
+
require 'yardstick/rake/measurement'
|
38
|
+
Yardstick::Rake::Measurement.new do |measurement|
|
39
|
+
measurement.output = 'measurement/report.txt'
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'yardstick/rake/verify'
|
43
|
+
Yardstick::Rake::Verify.new do |verify|
|
44
|
+
verify.threshold = 59.6
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => [:spec, :rubocop]
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
module FaradayMiddleware
|
7
|
+
class FollowOAuthRedirects < FollowRedirects
|
8
|
+
dependency 'simple_oauth'
|
9
|
+
|
10
|
+
AUTH_HEADER = OAuth::AUTH_HEADER
|
11
|
+
CONTENT_TYPE = OAuth::CONTENT_TYPE
|
12
|
+
TYPE_URLENCODED = OAuth::TYPE_URLENCODED
|
13
|
+
|
14
|
+
def update_env(env, request_body, response)
|
15
|
+
env = super(env, request_body, response)
|
16
|
+
|
17
|
+
# update Authentication Header
|
18
|
+
if oauth_signed_request?(env)
|
19
|
+
env[:request_headers][OAuth::AUTH_HEADER] = oauth_header(env).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
env
|
23
|
+
end
|
24
|
+
|
25
|
+
def oauth_header(env)
|
26
|
+
SimpleOAuth::Header.new env[:method],
|
27
|
+
env[:url].to_s,
|
28
|
+
signature_params(body_params(env)),
|
29
|
+
oauth_options(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
def oauth_signed_request?(env)
|
33
|
+
env[:request].oauth
|
34
|
+
end
|
35
|
+
|
36
|
+
def oauth_options(env)
|
37
|
+
extra = env[:request][:oauth]
|
38
|
+
if extra.present? and extra.is_a? Hash and !extra.empty?
|
39
|
+
@options.merge extra
|
40
|
+
else
|
41
|
+
@options
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def body_params(env)
|
46
|
+
if include_body_params?(env)
|
47
|
+
if env[:body].respond_to?(:to_str)
|
48
|
+
::Faraday::Utils.parse_nested_query env[:body]
|
49
|
+
else
|
50
|
+
env[:body]
|
51
|
+
end
|
52
|
+
end || {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def include_body_params?(env)
|
56
|
+
# see RFC 5849, section 3.4.1.3.1 for details
|
57
|
+
!(type = env[:request_headers][OAuth::CONTENT_TYPE]) ||
|
58
|
+
type == OAuth::TYPE_URLENCODED
|
59
|
+
end
|
60
|
+
|
61
|
+
def signature_params(params)
|
62
|
+
return params if params.empty?
|
63
|
+
params.reject { |_k, v| v.respond_to?(:content_type) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if Faraday::Middleware.respond_to? :register_middleware
|
68
|
+
Faraday::Response.register_middleware \
|
69
|
+
follow_oauth_redirects: -> { FollowOAuthRedirects }
|
70
|
+
end
|
71
|
+
end
|
data/lib/tinybucket.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tinybucket/version'
|
4
|
+
|
5
|
+
require 'active_support/dependencies/autoload'
|
6
|
+
|
7
|
+
require 'active_support/core_ext/hash'
|
8
|
+
require 'active_support/configurable'
|
9
|
+
require 'active_support/inflector'
|
10
|
+
|
11
|
+
require 'faraday'
|
12
|
+
require 'faraday_middleware'
|
13
|
+
require 'faraday_middleware/response_middleware'
|
14
|
+
require 'faraday_middleware/follow_oauth_redirects'
|
15
|
+
require 'faraday-http-cache'
|
16
|
+
|
17
|
+
require 'active_model'
|
18
|
+
|
19
|
+
require 'logger'
|
20
|
+
require 'uri'
|
21
|
+
|
22
|
+
require 'tinybucket/enumerator'
|
23
|
+
require 'tinybucket/iterator'
|
24
|
+
|
25
|
+
require 'tinybucket/config'
|
26
|
+
require 'tinybucket/null_logger'
|
27
|
+
require 'tinybucket/api'
|
28
|
+
require 'tinybucket/api_factory'
|
29
|
+
require 'tinybucket/api/helper'
|
30
|
+
require 'tinybucket/connection'
|
31
|
+
require 'tinybucket/constants'
|
32
|
+
require 'tinybucket/error'
|
33
|
+
require 'tinybucket/model/concerns'
|
34
|
+
require 'tinybucket/model'
|
35
|
+
require 'tinybucket/parser'
|
36
|
+
require 'tinybucket/request'
|
37
|
+
require 'tinybucket/resource'
|
38
|
+
require 'tinybucket/response'
|
39
|
+
|
40
|
+
require 'tinybucket/client'
|
41
|
+
|
42
|
+
require 'active_support/notifications'
|
43
|
+
ActiveSupport::Notifications.subscribe('request.faraday') \
|
44
|
+
do |_name, start_time, end_time, _, env|
|
45
|
+
url = env[:url]
|
46
|
+
http_method = env[:method].to_s.upcase
|
47
|
+
duration = end_time - start_time
|
48
|
+
Tinybucket.logger.debug \
|
49
|
+
format(
|
50
|
+
'[%s] %s %s (%.3f s)',
|
51
|
+
url.host, http_method, url.request_uri, duration
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
module Tinybucket
|
56
|
+
class << self
|
57
|
+
include ActiveSupport::Configurable
|
58
|
+
attr_accessor :logger, :api_client
|
59
|
+
|
60
|
+
def new
|
61
|
+
@api_client = Tinybucket::Client.new
|
62
|
+
end
|
63
|
+
|
64
|
+
def configure
|
65
|
+
yield(config)
|
66
|
+
end
|
67
|
+
|
68
|
+
def config
|
69
|
+
@config ||= Tinybucket::Config.new
|
70
|
+
end
|
71
|
+
|
72
|
+
def logger
|
73
|
+
config.logger || Tinybucket::NullLogger.new
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
[
|
8
|
+
:BaseApi,
|
9
|
+
:BranchesApi,
|
10
|
+
:BranchRestrictionsApi,
|
11
|
+
:BuildStatusApi,
|
12
|
+
:CommitsApi,
|
13
|
+
:CommentsApi,
|
14
|
+
:DiffApi,
|
15
|
+
:ProjectsApi,
|
16
|
+
:PullRequestsApi,
|
17
|
+
:ReposApi,
|
18
|
+
:RepoApi,
|
19
|
+
:TeamApi,
|
20
|
+
:UserApi
|
21
|
+
].each do |klass_name|
|
22
|
+
autoload klass_name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
class Parser
|
6
|
+
attr_reader :type, :options
|
7
|
+
|
8
|
+
def initialize(type, model_class)
|
9
|
+
parser_class =
|
10
|
+
case type
|
11
|
+
when :collection then Tinybucket::Parser::CollectionParser
|
12
|
+
when :object then Tinybucket::Parser::ObjectParser
|
13
|
+
else throw "Unknown parser type: #{type}"
|
14
|
+
end
|
15
|
+
|
16
|
+
@type = parser_class
|
17
|
+
@options = { model_class: model_class }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class BaseApi
|
22
|
+
include Tinybucket::Connection
|
23
|
+
include Tinybucket::Request
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
#
|
28
|
+
# Get parser
|
29
|
+
#
|
30
|
+
# @param type [Symbol] :collection or :object
|
31
|
+
# @param model_class [Tinybucket::Model::Base] SubClass of Tinybucket::Model::Base
|
32
|
+
# @return [Hash]
|
33
|
+
def get_parser(type, model_class)
|
34
|
+
Tinybucket::Api::Parser.new(type, model_class)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def logger
|
40
|
+
Tinybucket.logger
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# BranchRestrictions API client
|
6
|
+
#
|
7
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions
|
8
|
+
# branch-restrictions 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 BranchRestrictionsApi < BaseApi
|
15
|
+
include Tinybucket::Api::Helper::BranchRestrictionsHelper
|
16
|
+
|
17
|
+
attr_accessor :repo_owner, :repo_slug
|
18
|
+
|
19
|
+
# Send 'GET the branch-restrictions' request.
|
20
|
+
#
|
21
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions#get
|
22
|
+
# GET the branch-restrictions
|
23
|
+
#
|
24
|
+
# @param options [Hash]
|
25
|
+
# @return [Tinybucket::Model::Page]
|
26
|
+
def list(options = {})
|
27
|
+
get_path(
|
28
|
+
path_to_list,
|
29
|
+
options,
|
30
|
+
get_parser(:collection, Tinybucket::Model::BranchRestriction)
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Send 'GET a specific restriction' request.
|
35
|
+
#
|
36
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions/%7Bid%7D#get
|
37
|
+
# GET a specific restriction
|
38
|
+
#
|
39
|
+
# @param restriction_id [String] The restriction's identifier
|
40
|
+
# @param options [Hash]
|
41
|
+
# @return [Tinybucket::Model::BranchRestriction]
|
42
|
+
def find(restriction_id, options = {})
|
43
|
+
get_path(
|
44
|
+
path_to_find(restriction_id),
|
45
|
+
options,
|
46
|
+
get_parser(:object, Tinybucket::Model::BranchRestriction)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Branches Api client
|
6
|
+
#
|
7
|
+
# @!attribute [rw] repo_owner
|
8
|
+
# @return [String] repository owner name.
|
9
|
+
# @!attribute [rw] repo_slug
|
10
|
+
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repo_slug}.
|
11
|
+
class BranchesApi < BaseApi
|
12
|
+
include Tinybucket::Api::Helper::BranchesHelper
|
13
|
+
|
14
|
+
attr_accessor :repo_owner, :repo_slug
|
15
|
+
|
16
|
+
# Send 'GET a branches list for a repository' request
|
17
|
+
#
|
18
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/branches#get
|
19
|
+
# GET a branches list for a repository
|
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::Branch)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Send 'GET an individual branch' request
|
32
|
+
#
|
33
|
+
# @see https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/refs/branches/%7Bname%7D#get
|
34
|
+
# GET an individual branch
|
35
|
+
#
|
36
|
+
# @param name [String] The branch name
|
37
|
+
# @param options [Hash]
|
38
|
+
# @return [Tinybucket::Model::Branch]
|
39
|
+
def find(name, options = {})
|
40
|
+
get_path(
|
41
|
+
path_to_find(name),
|
42
|
+
options,
|
43
|
+
get_parser(:object, Tinybucket::Model::Branch)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# BuildStatus Api client
|
6
|
+
#
|
7
|
+
# @see https://confluence.atlassian.com/bitbucket/statuses-build-resource-779295267.html
|
8
|
+
# statuses/build Resource - Bitbucket Cloud REST API
|
9
|
+
class BuildStatusApi < BaseApi
|
10
|
+
include Tinybucket::Api::Helper::BuildStatusHelper
|
11
|
+
|
12
|
+
attr_accessor :revision, :repo_owner, :repo_slug
|
13
|
+
|
14
|
+
# Send 'GET a builds list for a commit' request
|
15
|
+
#
|
16
|
+
# @param options [Hash]
|
17
|
+
# @return [Tinybucket::Model::Page]
|
18
|
+
def list(options = {})
|
19
|
+
get_path(
|
20
|
+
path_to_list,
|
21
|
+
options,
|
22
|
+
get_parser(:collection, Tinybucket::Model::BuildStatus)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Send 'GET the build status for a commit' request
|
27
|
+
#
|
28
|
+
# @param revision [String]
|
29
|
+
# @param key [String]
|
30
|
+
# @param options [Hash]
|
31
|
+
# @return [Tinybucket::Model::BuildStatus]
|
32
|
+
def find(revision, key, options = {})
|
33
|
+
get_path(
|
34
|
+
path_to_find(revision, key),
|
35
|
+
options,
|
36
|
+
get_parser(:object, Tinybucket::Model::BuildStatus)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Send 'POST a build status for a commit' request
|
41
|
+
#
|
42
|
+
# @param revision [String]
|
43
|
+
# @param key [String]
|
44
|
+
# @param options [Hash]
|
45
|
+
# @return [Tinybucket::Model::BuildStatus]
|
46
|
+
def post(revision, key, options)
|
47
|
+
post_path(
|
48
|
+
path_to_post(revision),
|
49
|
+
options.merge(key: key),
|
50
|
+
get_parser(:object, Tinybucket::Model::BuildStatus)
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Send 'PUT a build status for a commit' request
|
55
|
+
#
|
56
|
+
# @param revision [String]
|
57
|
+
# @param key [String]
|
58
|
+
# @param options [Hash]
|
59
|
+
# @return [Tinybucket::Model::BuildStatus]
|
60
|
+
def put(revision, key, options)
|
61
|
+
put_path(
|
62
|
+
path_to_put(revision, key),
|
63
|
+
options,
|
64
|
+
get_parser(:object, Tinybucket::Model::BuildStatus)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tinybucket
|
4
|
+
module Api
|
5
|
+
# Comments Api client
|
6
|
+
#
|
7
|
+
# @!attribute [rw] repo_owner
|
8
|
+
# @return [String] repository owner name.
|
9
|
+
# @!attribute [rw] repo_slug
|
10
|
+
# @return [String] {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D repository slug}.
|
11
|
+
# @!attribute [rw] commented_to
|
12
|
+
# @return [Tinybucket::Model::Commit, Tinybucket::Model::PullRequest]
|
13
|
+
class CommentsApi < BaseApi
|
14
|
+
include Tinybucket::Api::Helper::CommentsHelper
|
15
|
+
|
16
|
+
attr_accessor :repo_owner, :repo_slug
|
17
|
+
|
18
|
+
attr_accessor :commented_to
|
19
|
+
|
20
|
+
# Send 'GET a list of comments' request.
|
21
|
+
#
|
22
|
+
# This method send different request depend on 'commented_to' attribute.
|
23
|
+
#
|
24
|
+
# @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
|
25
|
+
# this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
|
26
|
+
# GET a list of commit comments}.
|
27
|
+
# @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
|
28
|
+
# this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments#get
|
29
|
+
# GET a list of pull request comments}.
|
30
|
+
#
|
31
|
+
# @param options [Hash]
|
32
|
+
# @return [Tinybucket::Model::Page]
|
33
|
+
def list(options = {})
|
34
|
+
list = get_path(path_to_list,
|
35
|
+
options,
|
36
|
+
get_parser(:collection, Tinybucket::Model::Comment))
|
37
|
+
|
38
|
+
associate_with_target(list)
|
39
|
+
list
|
40
|
+
end
|
41
|
+
|
42
|
+
# Send 'GET a individual comment' request.
|
43
|
+
#
|
44
|
+
# This method send different request depend on 'commented_to' attribute.
|
45
|
+
#
|
46
|
+
# @note When 'commented_to' is {Tinybucket::Model::Commit} instance,
|
47
|
+
# this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
|
48
|
+
# GET an individual commit comment}.
|
49
|
+
# @note When 'commented_to' is {Tinybucket::Model::PullRequest} instance,
|
50
|
+
# this method send {https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bsha%7D/comments/%7Bcomment_id%7D#get
|
51
|
+
# GET an individual pull request comment}.
|
52
|
+
#
|
53
|
+
# @param comment_id [String] comment identifier
|
54
|
+
# @param options [Hash]
|
55
|
+
# @return [Tinybucket::Model::Comment]
|
56
|
+
def find(comment_id, options = {})
|
57
|
+
comment = get_path(path_to_find(comment_id),
|
58
|
+
options,
|
59
|
+
get_parser(:object, Tinybucket::Model::Comment))
|
60
|
+
|
61
|
+
associate_with_target(comment)
|
62
|
+
comment
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def associate_with_target(result)
|
68
|
+
case result
|
69
|
+
when Tinybucket::Model::Comment
|
70
|
+
result.commented_to = commented_to
|
71
|
+
when Tinybucket::Model::Page
|
72
|
+
result.items.map { |m| m.commented_to = commented_to }
|
73
|
+
else
|
74
|
+
raise ArgumentError, "Invalid result: #{result.inspect}"
|
75
|
+
end
|
76
|
+
|
77
|
+
result
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|