Sha256: 61744ae6232c2845c97f576082d97386a96ce0bd750b8cc8591ac08a11bdee36

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'rake_factory'
require 'octokit'

module RakeGithub
  module Tasks
    module PullRequests
      class Merge < RakeFactory::Task
        default_description(RakeFactory::DynamicValue.new do |t|
          "Merges pull request on the specified branch in the #{t.repository} repository"
        end)

        parameter :repository, required: true
        parameter :access_token, required: true
        parameter :branch_name, required: true
        parameter :commit_message, default: ''

        action do |t|
          github_client = Octokit::Client.new(access_token: access_token)

          open_prs = github_client.pull_requests(t.repository)

          current_pr = open_prs
            .find { |pr| pr[:head][:ref] == t.branch_name }

          raise NoPullRequestError.new t.branch_name if current_pr.nil?

          github_client.merge_pull_request(
            t.repository,
            current_pr[:number],
            format(t.commit_message % current_pr[:title])
          )
        end
      end
    end
  end
end

class NoPullRequestError < StandardError
  attr_reader :branch_name
  def initialize(branch_name)
    @branch_name = branch_name
  end

  def message
    "No pull request associated with branch %s" % branch_name
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rake_github-0.10.0.pre.3 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.10.0.pre.2 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.10.0.pre.1 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.9.0 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.8.0.pre.12 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.8.0.pre.11 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.8.0.pre.10 lib/rake_github/tasks/pull_requests/merge.rb
rake_github-0.8.0.pre.9 lib/rake_github/tasks/pull_requests/merge.rb