Auto-close everypolitician-data pull requests that have been superseded (where it is safe to do so)
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Close old pull requests

This library will go through the open pull requests on everypolitician/everypolitician-data and close any that have been are now out of date and have been replaced by a newer pull request.

To determine if a pull request is out of date we perform the following steps:

  • Group pull requests by title and author -- pull requests created by @everypoliticianbot in everypolitician-data have a predictable title "#{} (#{}): refresh data"
  • Close all but the most recently created pull requests in each group.


Add this line to your application's Gemfile:

gem 'close_old_pull_requests', git: '', branch: 'master'

And then execute:

$ bundle


First require the library in your program:

require 'close_old_pull_requests'

Then you can perform a cleanup of old pull requests by running:

CloseOldPullRequests.clean(access_token: ENV['GITHUB_ACCESS_TOKEN']).each do |pull_request|
  puts "Pull request #{pull_request.number} is outdated. (Newest pull request is #{pull_request.superseded_by.number})"

You can omit the access_token argument if you're using the GITHUB_ACCESS_TOKEN environment variable, since that is the default.


After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.