class BBFlow::Github

Public Class Methods

add_labels_to_pull_request(pull_request, labels) click to toggle source

@param [Sawyer::Resource] pull_request @param [Array<String>] labels

@return [void]

# File lib/bb_flow/github.rb, line 70
def add_labels_to_pull_request(pull_request, labels)
  puts 'Adding labels to pull request...'
  octokit.add_labels_to_an_issue(repository_name, pull_request, labels)
end
add_reviewers_to_pull_request(pull_request, reviewer_logins) click to toggle source

@param [String] pull_request @param [Array<String>] reviewer_logins

@return [void]

# File lib/bb_flow/github.rb, line 49
def add_reviewers_to_pull_request(pull_request, reviewer_logins)
  puts 'Adding reviewers to the pull request...'
  octokit.request_pull_request_review(repository_name, pull_request, reviewer_logins)
end
changed_files() click to toggle source
# File lib/bb_flow/github.rb, line 91
        def changed_files
  Misc.execute("git diff --name-only #{Options.get(:base_branch)} #{remote_branch}").split
end
collaborators() click to toggle source
# File lib/bb_flow/github.rb, line 55
                 def collaborators
  puts 'Fetching project collaborators...'
  octokit.collaborators(repository_name).map(&:login).sort.map(&octokit.method(:user)).map { |user| [user.login, user.name] }
end
commits_info() click to toggle source
# File lib/bb_flow/github.rb, line 20
        def commits_info
  octokit.compare(repository_name, Options.get(:base_branch), local_branch).commits
end
create_pull_request(title, body) click to toggle source

@param [String] title @param [String] body

@return [Sawyer::Resource] the newly created pull request.

# File lib/bb_flow/github.rb, line 40
def create_pull_request(title, body)
  puts 'Creating a pull request...'
  octokit.create_pull_request(repository_name, Options.get(:base_branch), local_branch, title, body)
end
find_pull_request() click to toggle source

@return [Sawyer::Resource]

# File lib/bb_flow/github.rb, line 32
def find_pull_request
  octokit.pull_requests(repository_name).detect { |pr| pr.head.ref == local_branch }
end
has_branch?() click to toggle source

@return [Boolean]

# File lib/bb_flow/github.rb, line 76
def has_branch?
  Misc.git.is_remote_branch?(local_branch)
end
http_url() click to toggle source

@return [String]

# File lib/bb_flow/github.rb, line 10
def http_url
  "https://github.com/#{repository_name}"
end
labels() click to toggle source
# File lib/bb_flow/github.rb, line 61
                 def labels
  puts 'Fetching repository labels...'
  octokit.labels(repository_name).map(&:name)
end
other_branch_committers() click to toggle source
# File lib/bb_flow/github.rb, line 27
        def other_branch_committers
  (commits_info.map(&:author) + commits_info.map(&:committer)).map(&:login).uniq - [octokit.user.login]
end
pushed?() click to toggle source

@return [Boolean]

# File lib/bb_flow/github.rb, line 81
def pushed?
  unpushed_commits_number == 0
end
remote_branch() click to toggle source

@return [String]

# File lib/bb_flow/github.rb, line 101
def remote_branch
  "#{remote_name}/#{local_branch}"
end
remote_name() click to toggle source

@return [String]

# File lib/bb_flow/github.rb, line 96
def remote_name
  remote.name
end
repository_url() click to toggle source
# File lib/bb_flow/github.rb, line 15
                 def repository_url
  remote.url
end
unpushed_commits_number() click to toggle source

@return [Integer]

# File lib/bb_flow/github.rb, line 86
def unpushed_commits_number
  git_command = "git rev-list --count HEAD ^#{remote_branch}"
  Misc.execute(git_command).strip.to_i
end

Private Class Methods

local_branch() click to toggle source

@return [String]

# File lib/bb_flow/github.rb, line 137
def local_branch
  Misc.git.current_branch
end
octokit() click to toggle source
# File lib/bb_flow/github.rb, line 108
        def octokit
  Octokit::Client.new(access_token: token)
end
remote() click to toggle source
# File lib/bb_flow/github.rb, line 119
        def remote
  remotes = Misc.git.remotes.select { |remote| remote.url.include?('github') }

  case remotes.size
  when 0
    Printer.panic("You don't have any remotes set up.")
  when 1
    remotes.first
  else
    Printer.select_item(
      remotes,
      'Which remote would you like to push to?',
      formatter: ->(remote) { [remote.name, remote.url] }
    )
  end
end
repository_name() click to toggle source

@return [String]

# File lib/bb_flow/github.rb, line 113
def repository_name
  # Match both git@github.com:shockone/bb-flow-test.git and https://github.com/shockone/bb-flow-test
  repository_url[%r{github\.com[/:]([\w-]+/[\w-]+)(\.git|$)}, 1]
end
token() click to toggle source
# File lib/bb_flow/github.rb, line 142
                  def token
  url = 'https://github.com/settings/tokens/new'
  Printer.ask("Paste a Github token. You can generate it on #{url} (leave default scopes): ")
end