Sha256: e827fb7459dc05fa841c6a45aeb08d3b6e8be71fe55663b410bc8e07a433c089

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

#! /usr/bin/env ruby
#
# git-merge-pr(1)
#
# Summary:
#   Merge a pull request on github.com
#
# Usage:
#   git-merge-pr 1776
#
# Author:
#   Parker Moore (@parkr)
#

require 'octokit'
require 'netrc'
require 'rugged'

abort "Provide a PR number (no '#' tho)" if ARGV.empty?

pr_num = ARGV.first

remote_name = ENV.fetch("REMOTE_NAME", "origin")
remotes = Rugged::Repository.discover(Dir.pwd).remotes
remote = remotes.find{ |r| r.name.eql?(remote_name) }.url
remote.sub!("git@github.com:", "https://github.com/")
remote.sub!(/\.git$/, "")

client = Octokit::Client.new(netrc: true)
repo   = Octokit::Repository.from_url(remote)

unless client.pull_merged?(repo, pr_num)
  begin
    client.merge_pull_request(repo, pr_num)
  rescue Octokit::NotFound => e
    abort "Got a 404 -- looks like #{repo}##{pr_num} doesn't exist."
  end

  # delete branch if it's on the repo
  merged_branch = client.pull_request(repo, pr_num).head.ref
  begin
    if client.ref(repo, "heads/#{merged_branch}")
      unless %w[master gh-pages].include?(merged_branch)
        client.delete_branch(repo, merged_branch)
      end
    end
  rescue Octokit::NotFound
  end
else
  puts "Pull request #{repo}##{pr_num} has already been merged."
  print "Continue anyway? (y/n) "
  abort unless STDIN.gets.chomp == "y"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git-merge-pr-0.5.0 bin/git-merge-pr