class GitReflow::GitServer::BitBucket::PullRequest
Public Class Methods
create(options = {})
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 17 def self.create(options = {}) self.new GitReflow.git_server.connection.repos.pull_requests.create( GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, title: options[:title], description: options[:body] || options[:description], source: { branch: { name: GitReflow.git_server.class.current_branch }, repository: { full_name: "#{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}" } }, destination: { branch: { name: options[:base] } }, reviewers: [username: GitReflow.git_server.class.user]) end
find_open(to: 'master', from: GitReflow.git_server.class.current_branch)
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 33 def self.find_open(to: 'master', from: GitReflow.git_server.class.current_branch) begin matching_pull = GitReflow.git_server.connection.repos.pull_requests.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, limit: 1).select do |pr| pr.source.branch.name == from and pr.destination.branch.name == to end.first if matching_pull self.new matching_pull end rescue ::BitBucket::Error::NotFound => e GitReflow.git_server.say "No BitBucket repo found for #{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}", :error rescue ::BitBucket::Error::Forbidden => e GitReflow.git_server.say "You don't have API access to this repo", :error end end
new(attributes)
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 7 def initialize(attributes) self.number = attributes.id self.description = attributes.body || attributes.description self.html_url = "#{attributes.source.repository.links.html.href}/pull-request/#{self.number}" self.feature_branch_name = attributes.source.branch.name[/[^:]+$/] self.base_branch_name = attributes.destination.branch.name[/[^:]+$/] self.build = Build.new self.source_object = attributes end
Public Instance Methods
approvals()
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 70 def approvals approved = [] GitReflow.git_server.connection.repos.pull_requests.activity(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id).each do |activity| break unless activity.respond_to?(:approval) and activity.approval.user.username != GitReflow.git_server.class.user approved |= [activity.approval.user.username] end approved end
comments()
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 55 def comments GitReflow.git_server.connection.repos.pull_requests.comments.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id) end
last_comment()
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 59 def last_comment last_comment = comments.first return "" unless last_comment "#{last_comment.content.raw}" end
reviewers()
click to toggle source
# File lib/git_reflow/git_server/bit_bucket/pull_request.rb, line 65 def reviewers return [] unless comments.size > 0 comments.map {|c| c.user.username }.uniq - [GitReflow.git_server.class.user] end