Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexanderadam/a1327937145d96858dee5a3575c54c3d to your computer and use it in GitHub Desktop.
Save alexanderadam/a1327937145d96858dee5a3575c54c3d to your computer and use it in GitHub Desktop.
Script to unsubscribe from all issue notifications on GitHub
#!/usr/bin/env ruby
# set env variables GITHUB_USER and GITHUB_PASS
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'ferrum'
end
def browser
@browser ||= Ferrum::Browser.new(timeout: 30)
end
def left_notification_count
browser.evaluate("document.querySelectorAll('.js-notification-bulk-action-check-item').length")
end
browser.goto('https://github.com/notifications')
input = browser.at_xpath("//input[@id='login_field']")
input.focus.type(ENV['GITHUB_USER'])
input = browser.at_xpath("//input[@id='password']")
input.focus.type(ENV['GITHUB_PASS'], :Enter)
browser.network.wait_for_idle
sleep 2
while left_notification_count > 0
browser.at_css('.js-notifications-mark-all-prompt').click
browser.network.wait_for_idle
browser.at_css('button[title="Unsubscribe"]').click
browser.network.wait_for_idle
# I thought wait_for_idle should be enough but it seems it isn't
sleep 5
print '.'
end
browser.quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment