Skip to content

Instantly share code, notes, and snippets.

@gmanley
Created December 24, 2014 19:41
Show Gist options
  • Save gmanley/9c5bff5bf2f6643b22a1 to your computer and use it in GitHub Desktop.
Save gmanley/9c5bff5bf2f6643b22a1 to your computer and use it in GitHub Desktop.
require 'pry'
require 'octokit'
REPO_PATH = 'CouponTrade/giftcards'
WHITE_LIST = %w[
drachma
]
def in_giftcards_dir
Dir.chdir(File.expand_path('~/projects/giftcards')) do
yield
end
end
Octokit.auto_paginate = true
client = Octokit::Client.new(access_token: '__')
prs = client.pull_requests(REPO_PATH, state: 'closed', per_page: 100)
merged_prs = prs.map { |pr| pr.head.ref if pr.merged_at }.compact
in_giftcards_dir do
remote_branches = `git branch -r`.split("\n").map { |b| b.gsub('origin/', '').strip }
merged_prs.each do |ref|
if remote_branches.include?(ref) && !WHITE_LIST.include?(ref)
puts "Deleting branch of merged PR: #{ref}"
system("git push origin :#{ref}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment