debian-mirror-gitlab/lib/bitbucket_server/client.rb

59 lines
1.8 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
module BitbucketServer
class Client
attr_reader :connection
def initialize(options = {})
@connection = Connection.new(options)
end
def pull_requests(project_key, repo)
path = "/projects/#{project_key}/repos/#{repo}/pull-requests?state=ALL"
get_collection(path, :pull_request)
end
def activities(project_key, repo, pull_request_id)
path = "/projects/#{project_key}/repos/#{repo}/pull-requests/#{pull_request_id}/activities"
get_collection(path, :activity)
end
def repo(project, repo_name)
parsed_response = connection.get("/projects/#{project}/repos/#{repo_name}")
BitbucketServer::Representation::Repo.new(parsed_response)
end
2019-10-12 21:52:04 +05:30
def repos(page_offset: 0, limit: nil, filter: nil)
2018-11-18 11:00:15 +05:30
path = "/repos"
2019-10-12 21:52:04 +05:30
path += "?name=#{filter}" if filter
2018-12-13 13:39:08 +05:30
get_collection(path, :repo, page_offset: page_offset, limit: limit)
2018-11-18 11:00:15 +05:30
end
def create_branch(project_key, repo, branch_name, sha)
payload = {
name: branch_name,
startPoint: sha,
message: 'GitLab temporary branch for import'
}
connection.post("/projects/#{project_key}/repos/#{repo}/branches", payload.to_json)
end
def delete_branch(project_key, repo, branch_name, sha)
payload = {
name: Gitlab::Git::BRANCH_REF_PREFIX + branch_name,
dryRun: false
}
connection.delete(:branches, "/projects/#{project_key}/repos/#{repo}/branches", payload.to_json)
end
private
2018-12-13 13:39:08 +05:30
def get_collection(path, type, page_offset: 0, limit: nil)
paginator = BitbucketServer::Paginator.new(connection, Addressable::URI.escape(path), type, page_offset: page_offset, limit: limit)
2018-11-18 11:00:15 +05:30
BitbucketServer::Collection.new(paginator)
end
end
end