Sha256: 5b2376334b1a25e567b5dfa2b6c30e2fb1ad2785cd1669457303a7b877bbdf1e

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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 = Rugged::Repository.new(Rugged::Repository.discover(Dir.pwd)).remotes.first.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.3.0 bin/git-merge-pr