2016-08-22 14:42:26 -04:00
|
|
|
module Bitbucket
|
|
|
|
class Client
|
2016-12-15 07:19:28 -05:00
|
|
|
attr_reader :connection
|
|
|
|
|
2016-08-22 14:42:26 -04:00
|
|
|
def initialize(options = {})
|
2016-11-20 00:44:19 -05:00
|
|
|
@connection = Connection.new(options)
|
2016-08-22 14:42:26 -04:00
|
|
|
end
|
|
|
|
|
2016-08-22 15:09:25 -04:00
|
|
|
def issues(repo)
|
2016-12-07 04:33:32 -05:00
|
|
|
path = "/repositories/#{repo}/issues"
|
2016-12-07 08:54:32 -05:00
|
|
|
get_collection(path, :issue)
|
2016-08-22 15:09:25 -04:00
|
|
|
end
|
|
|
|
|
2016-12-07 04:33:32 -05:00
|
|
|
def issue_comments(repo, issue_id)
|
|
|
|
path = "/repositories/#{repo}/issues/#{issue_id}/comments"
|
2016-12-07 08:54:32 -05:00
|
|
|
get_collection(path, :comment)
|
2016-08-22 15:10:29 -04:00
|
|
|
end
|
|
|
|
|
2016-08-22 15:15:15 -04:00
|
|
|
def pull_requests(repo)
|
2016-12-07 04:33:32 -05:00
|
|
|
path = "/repositories/#{repo}/pullrequests?state=ALL"
|
2016-12-07 08:54:32 -05:00
|
|
|
get_collection(path, :pull_request)
|
2016-08-22 15:15:15 -04:00
|
|
|
end
|
2016-08-22 14:53:46 -04:00
|
|
|
|
2016-11-16 03:13:17 -05:00
|
|
|
def pull_request_comments(repo, pull_request)
|
2016-12-07 04:33:32 -05:00
|
|
|
path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments"
|
2016-12-07 08:54:32 -05:00
|
|
|
get_collection(path, :pull_request_comment)
|
2016-11-16 03:13:17 -05:00
|
|
|
end
|
|
|
|
|
2016-11-18 00:30:35 -05:00
|
|
|
def pull_request_diff(repo, pull_request)
|
2016-12-07 04:33:32 -05:00
|
|
|
path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff"
|
|
|
|
connection.get(path)
|
2016-11-18 00:30:35 -05:00
|
|
|
end
|
|
|
|
|
2016-08-22 14:55:08 -04:00
|
|
|
def repo(name)
|
|
|
|
parsed_response = connection.get("/repositories/#{name}")
|
|
|
|
Representation::Repo.new(parsed_response)
|
|
|
|
end
|
|
|
|
|
2016-08-22 14:53:46 -04:00
|
|
|
def repos
|
2016-12-09 18:28:49 -05:00
|
|
|
path = "/repositories?role=member"
|
2016-12-07 08:54:32 -05:00
|
|
|
get_collection(path, :repo)
|
2016-08-22 14:53:46 -04:00
|
|
|
end
|
|
|
|
|
2016-08-22 14:45:29 -04:00
|
|
|
def user
|
2016-08-22 14:53:46 -04:00
|
|
|
@user ||= begin
|
|
|
|
parsed_response = connection.get('/user')
|
|
|
|
Representation::User.new(parsed_response)
|
|
|
|
end
|
2016-08-22 14:45:29 -04:00
|
|
|
end
|
|
|
|
|
2016-08-22 14:42:26 -04:00
|
|
|
private
|
|
|
|
|
2016-12-07 08:54:32 -05:00
|
|
|
def get_collection(path, type)
|
|
|
|
paginator = Paginator.new(connection, path, type)
|
|
|
|
Collection.new(paginator)
|
|
|
|
end
|
2016-08-22 14:42:26 -04:00
|
|
|
end
|
|
|
|
end
|