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