diff options
author | Stan Hu <stanhu@gmail.com> | 2018-06-25 23:06:10 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-06-25 23:06:10 +0300 |
commit | ebd8e4333a263138abf2113dd315a97352851cbe (patch) | |
tree | 4e4975eab778d490c20c9252785761a1d78fae26 /lib/bitbucket_server/client.rb | |
parent | 2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff) |
WIP: Add support for Bitbucket Server imports
Diffstat (limited to 'lib/bitbucket_server/client.rb')
-rw-r--r-- | lib/bitbucket_server/client.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/bitbucket_server/client.rb b/lib/bitbucket_server/client.rb new file mode 100644 index 00000000000..1f2f03790dd --- /dev/null +++ b/lib/bitbucket_server/client.rb @@ -0,0 +1,59 @@ +module BitbucketServer + class Client + attr_reader :connection + + def initialize(options = {}) + @connection = Connection.new(options) + end + + def issues(repo) + path = "/repositories/#{repo}/issues" + get_collection(path, :issue) + end + + def issue_comments(repo, issue_id) + path = "/repositories/#{repo}/issues/#{issue_id}/comments" + get_collection(path, :comment) + end + + def pull_requests(repo) + path = "/repositories/#{repo}/pullrequests?state=ALL" + get_collection(path, :pull_request) + end + + def pull_request_comments(repo, pull_request) + path = "/repositories/#{repo}/pullrequests/#{pull_request}/comments" + get_collection(path, :pull_request_comment) + end + + def pull_request_diff(repo, pull_request) + path = "/repositories/#{repo}/pullrequests/#{pull_request}/diff" + connection.get(path) + end + + def repo(project, repo_name) + parsed_response = connection.get("/projects/#{project}/repos/#{repo_name}") + # XXXX TODO Handle failure + BitbucketServer::Representation::Repo.new(parsed_response) + end + + def repos + path = "/repos" + get_collection(path, :repo) + end + + def user + @user ||= begin + parsed_response = connection.get('/user') + BitbucketServer::Representation::User.new(parsed_response) + end + end + + private + + def get_collection(path, type) + paginator = BitbucketServer::Paginator.new(connection, path, type) + BitbucketServer::Collection.new(paginator) + end + end +end |